public async Task <IActionResult> OnGetAddAdminAsync(int userId) { // Check that the user isn't already an admin if (await(from admin in _context.EventAdmins where admin.Admin.ID == userId && admin.Event == Event select admin).AnyAsync()) { return(NotFound("User is already an admin in this event.")); } EventAdmins Admin = new EventAdmins(); PuzzleUser user = await _context.PuzzleUsers.FirstOrDefaultAsync(m => m.ID == userId); if (user == null) { return(NotFound("Could not find user with ID '" + userId + "'. Check to make sure the user hasn't been removed.")); } Admin.Admin = user; Admin.Event = Event; _context.EventAdmins.Add(Admin); user.MayBeAdminOrAuthor = true; await _context.SaveChangesAsync(); return(RedirectToPage("/Events/Players")); }
public async Task <EventAdmins> CreateAndReturnAsync(int eventId, int userId) { var entity = new EventAdmins { EventId = eventId, UserId = userId }; _repository.EventAdmins.Create(entity); await _repository.SaveAsync(); return(entity); }
public async Task <IActionResult> OnGetRemoveAdminAsync(int userId) { EventAdmins Admin = await _context.EventAdmins.FirstOrDefaultAsync(admin => admin.Admin.ID == userId && admin.Event == Event); if (Admin == null) { return(NotFound("Could not find event admin with ID '" + userId + "'. They may have already been removed from the admin role.")); } _context.EventAdmins.Remove(Admin); await _context.SaveChangesAsync(); return(RedirectToPage("/Events/Players")); }