public ActionResult Create([Bind(Include = "DepartmentId,DeptName,DeptCode,DeptCredit,Adminstrator,StratDate,Building")] Department department) { if (ModelState.IsValid) { if (!_departmentBusiness.IsDeptNameExists(department.DeptName)) { if (!_departmentBusiness.IsDeptCodeExists(department.DeptCode)) { _departmentBusiness.Add(department); ViewBag.Message = "Department Created Successfully!"; // return RedirectToAction("Index"); } else { ViewBag.Message = "Department Code Already Exists !"; } } else { ViewBag.Message = "Department Name Already Exists !"; } } return(View(department)); }
public ActionResult DepartmentAdd(DepartmentActionView model) { try { HttpCookie reqCookies = Request.Cookies["StaffLoginCookie"]; ResponseStaffLogin login = JsonConvert.DeserializeObject <ResponseStaffLogin>(reqCookies.Value.ToString().UrlDecode()); if (ModelState.IsValid) { model.ActionBy = login.Account; if (_departmentBusiness.Add(model)) { _departmentBusiness.Save(); return(Redirect("/Staff/Department")); } } return(View(model)); } catch (Exception) { return(View(model)); } }