public ActionResult Edit([Bind(Include = "WorkingStandardId,WorkingStandardName,IdCode,MaxxamId,ExpiryDate")] WorkingStandardEditViewModel workingStandard) { if (ModelState.IsValid) { InventoryItemRepository inventoryRepo = _uow.InventoryItemRepository; var user = _uow.GetCurrentUser(); InventoryItem invItem = inventoryRepo.Get() .Where(item => item.WorkingStandard != null && item.WorkingStandard.WorkingStandardId == workingStandard.WorkingStandardId) .FirstOrDefault(); WorkingStandard updateStandard = invItem.WorkingStandard; updateStandard.IdCode = workingStandard.IdCode; updateStandard.WorkingStandardName = workingStandard.WorkingStandardName; updateStandard.LastModifiedBy = user.UserName; updateStandard.DateModified = DateTime.Today; updateStandard.ExpiryDate = workingStandard.ExpiryDate; _uow.WorkingStandardRepository.Update(updateStandard); //_uow.Commit(); return(RedirectToAction("Index")); } return(View(workingStandard)); }
public void Post(int id) { var receipt = _repository.Get(id); receipt.StatusId = (int)Status.Posted; int totalQuantity; decimal totalCost; foreach (var item in receipt.ReceiptItem) { var newItem = new InventoryItem(); var oldItem = _inventoryItemRepository.Get(item.ItemId.Value); totalQuantity = oldItem != null ? oldItem.TotalQuantity.Value : 0; totalCost = oldItem != null ? oldItem.TotalCost.Value : 0; newItem.ItemId = item.ItemId; newItem.InventoryId = receipt.InventoryId; newItem.TotalCost = totalCost + item.TotalCost; newItem.TotalQuantity = totalQuantity + item.Quantity; newItem.AvgCost = newItem.TotalCost / newItem.TotalQuantity; if (oldItem == null) { _inventoryItemRepository.Add(newItem); } else { _inventoryItemRepository.Context.Entry(oldItem).CurrentValues.SetValues(newItem); } } var unitOfWork = new UnitOfWork((SCMSContext)_repository.Context); unitOfWork.Complete(); }
public ActionResult Edit([Bind(Include = "LotNumber,StockStandardId,ExpiryDate,IdCode,SupplierName,StockStandardName")] StockStandardEditViewModel stockstandard, HttpPostedFileBase uploadCofA, HttpPostedFileBase uploadMSDS) { var errors = ModelState.Values.SelectMany(v => v.Errors); if (ModelState.IsValid) { InventoryItemRepository inventoryRepo = _uow.InventoryItemRepository; var user = _uow.GetCurrentUser(); InventoryItem invItem = inventoryRepo.Get() .Where(item => item.StockStandard != null && item.StockStandard.StockStandardId == stockstandard.StockStandardId) .FirstOrDefault(); StockStandard updateStandard = invItem.StockStandard; updateStandard.StockStandardName = stockstandard.StockStandardName; updateStandard.IdCode = stockstandard.IdCode; updateStandard.LotNumber = stockstandard.LotNumber; updateStandard.LastModifiedBy = user.UserName; updateStandard.DateModified = DateTime.Today; updateStandard.ExpiryDate = stockstandard.ExpiryDate; _uow.StockStandardRepository.Update(updateStandard); //_uow.Commit(); if (uploadCofA != null) { var cofa = new CertificateOfAnalysis() { FileName = uploadCofA.FileName, ContentType = uploadCofA.ContentType, DateAdded = DateTime.Today }; using (var reader = new System.IO.BinaryReader(uploadCofA.InputStream)) { cofa.Content = reader.ReadBytes(uploadCofA.ContentLength); } stockstandard.CertificateOfAnalysis = cofa; //add certificate analysis invItem.CertificatesOfAnalysis.Add(cofa); } if (uploadMSDS != null) { var msds = new MSDS() { FileName = uploadMSDS.FileName, ContentType = uploadMSDS.ContentType, DateAdded = DateTime.Today }; using (var reader = new System.IO.BinaryReader(uploadMSDS.InputStream)) { msds.Content = reader.ReadBytes(uploadMSDS.ContentLength); } stockstandard.MSDS = msds; var msdsRepo = new MSDSRepository(); var oldSDS = msdsRepo.Get() .Where(item => item.InventoryItem.StockStandard != null && item.InventoryItem.StockStandard.StockStandardId == stockstandard.StockStandardId) .First(); oldSDS.Content = msds.Content; oldSDS.FileName = msds.FileName; oldSDS.ContentType = msds.ContentType; oldSDS.DateAdded = DateTime.Today; msdsRepo.Update(oldSDS); _uow.Commit(); } invItem.SupplierName = stockstandard.SupplierName; inventoryRepo.Update(invItem); //_uow.Commit(); return(RedirectToAction("Details", new { id = stockstandard.StockStandardId })); } return(View(stockstandard)); }