コード例 #1
0
        public IActionResult Index(BookRoom confirmBooking, String btnbookroom)
        {
            var   roomName   = _motelContext.RoomTypes.Where(p => p.RoomName == btnbookroom).Select(p => p.RoomName).FirstOrDefault();
            var   roomTypeID = _motelContext.RoomTypes.Where(p => p.RoomName == roomName).Select(x => x.ID).FirstOrDefault();
            var   guestID    = _motelContext.Guests.Where(p => p.FirstName == confirmBooking.firstName && p.LastName == confirmBooking.lastName).Select(x => x.ID).FirstOrDefault();
            var   locationID = 1;
            Guest g          = new Guest()
            {
                FirstName   = confirmBooking.firstName,
                LastName    = confirmBooking.lastName,
                Address     = confirmBooking.address,
                PhoneNumber = confirmBooking.phoneno,
                ZipCode     = confirmBooking.zipcode
            };

            RoomReservation confirmRoomReservation = new RoomReservation()
            {
                RoomTypeID        = roomTypeID,
                GuestID           = g.ID,
                checkIn           = confirmBooking.checkinDate,
                checkOut          = confirmBooking.checkoutDate,
                MotelPropertiesID = locationID
            };

            confirmRoomReservation.Guest = g;
            _motelContext.RoomReservations.Add(confirmRoomReservation);


            //_motelContext.Entry(confirmRoomReservation).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
            _motelContext.SaveChanges();

            ViewData["ReservationID"] = confirmRoomReservation.ID;

            return(View(confirmRoomReservation));
        }
コード例 #2
0
        public IActionResult Update(ExistingReservation updateReservation, String Modifybtn)
        {
            switch (Modifybtn)
            {
            case "Update Reservation":
                var guestID       = _motelContext.RoomReservations.Where(p => p.ID == updateReservation.ReservationID).Select(p => p.GuestID).First();
                var existingGuest = _motelContext.Guests.Where(p => p.ID == guestID).Select(p => p).First();

                if (existingGuest != null)
                {
                    existingGuest.FirstName   = updateReservation.FirstName;
                    existingGuest.LastName    = updateReservation.LastName;
                    existingGuest.Address     = updateReservation.Address;
                    existingGuest.PhoneNumber = updateReservation.PhoneNumber;
                    existingGuest.ZipCode     = updateReservation.ZipCode;
                }

                _motelContext.SaveChanges();

                ViewBag.Message = "Customer Details successfully!";
                break;

            case "Cancel Reservation":
                var reservation = _motelContext.RoomReservations.Where(p => p.ID == updateReservation.ReservationID).Select(p => p).First();
                var guest       = _motelContext.Guests.Where(p => p.ID == reservation.GuestID).Select(p => p).First();

                _motelContext.RoomReservations.Remove(reservation);
                _motelContext.Guests.Remove(guest);

                _motelContext.SaveChanges();

                ViewBag.Message = "The operation is complete. Reservation is now Cancelled!";
                break;
            }


            return(View("UpdateConfirm"));
        }
コード例 #3
0
ファイル: DbInitializer.cs プロジェクト: ndesai88/NDMotel
        public static void Initialize(NDMotelContext context)
        {
            context.Database.EnsureCreated();

            if (context.Guests.Any())
            {
                return;
            }

            var guests = new Guest[]
            {
                new Guest {
                    FirstName = "Nirav", LastName = "Desai", Address = "123 Address Ln, FakeCity, IL", ZipCode = "12345", PhoneNumber = "123-456-7890"
                },
                new Guest {
                    FirstName = "Test", LastName = "Person", Address = "123 Address Road, FakeCity, IL", ZipCode = "12345", PhoneNumber = "321-456-7890"
                }
            };

            foreach (Guest guest in guests)
            {
                context.Guests.Add(guest);
            }

            context.SaveChanges();

            var roomType = new RoomType[]
            {
                new RoomType {
                    RoomDescription = "Spacious King Size Bed Room", RoomName = "King"
                },
                new RoomType {
                    RoomDescription = "Spacious Smoking King Size Bed Room", RoomName = "KingSM"
                },
                new RoomType {
                    RoomDescription = "Spacious Queen Size Bed Room", RoomName = "Queen"
                },
                new RoomType {
                    RoomDescription = "Spacious  Smoking Queen Size Bed Room", RoomName = "QueenSM"
                },
                new RoomType {
                    RoomDescription = "Spacious Suite with King Size Bed and Jacuzzi", RoomName = "Suite"
                },
                new RoomType {
                    RoomDescription = "Spacious 2 Full Size Bed Room", RoomName = "Full"
                }
            };

            foreach (RoomType RT in roomType)
            {
                context.RoomTypes.Add(RT);
            }

            context.SaveChanges();

            var motelProperties = new MotelProperties[]
            {
                new MotelProperties {
                    Location = "Des Plaines", Address = "123 Des Plaines St., Des Plaines, IL 60016"
                },
                new MotelProperties {
                    Location = "Chicago", Address = "123 Chicago Ln., Chicago, IL 60003"
                },
                new MotelProperties {
                    Location = "Bartlett", Address = "123 Bartlett St., Bartlett, IL 60103"
                }
            };

            foreach (MotelProperties MP in motelProperties)
            {
                context.MotelProperties.Add(MP);
            }

            context.SaveChanges();

            var roomReservation = new RoomReservation[]
            {
                new RoomReservation {
                    RoomTypeID = 1, GuestID = 1, MotelPropertiesID = 1, checkIn = DateTime.Parse("02-02-2017"), checkOut = DateTime.Parse("02-03-2017")
                },
                new RoomReservation {
                    RoomTypeID = 3, GuestID = 2, MotelPropertiesID = 1, checkIn = DateTime.Parse("02-02-2017"), checkOut = DateTime.Parse("02-03-2017")
                }
            };

            foreach (RoomReservation RR in roomReservation)
            {
                context.RoomReservations.Add(RR);
            }

            context.SaveChanges();

            var roomInventory = new RoomInventory[]
            {
                new RoomInventory {
                    RoomTypeID = 1, MotelPropertiesID = 1, HighestPrice = 70, BestPrice = 50, NumberOfRooms = 5
                },
                new RoomInventory {
                    RoomTypeID = 2, MotelPropertiesID = 1, HighestPrice = 80, BestPrice = 60, NumberOfRooms = 5
                },
                new RoomInventory {
                    RoomTypeID = 3, MotelPropertiesID = 1, HighestPrice = 70, BestPrice = 50, NumberOfRooms = 5
                },
                new RoomInventory {
                    RoomTypeID = 4, MotelPropertiesID = 1, HighestPrice = 70, BestPrice = 50, NumberOfRooms = 5
                },
                new RoomInventory {
                    RoomTypeID = 5, MotelPropertiesID = 1, HighestPrice = 100, BestPrice = 80, NumberOfRooms = 5
                },
                new RoomInventory {
                    RoomTypeID = 6, MotelPropertiesID = 1, HighestPrice = 60, BestPrice = 30, NumberOfRooms = 5
                }
            };

            foreach (RoomInventory RI in roomInventory)
            {
                context.RoomInventory.Add(RI);
            }

            context.SaveChanges();
        }