public IActionResult AddRoomType(RoomType roomType) { if (roomType.IsRegularRoom == true) { if (roomType.NumberOfRooms == null) { ModelState.AddModelError("NumberOfRooms", "Required"); } if (roomType.NumberOfBeds == null) { ModelState.AddModelError("NumberOfBeds", "Required"); } } if (ModelState.IsValid) { var check = _repository.GetAllRoomTypes().Where(q => q.Name == roomType.Name); if (check.Count() > 0) { ViewBag.AddRoomType = "This Room already Exists"; } else { _repository.AddRoomType(roomType); if (_repository.SaveChanges()) { ViewBag.AddRoomType = "Successfull!"; ModelState.Clear(); } else { ViewBag.AddRoomType = "Oops! Could not add new room type"; } } } return(View()); }