void SubtractLineItemStock(ProductTransferLineItem item, int branchId) { var stock = _unitOfWork.StockRepository.FindBy(x => x.BranchId == branchId && x.ProductId == item.ProductId).SingleOrDefault(); stock.Quantity = stock.Quantity - item.Quantity; _unitOfWork.StockRepository.Edit(stock); }
public bool AddProductTransferLineItem(ProductTransfer productTransfer, ProductTransferLineItem item) { _unitOfWork.ProductTransferRepository.Edit(productTransfer); AddLineItemStock(item, productTransfer.ToBranchId); SubtractLineItemStock(item, productTransfer.FromBranchId); _unitOfWork.Save(); return(true); }
public bool DeleteProductTransferLineItem(ProductTransfer productTransfer, ProductTransferLineItem lineItem) { //_unitOfWork.ProductTransferRepository.Edit(productTransfer); //SubtractLineItemStock(lineItem, productTransfer.FromBranchId); //_unitOfWork.Save(); //return true; _unitOfWork.ProductTransferLineItemRepository.Delete(lineItem); SubtractLineItemStock(lineItem, productTransfer.ToBranchId); AddLineItemStock(lineItem, productTransfer.FromBranchId); _unitOfWork.Save(); return(true); }
public ActionResult AddLineItem([Bind(Include = "ProductTransferId,Quantity,ProductId")] ProductTransferLineItemViewModel productTransferLineItemViewModel) { var productTransfer = _productTransferService.Get(t => t.ProductTransferId == productTransferLineItemViewModel.ProductTransferId, null, "ProductTransferLineItems").FirstOrDefault(); int exists = productTransfer.ProductTransferLineItems.Where(t => t.ProductId == productTransferLineItemViewModel.ProductId).ToList().Count; bool available = _productTransferService.IsAvailable(productTransferLineItemViewModel.ProductId, productTransfer.FromBranchId, productTransferLineItemViewModel.Quantity); if (exists > 0 || !available) { return(RedirectToAction("Create", "ProductTransfers", new { id = productTransfer.ProductTransferId })); } var productTransferLineItem = new ProductTransferLineItem() { ProductId = productTransferLineItemViewModel.ProductId, Quantity = productTransferLineItemViewModel.Quantity, ProductTransferId = productTransferLineItemViewModel.ProductTransferId, }; productTransfer.ProductTransferLineItems.Add(productTransferLineItem); _productTransferService.AddProductTransferLineItem(productTransfer, productTransferLineItem); return(RedirectToAction("Create", "ProductTransfers", new { id = productTransfer.ProductTransferId })); }
void AddLineItemStock(ProductTransferLineItem item, int branchId) { var stock = _unitOfWork.StockRepository.FindBy(x => x.BranchId == branchId && x.ProductId == item.ProductId).SingleOrDefault(); if (stock == null) { stock = new Stock() { BranchId = branchId, ProductId = item.ProductId, Quantity = item.Quantity, }; _unitOfWork.StockRepository.Add(stock); } else { stock.Quantity = stock.Quantity + item.Quantity; _unitOfWork.StockRepository.Edit(stock); } }