public async Task <ArrangeRoomResponseStudent> ApproveRoomBookingRequest(int id) { var roomBooking = await FindById(id); //Check if room request if (roomBooking.Status != RequestStatus.Pending) { throw new HttpStatusCodeException(HttpStatusCode.Forbidden, "RoomService: Request is not a pending request"); } //Get student by id in room booking var student = await _repoWrapper.Student.FindByIdAsync(roomBooking.StudentId); if (student == null) { throw new HttpStatusCodeException(HttpStatusCode.NotFound, "RoomService: Student not found"); } //Get active room with appropriate gender sorted by ascending room vacancy var rooms = await _repoWrapper.Room.GetAllActiveRoomWithSpecificGenderAndRoomTypeSortedByVacancy(student.Gender, roomBooking.TargetRoomType); if (rooms == null || !rooms.Any()) { throw new HttpStatusCodeException(HttpStatusCode.NotFound, "RoomService: Suitable Room not found"); } var room = rooms[0]; //Attach room's id to student student.RoomId = room.RoomId; student.IsHold = true; room.CurrentNumberOfStudent++; roomBooking.Status = RequestStatus.Approved; var maxDayForCompleteRoomBooking = await _paramService.FindById(GlobalParams.MaxDayForCompleteRoomBooking); if (maxDayForCompleteRoomBooking?.Value == null) { throw new HttpStatusCodeException(HttpStatusCode.NotFound, "RoomService: MaxDayForCompleteRoomBooking not found"); } var rejectDate = DateHelper.AddBusinessDays(DateTime.Now.AddHours(GlobalParams.TimeZone), maxDayForCompleteRoomBooking.Value.Value); roomBooking.RejectDate = new DateTime(rejectDate.Year, rejectDate.Month, rejectDate.Day, 17, 59, 0); await _repoWrapper.Student.UpdateAsyncWithoutSave(student, student.StudentId); await _repoWrapper.Room.UpdateAsyncWithoutSave(room, room.RoomId); await _repoWrapper.RoomBooking.UpdateAsyncWithoutSave(roomBooking, roomBooking.RoomBookingRequestFormId); await _repoWrapper.Save(); return(ArrangeRoomResponseStudent.ResponseFromEntity(student, room, roomBooking)); }
public static RoomBookingRequestForm EntityFromRequest(ImportRoomBookingRequest request, int studentId, int maxDayForApproveRoomBooking) { var rejectDate = DateHelper.AddBusinessDays(DateTime.Now.AddHours(7), maxDayForApproveRoomBooking - 1); return(new RoomBookingRequestForm() { StudentId = studentId, CreatedDate = DateTime.Now.AddHours(GlobalParams.TimeZone), LastUpdated = DateTime.Now.AddHours(GlobalParams.TimeZone), Month = request.Month, Status = RequestStatus.Approved, TargetRoomType = request.TargetRoomType, PriorityType = request.PriorityType, //Set reject date to before 6pm RejectDate = new DateTime(rejectDate.Year, rejectDate.Month, rejectDate.Day, 17, 59, 0) }); }
public static RoomBookingRequestForm NewEntityFromRequest(SendRoomBookingRequest request, int maxDayForApproveRoomBooking) { var rejectDate = DateHelper.AddBusinessDays(DateTime.Now.AddHours(GlobalParams.TimeZone), maxDayForApproveRoomBooking); return(new RoomBookingRequestForm() { StudentId = request.StudentId, CreatedDate = DateTime.Now.AddHours(GlobalParams.TimeZone), LastUpdated = DateTime.Now.AddHours(GlobalParams.TimeZone), Month = request.Month, Status = RequestStatus.Pending, TargetRoomType = request.TargetRoomType, IdentityCardImageUrl = request.IdentityCardImageUrl, PriorityImageUrl = request.PriorityImageUrl, StudentCardImageUrl = request.StudentCardImageUrl, PriorityType = request.PriorityType, //Set reject date to before 6pm RejectDate = new DateTime(rejectDate.Year, rejectDate.Month, rejectDate.Day, 17, 59, 0) }); }