예제 #1
0
        public async Task <IActionResult> RemoveAPost(int id)
        {
            //Gets reported post
            Post reportedPost = await _postRepository.GetSingle(id);

            //If another admin has already deleted the reported post or it has been permitted, reload the page
            if (reportedPost == null || reportedPost.IsReported == false)
            {
                return(Json(new { redirectToUrl = Url.Action(nameof(GetReportedPosts)) }));
                //return RedirectToAction(nameof(ReportedPosts));
            }

            //Gets list of yummy_Post instances with users that have liked it
            List <Yummy_Post> reportedPostLikedByOthers = await _yummy_PostRepository.GetAll()
                                                          .Where(yp => yp.PostId == id)
                                                          .ToListAsync();

            //Removes the instances from intermediary table (not very efficient, because of constantly SaveChanges(), RemoveRange() would be much better)
            foreach (var post in reportedPostLikedByOthers)
            {
                await _yummy_PostRepository.Remove(post);
            }

            //Removes the reported post
            await _postRepository.Remove(reportedPost);

            //return RedirectToAction(nameof(ReportedPosts));
            return(Json(new { redirectToUrl = Url.Action(nameof(GetReportedPosts)) }));
        }
예제 #2
0
        public async Task UnfollowUser(int id)
        {
            //Gets Id of currently logged in user
            int currentUserId = await _appUserManager.GetCurrentUserIdAsync(User);

            //Gets the row of current user following the specified one
            User_Follows userFollows = await _user_FollowsRepository.GetAll()
                                       .SingleOrDefaultAsync(uf => uf.FollowerId == currentUserId && uf.FollowsId == id);

            //Deletes the row
            await _user_FollowsRepository.Remove(userFollows);

            return;
        }