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()); }
public async Task <IActionResult> Create([Bind("Id,HotelName,TotalRooms,BookedRooms,RoomPrice,Address")] Hotel hotel) { if (ModelState.IsValid) { _context.Add(hotel); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(hotel)); }
public async Task <IActionResult> Create([Bind("Id,FullName,Email")] Client client) { if (ModelState.IsValid) { _context.Add(client); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(client)); }