Ejemplo n.º 1
0
        public async Task <ActionResult> AddGuest(int id, BookingGuestViewModel model)
        {
            try
            {
                var booking = _context.Bookings.Find(id);

                model.Guest.BookingID = booking.ID;

                _context.BookingGuests.Add(model.Guest);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View());
            }
        }
Ejemplo n.º 2
0
        // GET: Customer/AddGuest/5
        public async Task <ActionResult> AddGuest(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            BookingGuestViewModel model = new BookingGuestViewModel()
            {
                Booking = await _context.Bookings.FindAsync(id),
                Guest   = new BookingGuest()
            };

            if (model.Booking == null)
            {
                return(NotFound());
            }

            return(View(model));
        }
Ejemplo n.º 3
0
 public ActionResult CheckInConfirmation(int BookingId, int NumberOfCheckInGuests)
 {
     if (ModelState.IsValid)
     {
         Booking         currentBooking = Db.Bookings.SingleOrDefault(i => i.BookingId == BookingId);
         Camping         currentSpot    = Db.Camping.SingleOrDefault(i => i.ItemId == currentBooking.ItemId);
         ApplicationUser currentGuest   = Db.Users.SingleOrDefault(i => i.GuestId == currentBooking.GuestId);
         int             numberOfDays   = 0;
         if ((currentBooking == null) || (currentSpot == null) || (currentGuest == null))//check if fetched data is valid
         {
             ViewBag.Errormessage = "Fetching of data did not succeed. Please try again.";
             return(PartialView("_FailedCheckIn"));
         }
         BookingGuestViewModel checkInBooking = new BookingGuestViewModel
         {
             BookingId      = currentBooking.BookingId,
             BookingPrice   = currentBooking.BookingPrice,
             GuestFirstName = currentGuest.GuestFirstName,
             GuestLastName  = currentGuest.GuestLastName,
             GuestId        = currentGuest.GuestId,
             ItemId         = currentSpot.ItemId,
             ItemName       = currentSpot.ItemName,
             NumberOfGuests = currentBooking.NumberOfGuests
         };
         if (currentBooking.NumberOfGuests != NumberOfCheckInGuests) //Check if PartySize differ from reservation
         {
             currentGuest.GuestHasToPay = currentGuest.GuestHasToPay - currentBooking.BookingPrice;
             numberOfDays = Booking.CalculateNumberOfDays(currentBooking.BookingStartDate, currentBooking.BookingEndDate);
             currentBooking.BookingPrice      = currentSpot.CampingPrice * NumberOfCheckInGuests * numberOfDays;
             currentGuest.GuestHasToPay       = currentGuest.GuestHasToPay + currentBooking.BookingPrice;
             currentBooking.GuestHasCheckedIn = true;
             currentBooking.GuestHasReserved  = false;
             currentBooking.NumberOfGuests    = NumberOfCheckInGuests;
             currentSpot.ItemIsOccupied       = true;
             int numberOfSaves = Db.SaveChanges();
             if (numberOfSaves != 3)
             {
                 ViewBag.Errormessage = "The Checkin failed! Please check the number of checked in persons and the cost for the stay.";
                 return(PartialView("_FailedCheckIn", checkInBooking));
             }
             checkInBooking.BookingPrice   = currentBooking.BookingPrice;
             checkInBooking.NumberOfGuests = NumberOfCheckInGuests;
             return(PartialView("_CheckInConfirmation", checkInBooking));
         }
         else
         {
             currentBooking.GuestHasCheckedIn = true;
             currentBooking.GuestHasReserved  = false;
             currentSpot.ItemIsOccupied       = true;
             int numberOfSaves = Db.SaveChanges();
             if (numberOfSaves != 2)
             {
                 ViewBag.Errormessage = "The Checkin failed! Please check the number of checked in persons and the cost for the stay.";
                 return(PartialView("_FailedCheckIn", checkInBooking));
             }
             return(PartialView("_CheckInConfirmation", checkInBooking));
         }
     }
     else
     {
         ViewBag.Errormessage = "The check out did not recive correct indata. Please try again.";
         return(PartialView("_FailedCheckIn"));
     }
 }
Ejemplo n.º 4
0
 public ActionResult ShowGuestDepartures(BookingGuestViewModel departures)
 {
     return(PartialView("_ShowGuestDepartures", departures));
 }
