public ActionResult AddNewSubject(Subject model) { bool isAdded = false; bool IsUpdated = false; ViewBag.AllSubjects = new SelectList(Subject.GetAll(), "Id", "Name"); ViewBag.AlreadyExists = false; if (ModelState.IsValid) { if (model.ParentId == null) { if (model.Id != 0) { IsUpdated = Subject.Update(model.Id, null, model.Name); } else { isAdded = Subject.AddNew(model.Name, ApplicationHelper.LoggedUserId); } } else { if (model.Id != 0) { IsUpdated = Subject.Update(model.Id, model.ParentId, model.Name); } else { isAdded = Subject.AddNew(model.ParentId.Value, model.Name, ApplicationHelper.LoggedUserId); } } if (isAdded || IsUpdated) { return(RedirectToAction("Index")); } ViewBag.AlreadyExists = true; return(View(model)); } else { return(View(model)); } }