public async Task <IActionResult> Edit(Guid id, [Bind("Id,CommunityId,ApplicationUserId,NotifyMe,IsAdmin,IsAccepted")] CommunityFollower communityFollower)
        {
            if (id != communityFollower.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(communityFollower);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CommunityFollowerExists(communityFollower.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index), new { id = communityFollower.CommunityId }));
            }
            ViewData["ApplicationUserId"] = new SelectList(_context.ApplicationUsers, "Id", "Id", communityFollower.ApplicationUserId);
            ViewData["CommunityId"]       = new SelectList(_context.Communities, "Id", "BgImage", communityFollower.CommunityId);
            return(View(communityFollower));
        }
        public async Task <IActionResult> Create([Bind("Id,CommunityId,ApplicationUserId,NotifyMe,IsAdmin,IsAccepted")] CommunityFollower communityFollower)
        {
            if (ModelState.IsValid)
            {
                communityFollower.Id = Guid.NewGuid();
                _context.Add(communityFollower);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ApplicationUserId"] = new SelectList(_context.ApplicationUsers, "Id", "Id", communityFollower.ApplicationUserId);
            ViewData["CommunityId"]       = new SelectList(_context.Communities, "Id", "BgImage", communityFollower.CommunityId);
            return(View(communityFollower));
        }
        public IActionResult UnJoin(int id, string uid)
        {
            string userid = uid;

            CommunityFollower communityFollower = _context.CommunityFollowers.SingleOrDefault(m => m.CommunityId == id && m.ApplicationUserId == userid);

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


            if (_context.CommunityFollowers.Where(f => f.CommunityId == id && f.IsAccepted == false && f.ApplicationUserId == userid).Count() > 0)
            {
                _context.CommunityFollowers.Remove(communityFollower);
                _context.SaveChanges();
            }
            return(RedirectToAction("Details/" + id));
        }
コード例 #4
0
        public IActionResult LeaveGroup(int id)
        {
            string currentuserid = _userManager.GetUserId(User);

            CommunityFollower communityFollower = _context.CommunityFollowers.SingleOrDefault(m => m.CommunityId == id && m.ApplicationUserId == currentuserid);

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


            if (_context.CommunityFollowers.Where(f => f.CommunityId == id && f.ApplicationUserId == _userManager.GetUserId(User)).Count() > 0)
            {
                _context.CommunityFollowers.Remove(communityFollower);
                _context.SaveChanges();
            }
            return(RedirectToAction("Index/"));
        }