Beispiel #1
0
        public GeneralResponse EditMoneyAccount(EditMoneyAccountRequestOld request)
        {
            GeneralResponse response     = new GeneralResponse();
            MoneyAccount    moneyAccount = new MoneyAccount();

            moneyAccount = _moneyAccountRepository.FindBy(request.ID);

            if (moneyAccount != null)
            {
                try
                {
                    moneyAccount.ModifiedDate     = PersianDateTime.Now;
                    moneyAccount.ModifiedEmployee = _employeeRepository.FindBy(request.ModifiedEmployeeID);
                    moneyAccount.AccountName      = request.AccountName;
                    moneyAccount.BAccountInfo     = request.BAccountInfo;
                    moneyAccount.BAccountNumber   = request.BAccountNumber;
                    moneyAccount.IsBankAccount    = request.IsBankAccount;
                    moneyAccount.Pay          = request.Pay;
                    moneyAccount.Receipt      = request.Receipt;
                    moneyAccount.Discontinued = request.Discontinued;

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

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

                        return(response);
                    }

                    _moneyAccountRepository.Save(moneyAccount);
                    _uow.Commit();

                    ////response.success = true;
                }
                catch (Exception ex)
                {
                    response.ErrorMessages.Add(ex.Message);
                }
            }
            else
            {
                response.ErrorMessages.Add("هیچ موردی جهت ویرایش وجود ندارد.");
            }
            return(response);
        }
Beispiel #2
0
        public ActionResult Edit(string id, MoneyAccountDetailView moneyAccountDetailView)
        {
            moneyAccountDetailView.EmployeeView = GetEmployee();

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


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

                    request.ID = Guid.Parse(id);
                    request.ModifiedEmployeeID = GetEmployee().ID;
                    request.AccountName        = moneyAccountDetailView.MoneyAccountView.AccountName;
                    request.BAccountInfo       = moneyAccountDetailView.MoneyAccountView.BAccountInfo;
                    request.BAccountNumber     = moneyAccountDetailView.MoneyAccountView.BAccountNumber;
                    request.IsBankAccount      = moneyAccountDetailView.MoneyAccountView.IsBankAccount;
                    request.Pay        = moneyAccountDetailView.MoneyAccountView.Pay;
                    request.Receipt    = moneyAccountDetailView.MoneyAccountView.Receipt;
                    request.RowVersion = moneyAccountDetailView.MoneyAccountView.RowVersion;

                    GeneralResponse response = this._moneyAccountService.EditMoneyAccount(request);

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

            return(View(moneyAccountDetailView));
        }