public ActionResult Edit(string id, ProductPriceDetailView productPriceDetailView) { #region Access Check bool hasPermission = GetEmployee().IsGuaranteed("ProductPrice_Update"); if (!hasPermission) { ModelState.AddModelError("", "AccessDenied"); return(View(productPriceDetailView)); } #endregion productPriceDetailView.EmployeeView = GetEmployee(); if (ModelState.IsValid) { try { EditProductPriceRequestOld request = new EditProductPriceRequestOld(); request.ID = Guid.Parse(id); request.ModifiedEmployeeID = GetEmployee().ID; request.Discontinued = productPriceDetailView.ProductPriceView.Discontinued; request.Imposition = productPriceDetailView.ProductPriceView.Imposition; request.MaxDiscount = productPriceDetailView.ProductPriceView.MaxDiscount; request.Note = productPriceDetailView.ProductPriceView.Note; request.ProductID = productPriceDetailView.ProductPriceView.ProductID; request.ProductPriceTitle = productPriceDetailView.ProductPriceView.ProductPriceTitle; request.SortOrder = productPriceDetailView.ProductPriceView.SortOrder; request.UnitPrice = productPriceDetailView.ProductPriceView.UnitPrice; request.RowVersion = productPriceDetailView.ProductPriceView.RowVersion; GeneralResponse response = this._productPriceService.EditProductPrice(request); if (response.success) { return(RedirectToAction("Index/" + request.ProductID)); } else { foreach (string error in response.ErrorMessages) { ModelState.AddModelError("", error); } return(View(productPriceDetailView)); } } catch (Exception ex) { ModelState.AddModelError("", ex.Message); return(View(productPriceDetailView)); } } return(View(productPriceDetailView)); }
public GeneralResponse EditProductPrice(EditProductPriceRequestOld request) { GeneralResponse response = new GeneralResponse(); ProductPrice productPrice = new ProductPrice(); productPrice = _productPriceRepository.FindBy(request.ID); if (productPrice != null) { try { productPrice.ModifiedDate = PersianDateTime.Now; productPrice.ModifiedEmployee = _employeeRepository.FindBy(request.ModifiedEmployeeID); productPrice.Imposition = request.Imposition; productPrice.MaxDiscount = request.MaxDiscount; if (request.ProductID != null) { productPrice.Product = this._productRepository.FindBy(request.ProductID); } if (request.ProductPriceTitle != null) { productPrice.ProductPriceTitle = request.ProductPriceTitle; } productPrice.UnitPrice = request.UnitPrice; if (request.Note != null) { productPrice.Note = request.Note; } productPrice.Discontinued = request.Discontinued; if (productPrice.RowVersion != request.RowVersion) { response.ErrorMessages.Add("کارشناس محترم، یک کاربر همزمان با شما در حال ویرایش این رکورد است. بنابراین اطلاعات شما ذخیره نمی شود."); return(response); } else { productPrice.RowVersion += 1; } if (productPrice.GetBrokenRules().Count() > 0) { foreach (BusinessRule businessRule in productPrice.GetBrokenRules()) { response.ErrorMessages.Add(businessRule.Rule); } return(response); } _productPriceRepository.Save(productPrice); _uow.Commit(); ////response.success = true; } catch (Exception ex) { response.ErrorMessages.Add(ex.Message); } } else { response.ErrorMessages.Add("هیچ موردی جهت ویرایش وجود ندارد."); } return(response); }