public ActionResult ManageClassRoom(ClassroomViewModel classRoomViewModel) { GetUIDropdownLists(); var classRoomModel = (Classroom)Mapper.Map(classRoomViewModel, typeof(ClassroomViewModel), typeof(Classroom)); if (classRoomViewModel.Select != null) { if (classRoomViewModel.ClassroomId < 1 || classRoomViewModel.CalendarBookingId < 1) { ModelState.AddModelError("ClassroomId", "ClassroomId and CalendarId are required"); } if (ModelState.IsValid) { var calendar = _repositoryServices.GetTeacherCalendarByBookingId(classRoomViewModel.CalendarBookingId); var classroom = _repositoryServices.GetClassroomById(classRoomViewModel.ClassroomId); classRoomViewModel = (ClassroomViewModel)Mapper.Map(classroom, typeof(Classroom), typeof(ClassroomViewModel)); classRoomViewModel.CalendarBookingId = (int)calendar.CalendarBookingId; classRoomViewModel.SubjectId = calendar.SubjectId; ModelState.Clear(); } return(View("ManageClassRoom", classRoomViewModel)); } if (ModelState.IsValid) { if (classRoomViewModel.Delete != null) { var classroom = _repositoryServices.GetClassroomById(classRoomViewModel.ClassroomId); _repositoryServices.DeleteClassroom(classroom); return(View("SuccessfullCreation")); } else { var calendar = _repositoryServices.GetTeacherCalendarByBookingId(classRoomViewModel.CalendarBookingId); _repositoryServices.ManageClassRoom(classRoomModel); calendar.SubjectId = classRoomModel.SubjectId; calendar.ClassId = (int)classRoomModel.ClassroomId; _repositoryServices.SaveOrUpdateCalendar(calendar); return(View("SuccessfullCreation")); } } return(View("ManageClassRoom", classRoomViewModel)); }