コード例 #1
0
        public ActionResult Create([Bind(Include = "Id,DepartmentId,Name,ShortName")] Designation designation)
        {
            if (ModelState.IsValid)
            {
                bool isName      = _designationManager.IsDesignationNameExist(designation.Name);
                bool isShortName = _designationManager.IsDesignationShortNameExist(designation.ShortName);

                if (isName)
                {
                    ViewBag.NameCssClass    = "Alert Alert-warning";
                    ViewBag.NameMessageType = "Warning";
                    ViewBag.NameMessage     = "This designation name already exist!";
                }
                else if (isShortName)
                {
                    ViewBag.ShortNameCssClass    = "Alert Alert-warning";
                    ViewBag.ShortNameMessageType = "Warning";
                    ViewBag.ShortNameMessage     = "This designation short-name already exist!";
                }
                else
                {
                    _designationManager.Add(designation);
                    return(RedirectToAction("Index"));
                }
            }

            ViewBag.DepartmentId = new SelectList(_departmentManager.GetAll(), "Id", "Name", designation.DepartmentId);

            return(View(designation));
        }
コード例 #2
0
        public ActionResult Index(Designation designation)
        {
            if (ModelState.IsValid)
            {
                if (_designationManager.Add(designation))
                {
                    ViewBag.SuccessMsg = "Add designation";
                    // return RedirectToAction("Index");
                }
                else
                {
                    ViewBag.FailMsg = "designation ADD Failed";
                }
            }

            else
            {
                ViewBag.FailMsg = "Validation Error";
            }

            return(View());
        }