public async Task <IActionResult> Edit(int id, [Bind("GatheringUserId,GatheringId,UserId")] GatheringUser gatheringUser)
        {
            if (id != gatheringUser.GatheringUserId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(gatheringUser);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!GatheringUserExists(gatheringUser.GatheringUserId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["GatheringId"] = new SelectList(_context.Gathering, "GatheringId", "City", gatheringUser.GatheringId);
            ViewData["UserId"]      = new SelectList(_context.User, "Id", "Id", gatheringUser.UserId);
            return(View(gatheringUser));
        }
Example #2
0
        public async Task <IActionResult> JoinGathering(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var gathering = await _context.Gathering
                            .Include(g => g.Location)
                            .Include(g => g.User)
                            .FirstOrDefaultAsync(m => m.GatheringId == id);

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

            var user = await GetCurrentUserAsync();

            GatheringUser gatheringUser = new GatheringUser()
            {
                UserId      = user.Id,
                GatheringId = gathering.GatheringId
            };

            if (ModelState.IsValid)
            {
                _context.Add(gatheringUser);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            return(RedirectToAction(nameof(Index)));
        }
        public async Task <IActionResult> Create([Bind("GatheringUserId,GatheringId,UserId")] GatheringUser gatheringUser)
        {
            if (ModelState.IsValid)
            {
                _context.Add(gatheringUser);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["GatheringId"] = new SelectList(_context.Gathering, "GatheringId", "City", gatheringUser.GatheringId);
            ViewData["UserId"]      = new SelectList(_context.User, "Id", "Id", gatheringUser.UserId);
            return(View(gatheringUser));
        }