예제 #1
0
        public GeneralResponse EditStore(EditStoreRequestOld request)
        {
            GeneralResponse response = new GeneralResponse();
            Store           store    = new Store();

            store = _storeRepository.FindBy(request.ID);

            if (store != null)
            {
                try
                {
                    store.ModifiedDate     = PersianDateTime.Now;
                    store.ModifiedEmployee = _employeeRepository.FindBy(request.ModifiedEmployeeID);
                    if (request.OwnerEmployeeID != null)
                    {
                        store.OwnerEmployee = this._employeeRepository.FindBy(request.OwnerEmployeeID);
                    }
                    if (request.StoreName != null)
                    {
                        store.StoreName = request.StoreName;
                    }
                    if (request.Note != null)
                    {
                        store.Note = request.Note;
                    }

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

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

                        return(response);
                    }

                    _storeRepository.Save(store);
                    _uow.Commit();

                    ////response.success = true;
                }
                catch (Exception ex)
                {
                    response.ErrorMessages.Add(ex.Message);
                }
            }
            else
            {
                response.ErrorMessages.Add("NoItemToEditKey");
            }
            return(response);
        }
예제 #2
0
        public ActionResult Edit(string id, StoreDetailView storeDetailView)
        {
            storeDetailView.EmployeeView = GetEmployee();

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


            #region DropDownList For Owner Employee

            storeDetailView.EmployeeViews = _employeeService.GetInstallExprets().EmployeeViews;
            List <DropDownItem> list = new List <DropDownItem>();

            if (storeDetailView.EmployeeViews != null)
            {
                foreach (EmployeeView employeeView in storeDetailView.EmployeeViews)
                {
                    list.Add(new DropDownItem {
                        Value = employeeView.ID.ToString(), Text = employeeView.Name
                    });
                }
            }
            var selectList = new SelectList(list, "Value", "Text");
            ViewData["InstallExprets"] = selectList;
            #endregion

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

                    request.ID = Guid.Parse(id);
                    request.ModifiedEmployeeID = GetEmployee().ID;
                    request.OwnerEmployeeID    = storeDetailView.StoreView.OwnerEmployeeID;
                    request.StoreName          = storeDetailView.StoreView.StoreName;
                    request.Note       = storeDetailView.StoreView.Note;
                    request.RowVersion = storeDetailView.StoreView.RowVersion;

                    GeneralResponse response = this._storeService.EditStore(request);

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

            return(View(storeDetailView));
        }