Beispiel #1
0
        public GeneralResponse EditLevelLevel(EditLevelLevelRequest request)
        {
            GeneralResponse response   = new GeneralResponse();
            LevelLevel      levelLevel = new LevelLevel();

            levelLevel = _levelLevelRepository.FindBy(request.ID);

            if (levelLevel != null)
            {
                try
                {
                    levelLevel.ModifiedDate     = PersianDateTime.Now;
                    levelLevel.ModifiedEmployee = _employeeRepository.FindBy(request.ModifiedEmployeeID);
                    if (request.LevelID != levelLevel.Level.ID)
                    {
                        levelLevel.Level = this._levelRepository.FindBy(request.LevelID);
                    }
                    if (request.NextLevelID != levelLevel.RelatedLevel.ID)
                    {
                        levelLevel.RelatedLevel = this._levelRepository.FindBy(request.NextLevelID);
                    }

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

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

                        return(response);
                    }

                    _levelLevelRepository.Save(levelLevel);
                    _uow.Commit();

                    ////response.success = true;
                }
                catch (Exception ex)
                {
                    response.ErrorMessages.Add(ex.Message);
                }
            }
            else
            {
                response.ErrorMessages.Add("NoItemToEditKey");
            }
            return(response);
        }
        public ActionResult Edit(string id, LevelLevelDetailView levelLevelDetailView)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    EditLevelLevelRequest request = new EditLevelLevelRequest();

                    request.ID = Guid.Parse(id);
                    request.ModifiedEmployeeID = GetEmployee().ID; request.LevelID = levelLevelDetailView.LevelLevelView.LevelID;
                    request.NextLevelID        = levelLevelDetailView.LevelLevelView.RelatedLevelID;
                    request.RowVersion         = levelLevelDetailView.LevelLevelView.RowVersion;

                    GeneralResponse response = this._levelLevelService.EditLevelLevel(request);

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

            return(View(levelLevelDetailView));
        }