예제 #1
0
        public ActionResult Create(Guest guest,int id)
        {
            if (ModelState.IsValid)
            {
                Booking booking = db.Bookings.Find(id);
                guest.Bookings.Add(booking);
                db.Guests.Add(guest);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(guest);
        }
예제 #2
0
        public ActionResult Create(Booking booking, int id)
        {
            //Checking if all values are filled
            if (booking.Address == null || booking.Postcode == null || booking.City == null
                || booking.EmailAddress == null || booking.InvoiceAddress == null || booking.AccountNumber == null
                || booking.StartDate == null || booking.EndDate == null)
            {
                ViewData["error"] = "Please completely fill in the form";
                return View(booking);
            }

            //Checking if the startdate isn't greater than the enddate
            if (booking.StartDate > booking.EndDate)
            {
                ViewData["errorDate"] = "Please enter a correct date";
                return View(booking);
            }

            if (ModelState.IsValid)
            {
                Room room = db.Rooms.Find(id);

                double totalPrice = PriceCalculator.CalculateTotalPrice(room, booking.StartDate.Value.Month);

                booking.Username = db.Users.Find(User.Identity.Name).Username;
                int newID = db.Bookings.Max(b => b.ID) + 1;
                booking.ID = newID;
                booking.TotalPrice = Convert.ToInt32(totalPrice);
                booking.BookingStatus_name = "reserved";

                List<Guest> GuestList = new List<Guest>();
                for (int i = 0; i < room.NumberOfPersons; i++)
                    try
                    {
                        Guest g = new Guest();
                        g.FirstName = "default";
                        g.Lastname = "default";
                        g.Gender = "/";
                        g.ID = (db.Guests.Max(gg => gg.ID) + i) + 1;
                        g.Bookings.Add(booking);
                        db.Guests.Add(g);
                        booking.Guests.Add(g);
                    }
                    catch (DbEntityValidationException e)
                    {
                        throw e;
                    }

                db.Bookings.Add(booking);
                db.SaveChanges();
                return RedirectToAction("PriceOverview", booking);
            }

            ViewBag.BookingStatus_name = new SelectList(db.BookingStatus, "Name", "Name", booking.BookingStatus_name);
            ViewBag.Username = new SelectList(db.Users, "Username", "Password", booking.Username);
            return View(booking);
        }
예제 #3
0
 public ActionResult Edit(Guest guest)
 {
     if (ModelState.IsValid)
     {
         db.Entry(guest).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index", "Booking");
     }
     return View(guest);
 }