public JsonResult CreditServices_Edit(EditCreditServiceRequest request)
        {
            GeneralResponse response = new GeneralResponse();

            #region Access Check
            bool hasPermission = GetEmployee().IsGuaranteed("CreditService_Update");
            if (!hasPermission)
            {
                response.ErrorMessages.Add("AccessDenied");
                return(Json(response, JsonRequestBehavior.AllowGet));
            }
            #endregion

            response = _creditServiceService.EditCreditServices(request, GetEmployee().ID);

            return(Json(response, JsonRequestBehavior.AllowGet));
        }
Exemple #2
0
        public GeneralResponse EditCreditServices(EditCreditServiceRequest request, Guid EmployeeID)
        {
            GeneralResponse response = new GeneralResponse();

            try
            {
                CreditService creditService = _creditServiceRepository.FindBy(request.ID);

                if (creditService != null)
                {
                    #region Validate Uncredit Service Code

                    string _errorMessag = EditValidate(request.CreditServiceCode, request.ServiceName, request.ID);

                    if (_errorMessag != "NoError")
                    {
                        response.ErrorMessages.Add(_errorMessag);
                        return(response);
                    }

                    #endregion


                    if (request.MaxDiscount > request.UnitPrice)
                    {
                        response.ErrorMessages.Add("تخفیف نمیتواند بیش از قیمت پایه باشد");
                        return(response);
                    }

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

                    #region Validation

                    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);
                    }

                    #endregion

                    _creditServiceRepository.Save(creditService);
                }
                else
                {
                    response.ErrorMessages.Add("NoItemToEditKey");
                }
                _uow.Commit();
            }
            catch (Exception ex)
            {
                response.ErrorMessages.Add(ex.Message);
                if (ex.InnerException != null)
                {
                    response.ErrorMessages.Add(ex.InnerException.Message);
                }
            }

            return(response);
        }