Esempio n. 1
0
        public GeneralResponse EditCreditService(EditCreditServiceRequestOld request)
        {
            GeneralResponse response      = new GeneralResponse();
            CreditService   creditService = new CreditService();

            creditService = _creditServiceRepository.FindBy(request.ID);

            if (creditService != null)
            {
                try
                {
                    creditService.ModifiedDate      = PersianDateTime.Now;
                    creditService.ModifiedEmployee  = _employeeRepository.FindBy(request.ModifiedEmployeeID);
                    creditService.CreditServiceCode = request.CreditServiceCode;
                    creditService.Discontinued      = request.Discontinued;
                    creditService.ExpDays           = request.ExpDays;
                    creditService.Imposition        = request.Imposition;
                    creditService.MaxDiscount       = request.MaxDiscount;
                    creditService.Network           = this._networkRepository.FindBy(request.NetworkID);
                    creditService.PurchaseUnitPrice = request.PurchaseUnitPrice;
                    creditService.ResellerUnitPrice = request.ResellerUnitPrice;
                    if (request.ServiceName != null)
                    {
                        creditService.ServiceName = request.ServiceName;
                    }
                    creditService.UnitPrice = request.UnitPrice;
                    if (request.Note != null)
                    {
                        creditService.Note = request.Note;
                    }
                    creditService.Discontinued = request.Discontinued;

                    if (creditService.RowVersion != request.RowVersion)
                    {
                        response.ErrorMessages.Add("EditConcurrencyKey");
                        return(response);
                    }
                    else
                    {
                        creditService.RowVersion += 1;
                    }

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

                        return(response);
                    }

                    _creditServiceRepository.Save(creditService);
                    _uow.Commit();

                    ////response.success = true;
                }
                catch (Exception ex)
                {
                    response.ErrorMessages.Add(ex.Message);
                }
            }
            else
            {
                response.ErrorMessages.Add("NoItemToEditKey");
            }
            return(response);
        }
Esempio n. 2
0
        public ActionResult Edit(string id, CreditServiceDetailView creditServiceDetailView)
        {
            creditServiceDetailView.EmployeeView = GetEmployee();

            #region Access Check
            bool hasPermission = GetEmployee().IsGuaranteed("CreditService_Update");
            if (!hasPermission)
            {
                ModelState.AddModelError("", "AccessDenied");
                return(View(creditServiceDetailView));
            }
            #endregion

            #region DropDownList For Network
            creditServiceDetailView.NetworkViews = _networkService.GetNetworks().NetworkViews;
            List <DropDownItem> list = new List <DropDownItem>();

            if (creditServiceDetailView.NetworkViews != null)
            {
                foreach (NetworkView networkView in creditServiceDetailView.NetworkViews)
                {
                    list.Add(new DropDownItem {
                        Value = networkView.ID.ToString(), Text = networkView.NetworkName
                    });
                }
            }
            var selectList = new SelectList(list, "Value", "Text");
            ViewData["Networks"] = selectList;
            #endregion


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

                    request.ID = Guid.Parse(id);
                    request.ModifiedEmployeeID = GetEmployee().ID;
                    request.CreditServiceCode  = creditServiceDetailView.CreditServiceView.CreditServiceCode;
                    request.Discontinued       = creditServiceDetailView.CreditServiceView.Discontinued;
                    request.ExpDays            = creditServiceDetailView.CreditServiceView.ExpDays;
                    request.Imposition         = creditServiceDetailView.CreditServiceView.Imposition;
                    request.MaxDiscount        = Convert.ToInt64(creditServiceDetailView.CreditServiceView.MaxDiscount);
                    request.Note              = creditServiceDetailView.CreditServiceView.Note;
                    request.NetworkID         = creditServiceDetailView.CreditServiceView.NetworkID;
                    request.PurchaseUnitPrice = Convert.ToInt64(creditServiceDetailView.CreditServiceView.PurchaseUnitPrice);
                    request.ResellerUnitPrice = Convert.ToInt64(creditServiceDetailView.CreditServiceView.ResellerUnitPrice);
                    request.ServiceName       = creditServiceDetailView.CreditServiceView.ServiceName;
                    request.UnitPrice         = Convert.ToInt64(creditServiceDetailView.CreditServiceView.UnitPrice);
                    request.RowVersion        = creditServiceDetailView.CreditServiceView.RowVersion;

                    GeneralResponse response = this._creditServiceService.EditCreditService(request);

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

            return(View(creditServiceDetailView));
        }