예제 #1
0
 public int AddGuestsToEvent(int eventId, List <GuestDTO> guests)
 {
     foreach (var guest in guests)
     {
         var           dataGuest  = guestRepo.Get(e => e.FirstName == guest.FirstName && e.LastName == guest.LastName && e.Phone == guest.Phone).Select(g => g.Id).FirstOrDefault();
         EventGuestDTO eventGuest = null;
         if (dataGuest == 0)
         {
             var guestID = guestService.CreateGuest(guest);
             eventGuest = new EventGuestDTO
             {
                 EventId = eventId,
                 GuestId = guestID
             };
         }
         else
         {
             eventGuest = new EventGuestDTO
             {
                 EventId = eventId,
                 GuestId = dataGuest
             };
         }
         var newEventGuest = (EventGuest) new EventGuest().InjectFrom(eventGuest);
         eventGuestRepo.Add(newEventGuest);
         unitOfWork.Commit();
     }
     return(0);
 }
        public bool CreateBooking(BookingViewModel viewModel)
        {
            DateTime startDate;
            DateTime endDate;
            decimal  totalPrice;
            int      numberOfPeople;
            int      stayTypeId;
            bool     success = false;
            int      idGuest = 0;
            int      roomId;
            decimal  discount = 0M;


            startDate      = viewModel.SearchRooms.StartDate.Date;
            endDate        = viewModel.SearchRooms.EndDate.Date;
            numberOfPeople = viewModel.SearchRooms.NumberOfPeople;
            stayTypeId     = viewModel.SelectedStayType.Id;
            roomId         = viewModel.SelectedRoom.Id;
            totalPrice     = viewModel.TotalPrice;
            var guestWrapper = viewModel.Guest;

            if (viewModel.IsGuestSelected && viewModel.SelectedGuestResult.Id > 0)
            {
                idGuest = viewModel.SelectedGuestResult.Id;
            }
            bool shouldCreateNewGuest = guestWrapper != null && viewModel.IsGuestSelected == false;

            if (shouldCreateNewGuest)
            {
                var guestForCreation = new
                {
                    FirstName = guestWrapper.FirstName,
                    LastName  = guestWrapper.LastName,
                    Phone     = guestWrapper.Phone,
                    Address   = guestWrapper.Address,
                    Email     = guestWrapper.Email,
                    Details   = guestWrapper.Details,
                    Jmbg      = guestWrapper.Jmbg
                };
                Guest newGuest = _guestService.CreateGuest(guestForCreation);
                idGuest = newGuest.Id;
            }
            int reservationId     = _reservationService.CreateReservation(idGuest, startDate, endDate, totalPrice, discount);
            int roomReservationId = _reservationService.CreateRoomReservation(reservationId, roomId, numberOfPeople, stayTypeId);

            success = reservationId > 0 && roomReservationId > 0;

            return(success);
        }