// To protect from overposting attacks, enable the specific properties you want to bind to, for // more details, see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Attach(Booking).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BookingExists(Booking.ID)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
// To protect from overposting attacks, enable the specific properties you want to bind to, for // more details, see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Customer.Add(Customer); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Booking = await _context.Booking.FindAsync(id); if (Booking != null) { _context.Booking.Remove(Booking); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Room = await _context.Room.FindAsync(id); if (Room != null) { _context.Room.Remove(Room); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(string id) { if (id == null) { return(NotFound()); } Customer = await _context.Customer.FindAsync(id); if (Customer != null) { _context.Customer.Remove(Customer); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
// To protect from overposting attacks, enable the specific properties you want to bind to, for // more details, see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } ViewData["RoomID"] = new SelectList(_context.Room, "ID", "ID"); string query = "SELECT * From Room Where ID = @RID AND ID NOT IN (SELECT RoomID FROM Booking WHERE (CheckIn <= @ChckIn AND CheckOut >= @ChckOut) OR (CheckIn < @ChckOut AND CheckOut >=@ChckOut) OR (@ChckIn <= CheckIn AND @ChckOut >= CheckIn))"; var par1 = new SqliteParameter("@RID", Booking.RoomID); var par2 = new SqliteParameter("@ChckIn", Booking.CheckIn); var par3 = new SqliteParameter("@ChckOut", Booking.CheckOut); Vacancy = await _context.Room.FromSqlRaw(query, par1, par2, par3).ToListAsync(); if (Vacancy.Count() == 1) { Booking NewBooking = new Booking(); NewBooking.RoomID = Booking.RoomID; NewBooking.CustomerEmail = User.FindFirst(ClaimTypes.Name).Value; NewBooking.CheckIn = Booking.CheckIn; NewBooking.CheckOut = Booking.CheckOut; var theRoom = await _context.Room.FindAsync(Booking.RoomID); var nights = ((Booking.CheckOut - Booking.CheckIn).Days); NewBooking.Cost = nights * theRoom.Price; _context.Booking.Add(NewBooking); await _context.SaveChangesAsync(); ViewData["Room"] = theRoom.ID; ViewData["BedCount"] = theRoom.BedCount; ViewData["Nights"] = nights; ViewData["total"] = String.Format("{0:C}", NewBooking.Cost); ViewData["NewBooking"] = "true"; } else { ViewData["NewBooking"] = "false"; } return(Page()); }