コード例 #1
0
ファイル: ProductController.cs プロジェクト: zafariNet/Saman
        public ActionResult Edit(string id, ProductDetailView productDetailView)
        {
            #region Access Check
            bool hasPermission = GetEmployee().IsGuaranteed("Product_Update");
            if (!hasPermission)
            {
                ModelState.AddModelError("", "AccessDenied");
                return(View(productDetailView));
            }
            #endregion

            productDetailView.EmployeeView = GetEmployee();

            if (ModelState.IsValid)
            {
                try
                {
                    EditProductRequestOld request = new EditProductRequestOld();

                    request.ID = Guid.Parse(id);
                    request.ModifiedEmployeeID = GetEmployee().ID;
                    request.Discontinued       = productDetailView.ProductView.Discontinued;
                    request.ProductName        = productDetailView.ProductView.ProductName;
                    request.Discontinued       = productDetailView.ProductView.Discontinued;
                    request.ProductCategoryID  = productDetailView.ProductView.ProductCategoryID;
                    request.ProductCode        = productDetailView.ProductView.ProductCode;
                    request.Note         = productDetailView.ProductView.Note;
                    request.UnitsInStock = productDetailView.ProductView.UnitsInStock;
                    request.RowVersion   = productDetailView.ProductView.RowVersion;

                    GeneralResponse response = this._productService.EditProduct(request);

                    if (response.success)
                    {
                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        foreach (string error in response.ErrorMessages)
                        {
                            ModelState.AddModelError("", error);
                        }
                        return(View(productDetailView));
                    }
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("", ex.Message);
                    return(View(productDetailView));
                }
            }

            return(View(productDetailView));
        }
コード例 #2
0
ファイル: ProductService.cs プロジェクト: zafariNet/Saman
        public GeneralResponse EditProduct(EditProductRequestOld request)
        {
            GeneralResponse response = new GeneralResponse();
            Product         product  = new Product();

            product = _productRepository.FindBy(request.ID);

            if (product != null)
            {
                try
                {
                    product.ModifiedDate     = PersianDateTime.Now;
                    product.ModifiedEmployee = _employeeRepository.FindBy(request.ModifiedEmployeeID);
                    if (request.ProductCategoryID != product.ProductCategory.ID)
                    {
                        product.ProductCategory = this._productCategoryRepository.FindBy(request.ProductCategoryID);
                    }
                    product.ProductCode = request.ProductCode;
                    if (request.ProductName != null)
                    {
                        product.ProductName = request.ProductName;
                    }
                    //product.UnitsInStock = request.UnitsInStock;
                    if (request.Note != null)
                    {
                        product.Note = request.Note;
                    }
                    product.Discontinued = request.Discontinued;

                    if (product.RowVersion != request.RowVersion)
                    {
                        response.ErrorMessages.Add("کارشناس محترم، یک کاربر همزمان با شما در حال ویرایش این رکورد است. بنابراین اطلاعات شما ذخیره نمی شود.");
                        return(response);
                    }
                    else
                    {
                        product.RowVersion += 1;
                    }

                    if (product.GetBrokenRules().Count() > 0)
                    {
                        foreach (BusinessRule businessRule in product.GetBrokenRules())
                        {
                            response.ErrorMessages.Add(businessRule.Rule);
                        }

                        return(response);
                    }

                    _productRepository.Save(product);
                    _uow.Commit();
                }
                catch (Exception ex)
                {
                    response.ErrorMessages.Add(ex.Message);
                }
            }
            else
            {
                response.ErrorMessages.Add("هیچ موردی جهت ویرایش وجود ندارد.");
            }
            return(response);
        }