예제 #1
0
        public ActionResult Create(CodeDetailView CodeDetailView)
        {
            CodeDetailView.EmployeeView = GetEmployee();

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

            GetRequest getCenterRequest = new GetRequest()
            {
                ID = CodeDetailView.CodeView.CenterID
            };
            CodeDetailView.CodeView.CenterName = _centerService.GetCenter(getCenterRequest).CenterView.CenterName;

            if (ModelState.IsValid)
            {
                try
                {
                    AddCodeRequestOld request = new AddCodeRequestOld();
                    request.CreateEmployeeID = GetEmployee().ID;
                    request.CenterID         = CodeDetailView.CodeView.CenterID;
                    request.CodeName         = CodeDetailView.CodeView.CodeName;

                    GeneralResponse response = _codeService.AddCode(request);

                    if (response.success)
                    {
                        return(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));
        }