예제 #1
0
        public async Task <AppUser> RemoveLike(Post post, CodeExchangeContext UsersDb)
        {
            if (this.Likes.Contains(post) == true)
            {
                this.Likes.Remove(post);
                post.Likes--;
                //Target user and decrement rep
                var targetUser = UsersDb.AppUsers.FirstOrDefault(Entry => Entry.AppUserId == post.CreatorId);
                if (targetUser == null)
                {
                    return(null);
                }
                else
                {
                    targetUser.Rep--;
                    await UsersDb.SaveChangesAsync();

                    return(targetUser);
                }
            }
            else if (this.Dislikes.Contains(post) == true)
            {
                this.Dislikes.Remove(post);
                post.Dislikes--;
                //Target user and decrement rep
                var targetUser = UsersDb.AppUsers.FirstOrDefault(Entry => Entry.AppUserId == post.CreatorId);
                if (targetUser == null)
                {
                    return(null);
                }
                else
                {
                    targetUser.Rep--;
                    await UsersDb.SaveChangesAsync();

                    return(targetUser);
                }
            }
            return(null);
        }
예제 #2
0
        public async Task <AppUser> LikePost(Post post, CodeExchangeContext UsersDb)
        {
            if (this.Likes.Contains(post) == false && this.Dislikes.Contains(post) == false)
            {
                this.Likes.Add(post);
                post.Likes++;
                //Target user and add rep
                var targetUser = UsersDb.AppUsers.FirstOrDefault(Entry => Entry.AppUserId == post.CreatorId);
                if (targetUser == null)
                {
                    return(targetUser);
                }
                else
                {
                    targetUser.Rep++;
                    await UsersDb.SaveChangesAsync();

                    return(targetUser);
                }
            }
            return(null);
        }
 public AccountController(UserManager <AppUser> userManager, SignInManager <AppUser> signInManager, CodeExchangeContext db)
 {
     _userManager   = userManager;
     _signInManager = signInManager;
     _db            = db;
 }