public ActionResult Confirm(MakeBooking makeBooking=null)
        {
            makeBooking = GetMakeBookingSession();
            Service.DTO.BookingModel booking = new Service.DTO.BookingModel() { CheckInDate = makeBooking.CheckInDate, CheckOutDate = makeBooking.CheckOutDate };
            booking.Rooms = new List<Service.DTO.RoomModel>();
            foreach(RoomCategory room in makeBooking.RoomCategories)
            {
                for (int i = 0; i < room.NumberOfRooms; i++)
                {
                    booking.Rooms.Add(new Service.DTO.RoomModel() { TheCategory = new Service.DTO.CategoryModel() { Id = room.CategoryId } });
                }
            }
            //If there are no categories/rooms, send back to Rooms
            if (booking.Rooms.Count() == 0)
                return RedirectToAction("Rooms");

            booking.UserId = User.Identity.GetUserId();
            int bookingId = bookingService.SaveBooking(booking);
            if (bookingId!=0)
            {
                makeBooking.Id=bookingId;
                SaveMakeBookingSession(makeBooking);
                return RedirectToAction("Completed");
            }
            else
                return View(makeBooking);
        }
        private void SaveMakeBookingSession(MakeBooking booking)
        {
            //Lägga till ".Date" för att inte jämföra samma datum med olika tider.. ?
            if (booking.CheckInDate >= DateTime.Now.Date || booking.CheckOutDate > booking.CheckInDate)
            {

                Session["booking"] = booking;
            }
        }
        private void ChangeSessionRooms(MakeBooking booking)
        {
            MakeBooking savedBookingSession = (MakeBooking)Session["booking"];
            //TODO: Check dates and if null

            foreach(RoomCategory room in booking.RoomCategories)
            {
                savedBookingSession.RoomCategories.Where(cat => cat.CategoryId == room.CategoryId).First().NumberOfRooms = room.NumberOfRooms;
            }

            Session["booking"] = savedBookingSession;
        }
 private void ChangeSessionDate(MakeBooking booking)
 {
     MakeBooking savedBookingSession = (MakeBooking)Session["booking"];
     MakeBooking newBooking = new MakeBooking() { CheckInDate=booking.CheckInDate,CheckOutDate=booking.CheckOutDate};
     if(savedBookingSession==null)
     {
         #region  changethiscode
         List<RoomCategory> allCategories = GetAllRoomCategories().ToList();
         List<RoomCategory> newCategories = new List<RoomCategory>();
         double price=0;
         //Get price, and only display categories with a price for each day
         foreach (RoomCategory category in allCategories)
         {
             if (categoryService.HasPriceForDays(category.CategoryId, booking.CheckInDate, booking.CheckOutDate))
             {
                 price = categoryService.GetPriceForDates(category.CategoryId, booking.CheckInDate, booking.CheckOutDate);
                 allCategories.Where(c => c.CategoryId == category.CategoryId).First().PriceForChoosenDates = price;
                 newCategories.Add(allCategories.Where(c => c.CategoryId == category.CategoryId).First());
             }
         }
         newBooking.RoomCategories = newCategories;
         #endregion
         SaveMakeBookingSession(newBooking);
     }
     else
     {
         //If the dates are not the same, we need to get available rooms for the new dates
         if (booking.CheckInDate.Date != savedBookingSession.CheckInDate.Date || booking.CheckOutDate.Date != savedBookingSession.CheckOutDate.Date)
         {
             #region  changethiscode
             List<RoomCategory> allCategories = GetAllRoomCategories().ToList();
             List<RoomCategory> newCategories = new List<RoomCategory>();
             double price = 0;
             //Get price, and only display categories with a price for each day
             foreach (RoomCategory category in allCategories)
             {
                 if (categoryService.HasPriceForDays(category.CategoryId, booking.CheckInDate, booking.CheckOutDate))
                 {
                     price = categoryService.GetPriceForDates(category.CategoryId, booking.CheckInDate, booking.CheckOutDate);
                     allCategories.Where(c => c.CategoryId == category.CategoryId).First().PriceForChoosenDates = price;
                     newCategories.Add(allCategories.Where(c => c.CategoryId == category.CategoryId).First());
                 }
             }
             newBooking.RoomCategories = newCategories;
             #endregion
             SaveMakeBookingSession(newBooking);
         }
         else
         {
             //If no dates have been changed, we do not need to do anything.
         }
     }
 }
        public ActionResult Rooms(MakeBooking makeBooking)
        {
            //If there are no rooms selected
            int numberOfRooms = makeBooking.RoomCategories.Sum(r => r.NumberOfRooms);
            if (numberOfRooms < 1)
            {
                TempData["NoRoomsSelected"] = "Du har inte valt något rum";
                return RedirectToAction("Rooms");
            }

            //If modelstate is false
            if (!ModelState.IsValid) return RedirectToAction("Rooms");

            //Get all categories with 'not enought' rooms available
            //If null: there are enought rooms. If not null: Redirect back to room action with error-message
            RoomCategory nonAvailableRoom = makeBooking.RoomCategories.Where(c =>
                                bookingService.CheckAvailableRooms(c.CategoryId, c.NumberOfRooms, makeBooking.CheckInDate, makeBooking.CheckOutDate)
                                == false
                                ).FirstOrDefault();
            if (nonAvailableRoom != null)
            {
                TempData["isAvailable"] = "false";
                TempData["nonAvailableCategoryId"] = nonAvailableRoom.CategoryId;
                return RedirectToAction("Rooms");
            }

            ChangeSessionRooms(makeBooking);

            return RedirectToAction("Confirm");
        }
        public ActionResult Index(MakeBooking booking)
        {
            booking.CheckInDate = booking.CheckInDate.Date;
            booking.CheckOutDate = booking.CheckOutDate.Date;
            if (!ModelState.IsValid || booking.CheckInDate<DateTime.Now.Date || booking.CheckOutDate<=booking.CheckInDate)
            {
                ModelState.AddModelError(string.Empty, "Felaktigt datum. Inchecknig måste vara tidigast idag och utcheckning måste ske efter.");
                return View(booking);
            }

            ChangeSessionDate(booking);

            return RedirectToAction("Rooms");
        }
 public ActionResult Index()
 {
     MakeBooking bookingViewModel = GetMakeBookingSession();
     if (bookingViewModel == null)
     {
         bookingViewModel = new MakeBooking() { CheckInDate= DateTime.Now.Date,CheckOutDate=DateTime.Now.AddDays(1).Date};
     }
     return View(bookingViewModel);
 }