public async Task <IActionResult> GetOrder(int id) { var extra = await _repo.GetExtra(id); var extraToReturn = _mapper.Map <ExtraForUpdateDto>(extra); /// signalR section to copy out NotificationMessage notificationToReturn = null; var notificationFromRepo = await _hotelrepo.GetNotificationCounters(1); if (notificationFromRepo != null) { notificationFromRepo.OrderCount += 1; await _unitOfWork.CompleteAsync(); var notificationDto = _mapper.Map <NotificationDto>(notificationFromRepo); notificationToReturn = NotificationMessage.CreateNotification(1, "Order", "411", notificationDto); await _notifyHub.Clients.All.SendAsync("NewRequest", notificationToReturn); } return(Ok(notificationToReturn)); }
public async Task <IActionResult> CreateReservation(ReservationForCreateDto reservationForCreateDto) { if (reservationForCreateDto == null) { return(BadRequest()); } // retrieve current user's detail var currentUserId = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value); // var userFromRepo = await _hotelrepo.GetUser(currentUserId); // booking details var bookingFromRepo = await _repo.GuestCurrentBooking(currentUserId); if (bookingFromRepo == null) { return(NotFound($"Could not find guest booking")); } var reservationEntity = _mapper.Map <Reservation>(reservationForCreateDto); reservationEntity.GuestName = bookingFromRepo.GuestName; reservationEntity.Email = bookingFromRepo.Email; reservationEntity.Phone = bookingFromRepo.Phone; reservationEntity.RoomNumber = bookingFromRepo.RoomNumber; reservationEntity.IsNew = true; reservationEntity.IsDeleted = false; reservationEntity.IsCompleted = false; reservationEntity.BookingId = bookingFromRepo.Id; reservationEntity.HotelId = bookingFromRepo.HotelId; _repo.Add(reservationEntity); /// signalR section to copy out var notificationFromRepo = await _hotelrepo.GetNotificationCounters(bookingFromRepo.HotelId); if (notificationFromRepo != null) { notificationFromRepo.ReservationCount += 1; var notificationToReturn = _mapper.Map <NotificationDto>(notificationFromRepo); var notificationMessage = NotificationMessage.CreateNotification(bookingFromRepo.HotelId, "Reservation", reservationEntity.RoomNumber, notificationToReturn); await _notifyHub.Clients.All.SendAsync("NewRequest", notificationMessage); } if (await _unitOfWork.CompleteAsync()) { var reservationToReturn = _mapper.Map <ReservationForDetailDto>(reservationEntity); return(CreatedAtRoute("GetReservation", new { id = reservationEntity.Id }, reservationToReturn)); } throw new Exception("Creating the reservation failed on save"); }
public async Task <IActionResult> CreateOrder(MenuOrderCreateDto menuOrderCreateDto) { if (menuOrderCreateDto == null) { return(BadRequest()); } var currentUserId = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value); // booking details var bookingFromRepo = await _bookingrepo.GuestCurrentBooking(currentUserId); if (bookingFromRepo == null) { return(NotFound($"Could not find guest booking")); } var menuOrderEntity = _mapper.Map <MenuOrder>(menuOrderCreateDto); menuOrderEntity.GuestName = bookingFromRepo.GuestName; menuOrderEntity.Email = bookingFromRepo.Email; menuOrderEntity.Phone = bookingFromRepo.Phone; menuOrderEntity.RoomNumber = bookingFromRepo.RoomNumber; menuOrderEntity.OrderStatus = "Pending"; menuOrderEntity.IsDeleted = false; menuOrderEntity.BookingId = bookingFromRepo.Id; menuOrderEntity.HotelId = bookingFromRepo.HotelId; _repo.Add(menuOrderEntity); /// signalR section to copy out var notificationFromRepo = await _hotelrepo.GetNotificationCounters(bookingFromRepo.HotelId); if (notificationFromRepo != null) { notificationFromRepo.OrderCount += 1; var notificationToReturn = _mapper.Map <NotificationDto>(notificationFromRepo); var notificationMessage = NotificationMessage.CreateNotification(bookingFromRepo.HotelId, "Order", menuOrderEntity.RoomNumber, notificationToReturn); await _notifyHub.Clients.All.SendAsync("NewRequest", notificationMessage); } if (await _unitOfWork.CompleteAsync()) { var MenuOrderToReturn = _mapper.Map <MenuOrderUpdateDto>(menuOrderEntity); return(CreatedAtRoute("GetMenuOrder", new { id = MenuOrderToReturn.Id }, MenuOrderToReturn)); } throw new Exception("Creating the taxi failed on save"); }