예제 #1
0
        public ActionResult Create(SkillViewModel skillViewModel)
        {
            try
            {
                //Leading and trailing empty spaces are trimmed
                skillViewModel.SkillName        = skillViewModel.SkillName.Trim();
                skillViewModel.SkillDescription = skillViewModel.SkillDescription.Trim();
                var skillCreateResult = _skillService.Create(skillViewModel.ToDTO());

                //-1 is returned if new Skill has already existing Skill Name
                if (skillCreateResult == -1)
                {
                    ModelState.AddModelError("SkillName", "Skill Name Already Exists");
                    return(View(skillViewModel));
                }
                else if (skillCreateResult == 0)
                {
                    ViewBag.Message = "Db Creation Error! Please Restart Application";
                }
                //Notification Message is stored in tempdata
                TempData["message"] = "Successfully Added Skill";
                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
예제 #2
0
        public ActionResult Edit(SkillViewModel skillView, FormCollection collection, int page)
        {
            try
            {
                //Pass current page to edit view
                ViewBag.CurrentPage = page;

                skillView.SkillName        = skillView.SkillName.Trim();
                skillView.SkillDescription = skillView.SkillDescription.Trim();
                var skillUpdateResult = _skillService.Update(skillView.ToDTO());

                //-1 is returned if the updated Skill Name already exists
                if (skillUpdateResult == -1)
                {
                    ModelState.AddModelError("SkillName", "Skill Name already exists");
                    return(View(skillView));
                }

                //Notification Message is stored in tempdata
                TempData["message"] = "Modified skill record";
                return(RedirectToAction("Index", new { page = page }));
            }
            catch
            {
                ModelState.AddModelError("SkillName", "Skill Name already exists");
                return(View(skillView));
            }
        }