public async Task <IActionResult> Edit(int id, [Bind("Id,HotelName,TotalRooms,BookedRooms,RoomPrice,Address")] Hotel hotel)
        {
            if (id != hotel.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(hotel);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!HotelExists(hotel.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(hotel));
        }
        public IActionResult Create(int id)
        {
            if (SignInManager.IsSignedIn(User))
            {
                var client = (from clients in _context.Client
                              where clients.Email.Equals(User.Identity.Name)
                              select clients).FirstOrDefault();

                RoomReservation reservation = new RoomReservation();

                reservation.HotelId  = id;
                reservation.ClientId = client.Id;
                _context.Add(reservation);
                _context.SaveChanges();

                var clientReservation = _context.RoomReservation.Include(r => r.Client)
                                        .Include(r => r.Hotel)
                                        .FirstOrDefault(r => r.Id == reservation.Id);
                clientReservation.Hotel.BookedRooms = clientReservation.Hotel.BookedRooms + 1;
                _context.Update(clientReservation);
                _context.SaveChanges();
                return(View(clientReservation));
            }

            return(View());
        }
Esempio n. 3
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,FullName,Email")] Client client)
        {
            if (id != client.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(client);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ClientExists(client.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(client));
        }