public async Task <ActionResult> UpdateSchedulingAsync([FromBody] SchedulingUpdateModel schedulingUM) { try { //lấy id của scheduling cần update var scheduling = _schedulingService.GetScheduling(schedulingUM.Id); if (scheduling == null) { return(NotFound()); } if (_roomService.GetRoom(schedulingUM.RoomId).SpecialityId != Guid.Parse(scheduling.SpecialityId)) { return(BadRequest("Room này không đúng chuyên khoa hiện hành!")); } if (scheduling.IsAvailable) { return(BadRequest("Can not update this scheduling!")); } var totalBlock = ((schedulingUM.EndTime - schedulingUM.StartTime) * 2).TotalHours; if (totalBlock <= 0 || ((schedulingUM.StartTime.Minutes != 30 && schedulingUM.StartTime.Minutes != 0) || (schedulingUM.EndTime.Minutes != 0 && schedulingUM.EndTime.Minutes != 30))) { return(BadRequest("Vui lòng nhập đúng giờ!")); } //xóa blocks dựa vào id của scheduling _blockService.DeleteBlock(b => b.SchedulingId == scheduling.Id); //update data trong bảng scheduling _schedulingService.UpdateScheduling(schedulingUM.Adapt(scheduling), (await _userManager.GetUserAsync(User)).UserName); //tạo lại số lượng blocks dựa vào starttime và endtime cần update _schedulingService.CreateBlocks(scheduling, Convert.ToInt32(totalBlock)); _schedulingService.Save(); } catch (Exception) { return(BadRequest("update fail vì trùng phòng hoặc trùng bác sĩ tại một thời điểm.")); } return(Ok()); }