public void StockMutateObject(StockMutation stockMutation, IItemService _itemService, IBarringService _barringService, IWarehouseItemService _warehouseItemService) { // decimal stockAdjustmentDetailPrice = (stockMutation.Status == Constant.MutationStatus.Addition) ? stockAdjustmentDetail.Price : ((-1) * stockAdjustmentDetail.Price); // item.AvgCost = _barringService.CalculateAvgCost(item, stockAdjustmentDetail.Quantity, stockAdjustmentDetailPrice); // barring.AvgCost = _barringService.CalculateAvgCost(barring, stockAdjustmentDetail.Quantity, stockAdjustmentDetailPrice); int Quantity = (stockMutation.Status == Constant.MutationStatus.Addition) ? stockMutation.Quantity : (-1) * stockMutation.Quantity; WarehouseItem warehouseItem = _warehouseItemService.GetObjectById(stockMutation.WarehouseItemId); Item item = _itemService.GetObjectById(stockMutation.ItemId); Barring barring = _barringService.GetObjectById(stockMutation.ItemId); if (warehouseItem != null) { if (stockMutation.ItemCase == Constant.ItemCase.Ready) { _warehouseItemService.AdjustQuantity(warehouseItem, Quantity); } } if (barring == null) { // itemService in action if (stockMutation.ItemCase == Constant.ItemCase.Ready) { _itemService.AdjustQuantity(item, Quantity); } else if (stockMutation.ItemCase == Constant.ItemCase.PendingDelivery) { _itemService.AdjustPendingDelivery(item, Quantity); } else if (stockMutation.ItemCase == Constant.ItemCase.PendingReceival) { _itemService.AdjustPendingReceival(item, Quantity); } } else { // barringService in action if (stockMutation.ItemCase == Constant.ItemCase.Ready) { _barringService.AdjustQuantity(barring, Quantity); } else if (stockMutation.ItemCase == Constant.ItemCase.PendingDelivery) { _barringService.AdjustPendingDelivery(barring, Quantity); } else if (stockMutation.ItemCase == Constant.ItemCase.PendingReceival) { _barringService.AdjustPendingReceival(barring, Quantity); } } }