public ActionResult Create([Bind(Include = "checkIn,checkOut,Id,bill,guestsInfo")] Reservation reservation)
        {
            if (ModelState.IsValid)
            {
                db.Reservations.Add(reservation);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(reservation);
        }
        public ActionResult Create([Bind(Include = "Id,firstName,lastName,email,sessionId,address,phone,city,state,zip,sessionExpiration,expirationDate,member,password,loyaltyNum,stays,lastStay")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                db.People.Add(customer);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(customer));
        }
예제 #3
0
        public JsonResult CheckOut(int resId)
        {
            using (var context = new HotelDatabaseContainer())
            {
                var reservation = (from res in context.Reservations where res.Id == resId select res).First();

                //Occupy Room
                reservation.Room.occupied = false;
                reservation.checkOut      = DateTime.Now;
                reservation.stayed        = true;

                //Unassign Room
                reservation.Room = null;

                context.SaveChanges();

                return(Json(new
                {
                    checkOutTime = reservation.checkOut.ToString("g"),
                }));
            }
        }
예제 #4
0
        public JsonResult CheckIn(int resId)
        {
            using (var context = new HotelDatabaseContainer())
            {
                var reservation = (from res in context.Reservations where res.Id == resId select res).First();

                var customer = (from cus in context.Customers where cus.Id == reservation.PersonId select cus).FirstOrDefault();

                if (customer != null)
                {
                    customer.stays++;
                    customer.lastStay = reservation.checkIn;
                    CustomerOperations.setLoyalty(customer, DateTime.Now);
                }

                //Assign Room
                var availibleRooms = from room in context.Rooms
                                     where !room.occupied && room.RoomType.Id == reservation.RoomType.Id
                                     select room;

                //Only hit if everyone still hasn't checkedout
                if (!availibleRooms.Any())
                {
                    return(Json(new { errorMessage = "Please wait for someone to check out later today." }));
                }

                reservation.Room         = availibleRooms.First();
                reservation.roomAssigned = reservation.Room.Id;

                //Occupy Room
                reservation.Room.occupied = true;
                reservation.checkIn       = DateTime.Now;

                context.SaveChanges();

                return(Json(new { roomNum = reservation.Room.Id, checkInTime = reservation.checkIn.ToString("g") }));
            }
        }
예제 #5
0
        public ActionResult checkOutAllToday()
        {
            var context = new HotelDatabaseContainer();

            var today    = DateTime.Today;
            var tomorrow = DateTime.Today.AddDays(1);

            var reservations = from res in context.Reservations
                               where res.Room != null && !res.stayed &&
                               res.checkOut >= today && res.checkOut < tomorrow
                               select res;

            foreach (var res in reservations)
            {
                res.Room.occupied = false;
                res.stayed        = true;
                res.checkOut      = DateTime.Now;
            }

            context.SaveChanges();

            //Redirect to Hotel Status to see your results
            return(Redirect("HotelStatus"));
        }
예제 #6
0
        public JsonResult updateRecord(int roomTypeId, int newValue)
        {
            var now = DateTime.Now;

            using (var context = new HotelDatabaseContainer())
            {
                //RoomType
                var rTypeById = from rType in context.RoomTypes where rType.Id == roomTypeId select rType;

                if (!rTypeById.Any())
                { //Should Not Be Reachable
                    return(Json(new { errorMessage = "Could not Find Room Type" }));
                }

                var roomType = rTypeById.First();

                //All Availible Rooms
                var currRooms = roomType.numberOfRooms;

                //Get Used Rooms
                var usedRoomsCount = occupiedRooms(roomType, context);

                if (currRooms > newValue)
                { //Subtract Rooms
                    var roomId = roomType.Id;

                    var unusedRooms = (from res in context.Rooms where !res.occupied && res.RoomType.Id == roomId select res).ToList();

                    //Get Unused rooms with Left Outer Join
                    var unusedRoomsRes = unusedRooms.Count() - newValue;

                    if (unusedRoomsRes < 0 || unusedRooms.Count() < unusedRoomsRes)
                    {
                        return(Json(new { errorMessage = "Not enough unused rooms to get rid of.", usedRooms = usedRoomsCount }));
                    }

                    //Delete Rooms
                    for (var i = 0; i < unusedRoomsRes; i++)
                    {
                        context.Rooms.Remove(unusedRooms[i]);
                    }
                }
                else if (currRooms < newValue)
                { //Add Rooms
                    var newRooms = newValue - currRooms;

                    //Add Rooms
                    for (var i = 0; i < newValue - currRooms; i++)
                    {
                        context.Rooms.Add(new Room {
                            RoomType = roomType
                        });
                    }
                }

                roomType.numberOfRooms = newValue;

                //Update DB
                context.SaveChanges();

                return(Json(new { usedRooms = usedRoomsCount }));
            }
        }