Exemple #1
0
        private async Task SetState(CProfile user, CComment comment, string state)
        {
            var isLike = await context
                         .StatisticComments
                         .FirstOrDefaultAsync(sc => sc.Like == user && sc.Comment == comment);

            var isDislike = await context
                            .StatisticComments
                            .FirstOrDefaultAsync(sc => sc.Dislike == user && sc.Comment == comment);

            if (state == "like")
            {
                await SetLike(isLike, isDislike, user, comment);
            }
            else if (state == "dislike")
            {
                await SetDislike(isDislike, isLike, user, comment);
            }

            await context.SaveChangesAsync();
        }
Exemple #2
0
 private async Task SetLike(CStatisticComment isLike, CStatisticComment isDislike, CProfile user, CComment comment)
 {
     if (isLike == null)
     {
         if (isDislike == null)
         {
             await context
             .StatisticComments
             .AddAsync(new CStatisticComment
             {
                 Comment = comment,
                 Like    = user
             });
         }
         else
         {
             isDislike.Dislike = null;
             isDislike.Like    = user;
             context.StatisticComments.Update(isDislike);
         }
     }
     else
     {
         context.StatisticComments.Remove(isLike);
     }
 }