public ActionResult ManageStudent(StudentViewModel studentViewModel) { GetUIDropdownLists(); if (studentViewModel.Select != null) { if (studentViewModel.StudentId < 1) { ModelState.AddModelError("StudentId", "StudentId is required"); } if (ModelState.IsValid) { var student = _repositoryServices.GetStudentById(studentViewModel.StudentId); studentViewModel = (StudentViewModel)Mapper.Map(student, typeof(Student), typeof(StudentViewModel)); ModelState.Clear(); } return(View("ManageStudent", studentViewModel)); } if (ModelState.IsValid) { if (studentViewModel.Delete != null) { var student = _repositoryServices.GetStudentById(studentViewModel.StudentId); _repositoryServices.DeleteStudent(student); return(View("SuccessfullCreation")); } else { var studentModel = (Student)Mapper.Map(studentViewModel, typeof(StudentViewModel), typeof(Student)); _repositoryServices.ManageStudent(studentModel); return(View("SuccessfullCreation")); } } return(View("ManageStudent", studentViewModel)); }