Exemplo n.º 1
0
        public async Task <IActionResult> OnPostAsync(string id)
        {
            MyUsers = await _context.MyUsers.ToListAsync();

            MyUser = await _context.MyUsers.Where(u => u.Id == id).FirstOrDefaultAsync();

            if (MyUser != null)
            {
                if (!_ManageUsers.IsInRoleAsync(MyUser, "Organizer").Result)
                {
                    await _ManageUsers.AddToRoleAsync(MyUser, "Organizer");

                    await _ManageUsers.RemoveFromRoleAsync(MyUser, "Attendee");

                    await _context.SaveChangesAsync();

                    return(RedirectToPage("/ManageUsers/Index"));
                }
                else
                {
                    await _ManageUsers.RemoveFromRoleAsync(MyUser, "Organizer");

                    await _ManageUsers.AddToRoleAsync(MyUser, "Attendee");

                    await _context.SaveChangesAsync();

                    return(RedirectToPage("/ManageUsers/Index"));
                }
            }
            return(Page());
        }
Exemplo n.º 2
0
        // To protect from overposting attacks, see https://aka.ms/RazorPagesCRUD



        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            if (id == null)
            {
                return(NotFound());
            }


            JoinedEvent.Attendee = _context.Attendees.Where(a => a.AttendeeID == 1).First();
            JoinedEvent.Event    = _context.Events.Where(e => e.EventID == id).First();


            _context.JoinedEvents.Add(JoinedEvent);
            _context.Events.Where(e => e.EventID == id).First().SpotsAvailable--;


            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
Exemplo n.º 3
0
        // To protect from overposting attacks, enable the specific properties you want to bind to.
        // For more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(Attendee).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AttendeeExists(Attendee.AttendeeID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
Exemplo n.º 4
0
        // To protect from overposting attacks, see https://aka.ms/RazorPagesCRUD
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attendees.Add(Attendee);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
Exemplo n.º 5
0
      // To protect from overposting attacks, see https://aka.ms/RazorPagesCRUD
      public async Task <IActionResult> OnPostAsync()
      {
          if (!ModelState.IsValid)
          {
              return(Page());
          }
          var userId = _userManager.GetUserId(User);

          CurrentUser = await _context.MyUsers.Where(u => u.Id == userId).FirstOrDefaultAsync();

          Event.Organizer = CurrentUser;
          _context.Events.Add(Event);
          await _context.SaveChangesAsync();

          return(RedirectToPage("./Index"));
      }
Exemplo n.º 6
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"));
        }
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            Event = await _context.Events.FirstOrDefaultAsync(m => m.EventID == id);

            var userId = _userManager.GetUserId(User);

            var MyUser = await _context.MyUsers.Where(u => u.Id == userId).Include(u => u.JoinedEvents).FirstOrDefaultAsync();

            if (MyUser == null)
            {
                return(NotFound());
            }
            else
            {
                Event.SpotsAvailable++;
                MyUser.JoinedEvents.Remove(Event);
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }
        }