Ejemplo n.º 1
0
        public async Task <IActionResult> CreateReservation([Bind("IdReservations,CheckIn,CheckOut,IdRoom,IdCustomer")] Reservations reservations)
        {
            if (ModelState.IsValid)
            {
                var rooms = _context.Rooms.Where(x => x.IdRoom == reservations.IdRoom).FirstOrDefault();

                var reservationsList = _context.Reservations.Where(x => x.IdRoom == rooms.IdRoom)
                                       .OrderBy(x => x.CheckOut).ToList();
                bool found = reservations.CheckIn <reservationsList[0].CheckIn ||
                                                   reservations.CheckOut> reservationsList[reservationsList.Count() - 1].CheckOut;

                for (int i = 0; i < reservationsList.Count() - 2; ++i)
                {
                    if (reservationsList[i].CheckOut <reservations.CheckIn && reservationsList[i + 1].CheckIn> reservations.CheckOut)
                    {
                        found = true;
                        break;
                    }
                    if (found)
                    {
                        _context.Add(reservations);
                        await _context.SaveChangesAsync();

                        return(RedirectToAction(nameof(Index)));
                    }
                }

                ViewData["IdCustomer"] = new SelectList(_context.Customers, "IdCustomer", "IdCustomer", reservations.IdCustomer);
                ViewData["IdRoom"]     = new SelectList(_context.Rooms, "IdRoom", "IdRoom", reservations.IdRoom);
                return(View(reservations));
            }
            ViewData["IdCustomer"] = new SelectList(_context.Customers, "IdCustomer", "IdCustomer", reservations.IdCustomer);
            ViewData["IdRoom"]     = new SelectList(_context.Rooms, "IdRoom", "IdRoom", reservations.IdRoom);
            return(View(reservations));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> CreateLocation([Bind("IdLocation,NrStreat,StreatName,RegionName,Country")] Location location)
        {
            if (ModelState.IsValid)
            {
                _context.Add(location);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(location));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Create([Bind("IdFacilities,FacilitiesName,IsChecked")] Facilities facilities)
        {
            if (ModelState.IsValid)
            {
                _context.Add(facilities);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(facilities));
        }
        public async Task <IActionResult> CreateHotelImages([Bind("IdImageHotel,IdHotel,ImageHotel")] HotelImages hotelImages)
        {
            if (ModelState.IsValid)
            {
                _context.Add(hotelImages);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["IdHotel"] = new SelectList(_context.Hotels, "IdHotel", "IdHotel", hotelImages.IdHotel);
            return(View(hotelImages));
        }
        public async Task <IActionResult> CreateRoom([Bind("IdRoom,Beds,Reserved,Bath,IdHotel,PriceRoom,RoomNumber")] Rooms rooms)
        {
            if (ModelState.IsValid)
            {
                _context.Add(rooms);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["IdHotel"] = new SelectList(_context.Hotels, "IdHotel", "HotelName", rooms.IdHotel);
            return(View(rooms));
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> CreateCustomer([Bind("IdCustomer,FirstName,LastName,Username,Password,Email,Phone")] Customers customers)
        {
            if (ModelState.IsValid)
            {
                customers.TypeUser = "******";
                _context.Add(customers);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(customers));
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> CreateHotel([Bind("IdHotel,DescriptionTable,HotelName,Stars,IdLocation,ImageHotel")] Hotels hotels)
        {
            if (ModelState.IsValid)
            {
                _context.Add(hotels);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            ViewData["IdLocation"] = new SelectList(_context.Location, "IdLocation", "RegionName", hotels.IdLocation);
            return(View(hotels));
        }
Ejemplo n.º 8
0
        public async void deleteHotel(int id)
        {
            var facilitiesHotel = context.FacilitiesHotel.Where(x => x.IdHotel == id).ToList();

            foreach (var item in facilitiesHotel)
            {
                context.FacilitiesHotel.Remove(item);
            }

            var employesHotel = context.Employes.Where(x => x.IdHotel == id).ToList();

            foreach (var item in employesHotel)
            {
                context.Employes.Remove(item);
            }
            var roomsHotel = context.Rooms.Where(x => x.IdHotel == id).ToList();

            foreach (var item in roomsHotel)
            {
                DeleteReservations(item.IdRoom);
                context.Rooms.Remove(item);
            }
            var imagesHotel = context.HotelImages.Where(x => x.IdHotel == id).ToList();

            foreach (var item in imagesHotel)
            {
                context.HotelImages.Remove(item);
            }
            var hotels = context.Hotels.Where(m => m.IdHotel == id).SingleOrDefault();

            context.Hotels.Remove(hotels);
            await context.SaveChangesAsync();
        }
        public async Task <IActionResult> Create([Bind("IdHotel,Stars,HotelName,DescriptionTable")] Hotels hotels)
        {
            if (ModelState.IsValid)
            {
                context.Add(hotels);
                await context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(hotels));
        }