public void AddBooking(BookingForInsert booking) { var bookingToAdd = _mapper.Map <Booking>(booking); bookingToAdd.User = _context.Users.Find(booking.UserId); bookingToAdd.Lab = _context.ComputerLabs.Find(booking.Lab.Id); bookingToAdd.Status = "Đã đặt"; Add(bookingToAdd); }
public BookingForDetailed UpdateBooking(int id, BookingForInsert booking) { var userId = Convert.ToInt32(User.FindFirst(ClaimTypes.NameIdentifier).Value); if (_service.GetById(id).UserId != userId) { throw new ForbiddenException("Không có quyền chỉnh sửa lịch đặt phòng này"); } booking.UserId = userId; return(_service.UpdateBooking(id, booking)); }
public BookingForDetailed UpdateBooking(int id, BookingForInsert booking) { var bookingToUpdate = GetById(id) ?? throw new BadRequestException("Lịch đặt phòng này không tồn tại"); if (bookingToUpdate.BookingDate.CompareTo(DateTime.Now) <= 0) { throw new BadRequestException("Không thể thay đổi lịch đặt phòng sau khi đã hoàn thành"); } _mapper.Map(booking, bookingToUpdate); bookingToUpdate.User = _context.Users.Find(booking.UserId); bookingToUpdate.Lab = _context.ComputerLabs.Find(booking.Lab.Id); bookingToUpdate.Status = "Đã cập nhật"; _context.SaveChanges(); return(_mapper.Map <BookingForDetailed>(GetById(id))); }
public void AddBooking(BookingForInsert booking) { booking.UserId = Convert.ToInt32(User.FindFirst(ClaimTypes.NameIdentifier).Value); _service.AddBooking(booking); }