@@ -62,8 +62,6 @@ private async Task ManageStockInventory(Product product, ShipmentItem shipmentIt
6262 pwi . ReservedQuantity = 0 ;
6363
6464 await _productRepository . UpdateCollectionFieldItem ( product . Id , x => x . ProductWarehouseInventory , z => z . Id == pwi . Id , pwi ) ;
65- await _productRepository . UpdateField ( product . Id , x => x . UpdatedOnUtc , DateTime . UtcNow ) ;
66-
6765 product . StockQuantity = product . ProductWarehouseInventory . Sum ( x => x . StockQuantity ) ;
6866 product . ReservedQuantity = product . ProductWarehouseInventory . Sum ( x => x . ReservedQuantity ) ;
6967 await UpdateStockProduct ( product ) ;
@@ -90,7 +88,6 @@ private async Task ManageStockByAttributesInventory(Product product, ShipmentIte
9088 combination . ReservedQuantity = 0 ;
9189
9290 await _productRepository . UpdateCollectionFieldItem ( product . Id , x => x . ProductAttributeCombinations , z => z . Id == combination . Id , combination ) ;
93- await _productRepository . UpdateField ( product . Id , x => x . UpdatedOnUtc , DateTime . UtcNow ) ;
9491 }
9592 else
9693 {
@@ -107,7 +104,6 @@ private async Task ManageStockByAttributesInventory(Product product, ShipmentIte
107104 combination . ReservedQuantity = combination . WarehouseInventory . Sum ( x => x . ReservedQuantity ) ;
108105
109106 await _productRepository . UpdateCollectionFieldItem ( product . Id , x => x . ProductAttributeCombinations , z => z . Id == combination . Id , combination ) ;
110- await _productRepository . UpdateField ( product . Id , x => x . UpdatedOnUtc , DateTime . UtcNow ) ;
111107 }
112108
113109 product . StockQuantity = product . ProductAttributeCombinations . Sum ( x => x . StockQuantity ) ;
@@ -187,7 +183,6 @@ private async Task ReverseBookedInventory(Product product, InventoryJournal inve
187183 pwi . ReservedQuantity = 0 ;
188184
189185 await _productRepository . UpdateCollectionFieldItem ( product . Id , x => x . ProductWarehouseInventory , z => z . Id == pwi . Id , pwi ) ;
190- await _productRepository . UpdateField ( product . Id , x => x . UpdatedOnUtc , DateTime . UtcNow ) ;
191186 break ;
192187 }
193188 case ManageInventoryMethod . ManageStock :
@@ -213,8 +208,6 @@ private async Task ReverseBookedInventory(Product product, InventoryJournal inve
213208 product . ReservedQuantity = product . ProductAttributeCombinations . Sum ( x => x . ReservedQuantity ) ;
214209
215210 await _productRepository . UpdateCollectionFieldItem ( product . Id , x => x . ProductAttributeCombinations , z => z . Id == combination . Id , combination ) ;
216- await _productRepository . UpdateField ( product . Id , x => x . UpdatedOnUtc , DateTime . UtcNow ) ;
217-
218211 await UpdateStockProduct ( product ) ;
219212 }
220213 else
@@ -236,7 +229,6 @@ private async Task ReverseBookedInventory(Product product, InventoryJournal inve
236229 product . ReservedQuantity = product . ProductAttributeCombinations . Sum ( x => x . ReservedQuantity ) ;
237230
238231 await _productRepository . UpdateCollectionFieldItem ( product . Id , x => x . ProductAttributeCombinations , z => z . Id == combination . Id , combination ) ;
239- await _productRepository . UpdateField ( product . Id , x => x . UpdatedOnUtc , DateTime . UtcNow ) ;
240232 await UpdateStockProduct ( product ) ;
241233 }
242234
@@ -310,10 +302,11 @@ public virtual async Task AdjustReserved(Product product, int quantityToChange,
310302 product . DisableBuyButton = true ;
311303 product . LowStock = true ;
312304
313- await _productRepository . UpdateField ( product . Id , x => x . DisableBuyButton ,
314- product . DisableBuyButton ) ;
315- await _productRepository . UpdateField ( product . Id , x => x . LowStock , product . LowStock ) ;
316- await _productRepository . UpdateField ( product . Id , x => x . UpdatedOnUtc , DateTime . UtcNow ) ;
305+ await _productRepository . UpdateOneAsync ( x => x . Id == product . Id ,
306+ UpdateBuilder < Product > . Create ( )
307+ . Set ( x => x . DisableBuyButton , product . DisableBuyButton )
308+ . Set ( x => x . LowStock , product . LowStock ) ) ;
309+
317310 //cache
318311 await _cacheBase . RemoveByPrefix ( string . Format ( CacheKey . PRODUCTS_BY_ID_KEY , product . Id ) ) ;
319312
@@ -325,9 +318,10 @@ await _productRepository.UpdateField(product.Id, x => x.DisableBuyButton,
325318 product . Published = false ;
326319 product . LowStock = true ;
327320
328- await _productRepository . UpdateField ( product . Id , x => x . Published , product . Published ) ;
329- await _productRepository . UpdateField ( product . Id , x => x . LowStock , product . LowStock ) ;
330- await _productRepository . UpdateField ( product . Id , x => x . UpdatedOnUtc , DateTime . UtcNow ) ;
321+ await _productRepository . UpdateOneAsync ( x => x . Id == product . Id ,
322+ UpdateBuilder < Product > . Create ( )
323+ . Set ( x => x . Published , product . Published )
324+ . Set ( x => x . LowStock , product . LowStock ) ) ;
331325
332326 //cache
333327 await _cacheBase . RemoveByPrefix ( string . Format ( CacheKey . PRODUCTS_BY_ID_KEY , product . Id ) ) ;
@@ -350,10 +344,10 @@ await _productRepository.UpdateField(product.Id, x => x.DisableBuyButton,
350344 product . DisableBuyButton = false ;
351345 product . LowStock = product . MinStockQuantity <= prevStockQuantity ;
352346
353- await _productRepository . UpdateField ( product . Id , x => x . DisableBuyButton ,
354- product . DisableBuyButton ) ;
355- await _productRepository . UpdateField ( product . Id , x => x . LowStock , product . LowStock ) ;
356- await _productRepository . UpdateField ( product . Id , x => x . UpdatedOnUtc , DateTime . UtcNow ) ;
347+ await _productRepository . UpdateOneAsync ( x => x . Id == product . Id ,
348+ UpdateBuilder < Product > . Create ( )
349+ . Set ( x => x . DisableBuyButton , product . DisableBuyButton )
350+ . Set ( x => x . LowStock , product . LowStock ) ) ;
357351
358352 //cache
359353 await _cacheBase . RemoveByPrefix ( string . Format ( CacheKey . PRODUCTS_BY_ID_KEY , product . Id ) ) ;
@@ -366,9 +360,10 @@ await _productRepository.UpdateField(product.Id, x => x.DisableBuyButton,
366360 product . Published = true ;
367361 product . LowStock = product . MinStockQuantity < prevStockQuantity ;
368362
369- await _productRepository . UpdateField ( product . Id , x => x . Published , product . Published ) ;
370- await _productRepository . UpdateField ( product . Id , x => x . LowStock , product . LowStock ) ;
371- await _productRepository . UpdateField ( product . Id , x => x . UpdatedOnUtc , DateTime . UtcNow ) ;
363+ await _productRepository . UpdateOneAsync ( x => x . Id == product . Id ,
364+ UpdateBuilder < Product > . Create ( )
365+ . Set ( x => x . Published , product . Published )
366+ . Set ( x => x . LowStock , product . LowStock ) ) ;
372367
373368 //cache
374369 await _cacheBase . RemoveByPrefix ( string . Format ( CacheKey . PRODUCTS_BY_ID_KEY , product . Id ) ) ;
@@ -465,7 +460,6 @@ protected virtual async Task ReserveInventory(Product product, int quantity, str
465460 pwi . ReservedQuantity = 0 ;
466461
467462 await _productRepository . UpdateCollectionFieldItem ( product . Id , x => x . ProductWarehouseInventory , z => z . Id == pwi . Id , pwi ) ;
468- await _productRepository . UpdateField ( product . Id , x => x . UpdatedOnUtc , DateTime . UtcNow ) ;
469463 }
470464
471465 //cache
@@ -503,8 +497,8 @@ protected virtual async Task ReserveInventoryCombination(Product product, Produc
503497 product . ReservedQuantity = product . ProductAttributeCombinations . Sum ( x => x . ReservedQuantity ) ;
504498
505499 await _productRepository . UpdateCollectionFieldItem ( product . Id , x => x . ProductAttributeCombinations , z => z . Id == combination . Id , combination ) ;
506- await _productRepository . UpdateField ( product . Id , x => x . ReservedQuantity , product . ReservedQuantity ) ;
507- await _productRepository . UpdateField ( product . Id , x => x . UpdatedOnUtc , DateTime . UtcNow ) ;
500+ await _productRepository . UpdateOneAsync ( x => x . Id == product . Id ,
501+ UpdateBuilder < Product > . Create ( ) . Set ( x => x . ReservedQuantity , product . ReservedQuantity ) ) ;
508502 }
509503 else
510504 {
@@ -522,8 +516,8 @@ protected virtual async Task ReserveInventoryCombination(Product product, Produc
522516 product . ReservedQuantity = product . ProductAttributeCombinations . Sum ( x => x . ReservedQuantity ) ;
523517
524518 await _productRepository . UpdateCollectionFieldItem ( product . Id , x => x . ProductAttributeCombinations , z => z . Id == combination . Id , combination ) ;
525- await _productRepository . UpdateField ( product . Id , x => x . ReservedQuantity , product . ReservedQuantity ) ;
526- await _productRepository . UpdateField ( product . Id , x => x . UpdatedOnUtc , DateTime . UtcNow ) ;
519+ await _productRepository . UpdateOneAsync ( x => x . Id == product . Id ,
520+ UpdateBuilder < Product > . Create ( ) . Set ( x => x . ReservedQuantity , product . ReservedQuantity ) ) ;
527521 }
528522
529523 //cache
@@ -567,7 +561,6 @@ protected virtual async Task UnblockReservedInventory(Product product, int quant
567561 pwi . ReservedQuantity = 0 ;
568562
569563 await _productRepository . UpdateCollectionFieldItem ( product . Id , x => x . ProductWarehouseInventory , z => z . Id == pwi . Id , pwi ) ;
570- await _productRepository . UpdateField ( product . Id , x => x . UpdatedOnUtc , DateTime . UtcNow ) ;
571564 }
572565
573566 //cache
@@ -601,8 +594,8 @@ protected virtual async Task UnblockReservedInventoryCombination(Product product
601594 product . ReservedQuantity = product . ProductAttributeCombinations . Sum ( x => x . ReservedQuantity ) ;
602595
603596 await _productRepository . UpdateCollectionFieldItem ( product . Id , x => x . ProductAttributeCombinations , z => z . Id == combination . Id , combination ) ;
604- await _productRepository . UpdateField ( product . Id , x => x . ReservedQuantity , product . ReservedQuantity ) ;
605- await _productRepository . UpdateField ( product . Id , x => x . UpdatedOnUtc , DateTime . UtcNow ) ;
597+ await _productRepository . UpdateOneAsync ( x => x . Id == product . Id ,
598+ UpdateBuilder < Product > . Create ( ) . Set ( x => x . ReservedQuantity , product . ReservedQuantity ) ) ;
606599 }
607600 else
608601 {
@@ -617,7 +610,6 @@ protected virtual async Task UnblockReservedInventoryCombination(Product product
617610 combination . ReservedQuantity = combination . WarehouseInventory . Sum ( x => x . ReservedQuantity ) ;
618611
619612 await _productRepository . UpdateCollectionFieldItem ( product . Id , x => x . ProductAttributeCombinations , z => z . Id == combination . Id , combination ) ;
620- await _productRepository . UpdateField ( product . Id , x => x . UpdatedOnUtc , DateTime . UtcNow ) ;
621613 }
622614
623615 //cache
@@ -704,14 +696,15 @@ public virtual async Task UpdateStockProduct(Product product, bool mediator = tr
704696 if ( product . ReservedQuantity < 0 )
705697 product . ReservedQuantity = 0 ;
706698
707- //update
708- await _productRepository . UpdateField ( product . Id , x => x . StockQuantity , product . StockQuantity ) ;
709- await _productRepository . UpdateField ( product . Id , x => x . ReservedQuantity , product . ReservedQuantity ) ;
710- await _productRepository . UpdateField ( product . Id , x => x . LowStock ,
711- ( product . MinStockQuantity > 0 &&
712- product . MinStockQuantity >= product . StockQuantity - product . ReservedQuantity ) ||
713- product . StockQuantity - product . ReservedQuantity <= 0 ) ;
714- await _productRepository . UpdateField ( product . Id , x => x . UpdatedOnUtc , DateTime . UtcNow ) ;
699+ //update - one write, so the three stock fields never land out of step
700+ await _productRepository . UpdateOneAsync ( x => x . Id == product . Id ,
701+ UpdateBuilder < Product > . Create ( )
702+ . Set ( x => x . StockQuantity , product . StockQuantity )
703+ . Set ( x => x . ReservedQuantity , product . ReservedQuantity )
704+ . Set ( x => x . LowStock ,
705+ ( product . MinStockQuantity > 0 &&
706+ product . MinStockQuantity >= product . StockQuantity - product . ReservedQuantity ) ||
707+ product . StockQuantity - product . ReservedQuantity <= 0 ) ) ;
715708
716709
717710 //cache
0 commit comments