Просмотр исходного кода

Allow OrderGuid to be specified when placing an order.

Andrew Klopper лет назад: 8
Родитель
Сommit
41857ea4ab
3 измененных файлов с 16 добавлено и 4 удалено
  1. 12 1
      BulkPrintingAPI/Controllers/BatchesController.cs
  2. 2 1
      MAXClient/Client.cs
  3. 2 2
      MAXClient/Utils.cs

+ 12 - 1
BulkPrintingAPI/Controllers/BatchesController.cs

28
 
28
 
29
             [Required]
29
             [Required]
30
             public string CustomerReference { get; set; }
30
             public string CustomerReference { get; set; }
31
+
32
+            public Guid? OrderGuid { get; set; }
31
         };
33
         };
32
 
34
 
33
         private readonly ILogger _logger;
35
         private readonly ILogger _logger;
98
                 return BadRequest(ModelState);
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
             var credentials = await Utils.GetLoginCredentialsFromRequestAsync(HttpContext, _context);
112
             var credentials = await Utils.GetLoginCredentialsFromRequestAsync(HttpContext, _context);
102
             var catalogue = await Utils.GetProductCatalogueAsync(_clientFactory, _logger, _cache,
113
             var catalogue = await Utils.GetProductCatalogueAsync(_clientFactory, _logger, _cache,
103
                 credentials, false);
114
                 credentials, false);
109
             }
120
             }
110
 
121
 
111
             var orderResponse = await MAX.Utils.PlaceOrderAsync(_clientFactory, _logger,
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
                 Utils.AesDecryptBytes(credentials.Vendor.EncryptedVoucherKey,
124
                 Utils.AesDecryptBytes(credentials.Vendor.EncryptedVoucherKey,
114
                     _dataEncryptionOptions.DefaultKey));
125
                     _dataEncryptionOptions.DefaultKey));
115
 
126
 

+ 2 - 1
MAXClient/Client.cs

334
         }
334
         }
335
 
335
 
336
         public async Task<OrderResponse> PlaceOrderAsync(int accountId, Product product, int quantity,
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
             if (key.Length != 24)
339
             if (key.Length != 24)
340
             {
340
             {
371
                         RequestedQuantity = int.Parse(parts[3]),
371
                         RequestedQuantity = int.Parse(parts[3]),
372
                         DeliveredQuantity = int.Parse(parts[4]),
372
                         DeliveredQuantity = int.Parse(parts[4]),
373
                         Cost = decimal.Parse(parts[5]),
373
                         Cost = decimal.Parse(parts[5]),
374
+                        OrderGuid = orderGuid,
374
                         AccountId = accountId,
375
                         AccountId = accountId,
375
                         VendorId = _vendorId,
376
                         VendorId = _vendorId,
376
                         ProductId = product.Id,
377
                         ProductId = product.Id,

+ 2 - 2
MAXClient/Utils.cs

90
 
90
 
91
         public static async Task<OrderResponse> PlaceOrderAsync(
91
         public static async Task<OrderResponse> PlaceOrderAsync(
92
             ClientFactory clientFactory, ILogger logger, LoginCredentials credentials,
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
             using (var client = clientFactory.GetClient(logger, credentials))
95
             using (var client = clientFactory.GetClient(logger, credentials))
96
             {
96
             {
101
                         credentials.ToString()));
101
                         credentials.ToString()));
102
                 }
102
                 }
103
                 return await client.PlaceOrderAsync(credentials.User.AccountId,
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
     }