// To protect from overposting attacks, see https://aka.ms/RazorPagesCRUD public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Events.Add(Event); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Event = await _context.Events.Include(e => e.Attendees).FirstOrDefaultAsync(m => m.Id == id); if (Event == null) { return(NotFound()); } var attendee = await _context.buyers.FirstOrDefaultAsync(); if (!Event.Attendees.Contains(attendee)) { Event.Attendees.Add(attendee); await _context.SaveChangesAsync(); } return(Page()); }