Exemplo n.º 1
0
        public ActionResult Create(SuctionModeDetailView suctionModeDetailView)
        {
            suctionModeDetailView.EmployeeView = GetEmployee();

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

            if (ModelState.IsValid)
            {
                try
                {
                    AddSuctionModeRequestOld request = new AddSuctionModeRequestOld();
                    request.CreateEmployeeID = GetEmployee().ID;
                    request.SuctionModeName  = suctionModeDetailView.SuctionModeView.SuctionModeName;

                    GeneralResponse response = this._suctionModeService.AddSuctionMode(request);

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

            return(View(suctionModeDetailView));
        }
Exemplo n.º 2
0
        public GeneralResponse AddSuctionMode(AddSuctionModeRequestOld request)
        {
            GeneralResponse response = new GeneralResponse();

            try
            {
                SuctionMode suctionMode = new SuctionMode();
                suctionMode.ID              = Guid.NewGuid();
                suctionMode.CreateDate      = PersianDateTime.Now;
                suctionMode.CreateEmployee  = _employeeRepository.FindBy(request.CreateEmployeeID);
                suctionMode.SuctionModeName = request.SuctionModeName;
                suctionMode.SortOrder       = this.GetSortOrder();
                suctionMode.RowVersion      = 1;

                #region Validation

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

                    return(response);
                }

                #endregion

                _suctionModeRepository.Add(suctionMode);
                _uow.Commit();
            }
            catch (Exception ex)
            {
                response.ErrorMessages.Add(ex.Message);
            }

            return(response);
        }