Ejemplo n.º 5
0
 public ActionResult ShowGuestArrivals(BookingGuestViewModel arrivals)
 {
     return(PartialView("_ShowGuestArrivals", arrivals));
 }
Ejemplo n.º 6
0
 public ActionResult CheckOutConfirmation([Bind(Include = "BookingId,NumberOfGuests")] BookingGuestViewModel checkingOutGuest)
 {
     if (ModelState.IsValid)
     {
         List <Booking>        allBookings           = Db.Bookings.ToList();
         Booking               departingBooking      = Db.Bookings.SingleOrDefault(i => i.BookingId == checkingOutGuest.BookingId);
         ApplicationUser       departingGuest        = Db.Users.SingleOrDefault(i => i.GuestId == departingBooking.GuestId);
         Camping               departedGuestSpot     = Db.Camping.SingleOrDefault(i => i.ItemId == departingBooking.ItemId);
         List <Booking>        allGuestBookings      = new List <Booking>();
         BookingGuestViewModel departingGuestBooking = new BookingGuestViewModel();
         List <LinkBooking>    allLinkBookings       = Db.LinkBookings.ToList();
         if ((allBookings == null) || (allLinkBookings == null)) //check if any data is received
         {
             ViewBag.Errormessage = "Fetching of data did not succeed. Please try again.";
             return(PartialView("_CheckOut"));
         }
         if ((departingBooking == null) || (departedGuestSpot == null) || (departingGuest == null))//check if fetched data is valid
         {
             ViewBag.Errormessage = "No booking, spot or guest could be found. Please try again.";
             return(PartialView("_CheckOut"));
         }
         foreach (var booking in allBookings) //collect any other bookings the guest have made
         {
             if ((booking.GuestId == departingGuest.GuestId) && ((booking.GuestHasCheckedIn == true) || booking.GuestHasReserved == true))
             {
                 allGuestBookings.Add(booking);
             }
         }
         if (allGuestBookings.Count == 1)//if no other bookings exist
         {
             departingGuest.GuestHasCheckedIn   = false;
             departingGuest.GuestHasReserved    = false;
             departingGuest.GuestHasPaid        = departingGuest.GuestHasPaid + departingBooking.BookingPrice;
             departingGuest.GuestHasToPay       = departingGuest.GuestHasToPay - departingBooking.BookingPrice;
             departingBooking.GuestHasCheckedIn = false;
             departingBooking.GuestHasReserved  = false;
             departingBooking.BookingIsPaid     = true;
             departedGuestSpot.ItemIsOccupied   = false;
             if (Db.SaveChanges() != 3)
             {
                 ViewBag.Errormessage = "The check out did partly succed.";
                 return(PartialView("_CheckOutConfirmation", checkingOutGuest));
             }
         }
         else //if more bookings exist handle the specific booking.
         {
             departingGuest.GuestHasPaid        = departingGuest.GuestHasPaid + departingBooking.BookingPrice;
             departingGuest.GuestHasToPay       = departingGuest.GuestHasToPay - departingBooking.BookingPrice;
             departingBooking.GuestHasCheckedIn = false;
             departingBooking.GuestHasReserved  = false;
             departingBooking.BookingIsPaid     = true;
             departedGuestSpot.ItemIsOccupied   = false;
         }
         int numberOfSaves = Db.SaveChanges();
         if (numberOfSaves != 3)
         {
             ViewBag.Errormessage = "The check out did partly succed.";
             return(PartialView("_FailedCheckOut", checkingOutGuest));
         }
         departingGuestBooking.BookingId      = departingBooking.BookingId;
         departingGuestBooking.GuestFirstName = departingGuest.GuestFirstName;
         departingGuestBooking.GuestLastName  = departingGuest.GuestLastName;
         departingGuestBooking.BookingPrice   = departingBooking.BookingPrice;
         departingGuestBooking.NumberOfGuests = departingBooking.NumberOfGuests;
         departingGuestBooking.ItemName       = departedGuestSpot.ItemName;
         return(PartialView("_CheckOutConfirmation", departingGuestBooking));
     }
     else
     {
         ViewBag.Errormessage = "The check out did not recive correct indata. Please try again.";
         return(PartialView("_FailedCheckOut", checkingOutGuest));
     }
 }