public async Task <IActionResult> OnPostAddAsync(string UserName) { var User = await _context.Users.Where(u => u.UserName == UserName).FirstOrDefaultAsync(); await _userManager.AddToRoleAsync(User, "organizer"); // UserName är null // User.RoleIsOrganizer = true; await _context.SaveChangesAsync(); Event = await _context.Events.ToListAsync(); MyUser = await _context.Users.ToListAsync(); return(Page()); }
// 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")); }
// To protect from overposting attacks, see https://aka.ms/RazorPagesCRUD public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } var test = _context.Users.Where(u => u.UserName == User.Identity.Name).Include(u => u.HostedEvents).FirstOrDefaultAsync(); Event.Organizer = test.Result; _context.Events.Add(Event); await _context.SaveChangesAsync(); return(RedirectToPage("/Organizer/OrganizeEvents")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Event = await _context.Events.FindAsync(id); if (Event != null) { _context.Events.Remove(Event); await _context.SaveChangesAsync(); } return(RedirectToPage("/Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Event = await _context.Events.FindAsync(id); var user = await _context.Users .Where(u => u.UserName == User.Identity.Name) .Include(u => u.MyEvents) .FirstOrDefaultAsync(); if (Event != null) { Event.SpotsAvailable = Event.SpotsAvailable + 1; user.MyEvents.Remove(Event); await _context.SaveChangesAsync(); } return(RedirectToPage("/NormalUsers/MyEvents")); }