Exemple #1
0
        public ActionResult Edit(string id, CodeDetailView codeDetailView)
        {
            codeDetailView.EmployeeView = GetEmployee();

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

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

                    request.ID = Guid.Parse(id);
                    request.ModifiedEmployeeID = GetEmployee().ID;
                    request.CenterID           = codeDetailView.CodeView.CenterID;
                    request.CodeName           = codeDetailView.CodeView.CodeName;
                    request.RowVersion         = codeDetailView.CodeView.RowVersion;

                    GeneralResponse response = this._codeService.EditCode(request);

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

            return(View(codeDetailView));
        }
Exemple #2
0
        public GeneralResponse EditCode(EditCodeRequestOld request)
        {
            GeneralResponse response = new GeneralResponse();
            Code            code     = new Code();

            code = _codeRepository.FindBy(request.ID);

            if (code != null)
            {
                try
                {
                    code.ModifiedDate     = PersianDateTime.Now;
                    code.ModifiedEmployee = _employeeRepository.FindBy(request.ModifiedEmployeeID);
                    code.Center           = _centerRepository.FindBy(request.CenterID);
                    //string oldCode = code.CodeName;
                    code.CodeName = request.CodeName;

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

                    #region If Duplicate, send Error message

                    Infrastructure.Querying.Query query = new Infrastructure.Querying.Query();
                    Criterion criterion = new Criterion("CodeName", code.CodeName, CriteriaOperator.Equal);
                    query.Add(criterion);

                    //if (_codeRepository.FindBy(query).Count() > 0)
                    if (_codeRepository.FindBy(query) != null)
                    {
                        //Code exitstCode = _codeRepository.FindBy(query).FirstOrDefault();
                        //response.ErrorMessages.Add(String.Format("این پیش شماره قبلاً برای مرکز مخابراتی «{0}» به ثبت رسیده است.", exitstCode.Center.CenterName));
                        response.ErrorMessages.Add("DuplicateCode");
                        return(response);
                    }

                    #endregion

                    #region Update Center Of Customers if exist any

                    //// customers of New Code
                    //IEnumerable<Customer> customers = _customerRepository.FindBy(code.CodeName);
                    //Center center = _centerRepository.FindBy(request.CenterID);

                    //if (customers != null && customers.Count() > 0)
                    //{
                    //    foreach (Customer customer in customers)
                    //    {
                    //        customer.Center = center;
                    //        _customerRepository.Save(customer);
                    //    }
                    //}

                    //// Customers of Old Code
                    //customers = _customerRepository.FindBy(oldCode);

                    //if (customers != null && customers.Count() > 0)
                    //{
                    //    foreach (Customer customer in customers)
                    //    {
                    //        customer.Center = null;
                    //        _customerRepository.Save(customer);
                    //    }
                    //}

                    #endregion

                    #region Validation

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

                        return(response);
                    }

                    #endregion

                    _codeRepository.Save(code);
                    _uow.Commit();
                }
                catch (Exception ex)
                {
                    response.ErrorMessages.Add(ex.Message);
                }
            }
            else
            {
                response.ErrorMessages.Add("NoItemToEditKey");
            }
            return(response);
        }