public ActionResult Edit(string id, ProductLogDetailView productLogDetailView) { productLogDetailView.EmployeeView = GetEmployee(); if (ModelState.IsValid) { try { EditProductLogRequest request = new EditProductLogRequest(); request.ID = Guid.Parse(id); request.ModifiedEmployeeID = GetEmployee().ID; request.Closed = productLogDetailView.ProductLogView.Closed; request.InputSerialNumber = productLogDetailView.ProductLogView.InputSerialNumber; request.LogDate = productLogDetailView.ProductLogView.LogDate; request.Note = productLogDetailView.ProductLogView.Note; request.ProductID = productLogDetailView.ProductLogView.ProductID; request.ProductSerialFrom = productLogDetailView.ProductLogView.ProductSerialFrom; request.ProductSerialTo = productLogDetailView.ProductLogView.ProductSerialTo; request.PurchaseBillNumber = productLogDetailView.ProductLogView.PurchaseBillNumber; request.PurchaseDate = productLogDetailView.ProductLogView.PurchaseDate; request.PurchaseUnitPrice = productLogDetailView.ProductLogView.PurchaseUnitPrice; request.SellerName = productLogDetailView.ProductLogView.SellerName; request.TotalLine = productLogDetailView.ProductLogView.TotalLine; if (productLogDetailView.ProductLogView.IOTypeForCreate == "O") { request.UnitsIO = -Math.Abs(productLogDetailView.ProductLogView.UnitsIO); } else { request.UnitsIO = Math.Abs(productLogDetailView.ProductLogView.UnitsIO); } request.RowVersion = productLogDetailView.ProductLogView.RowVersion; GeneralResponse response = this._productLogService.EditProductLog(request); if (response.success) { return(RedirectToAction("Index/" + request.ProductID)); } else { foreach (string error in response.ErrorMessages) { ModelState.AddModelError("", error); } return(View(productLogDetailView)); } } catch (Exception ex) { ModelState.AddModelError("", ex.Message); return(View(productLogDetailView)); } } return(View(productLogDetailView)); }
public GeneralResponse EditProductLog(EditProductLogRequest request) { GeneralResponse response = new GeneralResponse(); ProductLog productLog = new ProductLog(); productLog = _productLogRepository.FindBy(request.ID); if (productLog != null) { try { productLog.ModifiedDate = PersianDateTime.Now; productLog.ModifiedEmployee = _employeeRepository.FindBy(request.ModifiedEmployeeID); if (request.Note != null) { productLog.Note = request.Note; } productLog.Closed = request.Closed; if (request.InputSerialNumber != null) { productLog.InputSerialNumber = request.InputSerialNumber; } if (request.LogDate != null) { productLog.LogDate = request.LogDate; } if (request.ProductID != null) { productLog.Product = this._productRepository.FindBy(request.ProductID); } if (request.ProductSerialFrom != null) { productLog.ProductSerialFrom = request.ProductSerialFrom; } if (request.ProductSerialTo != null) { productLog.ProductSerialTo = request.ProductSerialTo; } if (request.PurchaseBillNumber != null) { productLog.PurchaseBillNumber = request.PurchaseBillNumber; } if (request.PurchaseDate != null) { productLog.PurchaseDate = request.PurchaseDate; } productLog.PurchaseUnitPrice = request.PurchaseUnitPrice; if (request.SellerName != null) { productLog.SellerName = request.SellerName; } // بدست آوردن اختلاف تعداد Product product = productLog.Product; if (productLog.UnitsIO != request.UnitsIO) { product.UnitsInStock += request.UnitsIO - productLog.UnitsIO; _productRepository.Save(product); } productLog.UnitsIO = request.UnitsIO; #region RowVersion if (productLog.RowVersion != request.RowVersion) { response.ErrorMessages.Add("EditConcurrencyKey"); return(response); } else { productLog.RowVersion += 1; } #endregion #region Validation if (productLog.GetBrokenRules().Count() > 0) { foreach (BusinessRule businessRule in productLog.GetBrokenRules()) { response.ErrorMessages.Add(businessRule.Rule); } return(response); } #endregion _productLogRepository.Save(productLog); _uow.Commit(); } catch (Exception ex) { response.ErrorMessages.Add(ex.Message); } } else { response.ErrorMessages.Add("NoItemToEditKey"); } return(response); }