public FeedbackForDetailed AddFeedback(FeedbackForInsert feedback, int userId) { var booking = _context.Bookings.Find(feedback.BookingId) ?? throw new BadRequestException("Lịch đặt phòng không tồn tại"); if (booking.UserId != userId) { throw new ForbiddenException("Không có quyền phản hồi cho lịch đặt phòng này"); } if (booking.Feedback != null) { throw new BadRequestException("Bạn đã phản hồi cho lịch đặt phòng này"); } var feedbackToAdd = _mapper.Map <Feedback>(feedback); feedbackToAdd.Booking = _context.Bookings.Find(feedback.BookingId); feedbackToAdd.LabId = feedbackToAdd.Booking.LabId; feedbackToAdd.FeedbackDate = DateTime.Now; _context.Feedbacks.Add(feedbackToAdd); _context.SaveChanges(); return(_mapper.Map <FeedbackForDetailed>(feedbackToAdd)); }
public FeedbackForDetailed AddFeedback(FeedbackForInsert feedback) { var userId = Convert.ToInt32(User.FindFirst(ClaimTypes.NameIdentifier).Value); return(_service.AddFeedback(feedback, userId)); }