Kaynağa Gözat

Allow OrderGuid to be specified when placing an order.

Andrew Klopper 8 yıl önce
ebeveyn
işleme
41857ea4ab

+ 12 - 1
BulkPrintingAPI/Controllers/BatchesController.cs

@@ -28,6 +28,8 @@ namespace BulkPrintingAPI.Controllers
28 28
 
29 29
             [Required]
30 30
             public string CustomerReference { get; set; }
31
+
32
+            public Guid? OrderGuid { get; set; }
31 33
         };
32 34
 
33 35
         private readonly ILogger _logger;
@@ -98,6 +100,15 @@ namespace BulkPrintingAPI.Controllers
98 100
                 return BadRequest(ModelState);
99 101
             }
100 102
 
103
+            if (order.OrderGuid.HasValue)
104
+            {
105
+                var batch = await _context.Batches.SingleOrDefaultAsync(b => b.OrderGuid == order.OrderGuid.Value);
106
+                if (batch != null)
107
+                {
108
+                    return BadRequest(new { error = "Duplicate OrderGuid" });
109
+                }
110
+            }
111
+
101 112
             var credentials = await Utils.GetLoginCredentialsFromRequestAsync(HttpContext, _context);
102 113
             var catalogue = await Utils.GetProductCatalogueAsync(_clientFactory, _logger, _cache,
103 114
                 credentials, false);
@@ -109,7 +120,7 @@ namespace BulkPrintingAPI.Controllers
109 120
             }
110 121
 
111 122
             var orderResponse = await MAX.Utils.PlaceOrderAsync(_clientFactory, _logger,
112
-                credentials, product, order.Quantity, order.CustomerReference,
123
+                credentials, product, order.Quantity, order.CustomerReference, order.OrderGuid,
113 124
                 Utils.AesDecryptBytes(credentials.Vendor.EncryptedVoucherKey,
114 125
                     _dataEncryptionOptions.DefaultKey));
115 126
 

+ 2 - 1
MAXClient/Client.cs

@@ -334,7 +334,7 @@ namespace MAX
334 334
         }
335 335
 
336 336
         public async Task<OrderResponse> PlaceOrderAsync(int accountId, Product product, int quantity,
337
-            string customerReference, byte[] key)
337
+            string customerReference, Guid? orderGuid, byte[] key)
338 338
         {
339 339
             if (key.Length != 24)
340 340
             {
@@ -371,6 +371,7 @@ namespace MAX
371 371
                         RequestedQuantity = int.Parse(parts[3]),
372 372
                         DeliveredQuantity = int.Parse(parts[4]),
373 373
                         Cost = decimal.Parse(parts[5]),
374
+                        OrderGuid = orderGuid,
374 375
                         AccountId = accountId,
375 376
                         VendorId = _vendorId,
376 377
                         ProductId = product.Id,

+ 2 - 2
MAXClient/Utils.cs

@@ -90,7 +90,7 @@ namespace MAX
90 90
 
91 91
         public static async Task<OrderResponse> PlaceOrderAsync(
92 92
             ClientFactory clientFactory, ILogger logger, LoginCredentials credentials,
93
-            Product product, int quantity, string customerReference, byte[] key)
93
+            Product product, int quantity, string customerReference, Guid? orderGuid, byte[] key)
94 94
         {
95 95
             using (var client = clientFactory.GetClient(logger, credentials))
96 96
             {
@@ -101,7 +101,7 @@ namespace MAX
101 101
                         credentials.ToString()));
102 102
                 }
103 103
                 return await client.PlaceOrderAsync(credentials.User.AccountId,
104
-                    product, quantity, customerReference, key).ConfigureAwait(false);
104
+                    product, quantity, customerReference, orderGuid, key).ConfigureAwait(false);
105 105
             }
106 106
         }
107 107
     }