public async Task <IActionResult> OnPostAsync() { //Check valid user////////////////////////////////////////////////////////////////////////////////// ApplicationUser = await _userManager.GetUserAsync(User); // User = logged in user (built in magic) if (ApplicationUser == null) { return(NotFound()); } bool isCustomer = await _userManager.IsInRoleAsync(ApplicationUser, "customer"); if (!isCustomer) { return(NotFound()); } int SelectedCourt; if (SelectedCourtId == null) { SelectedCourt = 1; } else { SelectedCourt = int.Parse(SelectedCourtId); } int BookingStatusId = await _context.BookingStatus .Where(a => a.Status == "Pending") .Select(a => a.Id).SingleOrDefaultAsync(); var booking = new Booking() { ApplicationUserId = ApplicationUser.Id, CreatedDate = DateTime.Now, BookingDate = SelectedBookingDate, CourtId = SelectedCourt, BookingStatusId = BookingStatusId }; _context.Booking.Add(booking); await _context.SaveChangesAsync(); for (var i = 0; i < AreChecked.Count(); i++) { var slot = AreChecked[i] + 1; var bookedSlots = new BookedSlot() { Slot = slot, BookingId = booking.Id }; _context.BookedSlot.Add(bookedSlots); await _context.SaveChangesAsync(); } StatusMessage = "New booking has been added"; return(RedirectToPage("./Index")); }
public async Task <ActionResult> OnPostAsync() { ApplicationUser = await _userManager.GetUserAsync(User); // User = logged in user (built in magic) if (ApplicationUser == null) { return(NotFound()); } bool isAdmin = await _userManager.IsInRoleAsync(ApplicationUser, "admin"); if (!isAdmin) { return(NotFound()); } int SelectedStatusId = await _context.BookingStatus.Where(a => a.Status == SelectedStatus).Select(a => a.Id).SingleOrDefaultAsync(); // find status id here Booking = await _context.Booking.Where(a => a.Id == SelectedId).SingleOrDefaultAsync(); if (Booking == null) { return(NotFound()); } Booking.BookingStatusId = SelectedStatusId; //_context.Attach(Booking).State = EntityState.Modified; _context.Update(Booking); 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()); } _context.Attach(Court).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CourtExists(Court.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.Court.Add(Court); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Court = await _context.Court.FindAsync(id); if (Court != null) { _context.Court.Remove(Court); 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()); } ApplicationUser = await _userManager.GetUserAsync(User); // User = logged in user (built in magic) if (ApplicationUser == null) { return(NotFound()); } Booking = await _context.Booking.FindAsync(id); if (Booking != null) { _context.Booking.Remove(Booking); await _context.SaveChangesAsync(); } StatusMessage = "Admin Account Deleted."; return(RedirectToPage("./Index")); }