public async Task <IActionResult> AddTimeSlot(TimeSlotBindingModel timeSlotBindingModel) { if (!ModelState.IsValid) { return(RedirectToAction("Index")); } var startTime = DateTime.Parse(timeSlotBindingModel.StartTime); var endTime = DateTime.Parse(timeSlotBindingModel.EndTime); var isValid = await _timeSlotService.AreStartTimeAndEndTimeLegal(startTime, endTime); if (!isValid) { return(BadRequest("The time slot is invalid")); } var timeSlot = await _timeSlotService.GetTimeSlotByTimeAsync(startTime, endTime); if (timeSlot != null) { return(BadRequest("The time slot is already taken")); } var roomModel = await _roomService.GetRoomByIdAsync(timeSlotBindingModel.RoomId); if (roomModel == null) { return(BadRequest("Could not find the room.")); } var sessionModel = await _sessionService.GetSessionByIdAsync(timeSlotBindingModel.SessionId); if (sessionModel == null) { return(BadRequest("Could not find the session")); } var timeSlotModel = new TimeSlotModel { StartTime = startTime, EndTime = endTime, RoomModel = roomModel, SessionModel = sessionModel }; var successful = await _timeSlotService.AddTimeSlotAsync(timeSlotModel); if (!successful) { return(BadRequest("Could not add the time slot")); } return(RedirectToAction("Index")); }