コード例 #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"));
        }
コード例 #3
0
        // 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"));
        }