示例#1
0
        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());
        }
示例#2
0
        // 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"));
        }
示例#4
0
        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"));
        }
示例#5
0
        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"));
        }