Exemple #1
0
        private async Task SetNotificationAsync(CProfile profileTo, int profileFrom, string link, string userFromName, int?commentId)
        {
            var text = $"Пользователь {userFromName} ответил на ваш";
            var alt  = "комментарий";

            await notificationService.AddNotification(profileTo, profileFrom, text, link, alt, commentId);
        }
        private async Task SetState(
            CProfile user,
            CNews news,
            string state,
            string link)
        {
            var isLike = await context
                         .StatisticNews
                         .FirstOrDefaultAsync(sn => sn.Like == user && sn.News == news);

            var isDislike = await context
                            .StatisticNews
                            .FirstOrDefaultAsync(sn => sn.Dislike == user && sn.News == news);

            var isViews = await context
                          .StatisticNews
                          .FirstOrDefaultAsync(sn => sn.ViewBy == user && sn.News == news);

            if (state == "like")
            {
                await SetLike(isLike, isDislike, isViews, user, news, link);
            }
            else if (state == "dislike")
            {
                await SetDislike(isDislike, isLike, isViews, user, news);
            }
            else if (state == "view")
            {
                await SetView(isViews, user, news);
            }
            await context.SaveChangesAsync();
        }
        private async Task SetNotificationAsync(CProfile user, CNews news, string link)
        {
            var profileFromName = user.User.UserName;
            var profilFrom      = user.Id;
            var profileTo       = news.Owner;
            var text            = $"Пользователь {profileFromName} оценил вашу";
            var alt             = "статью";

            await notificationService.AddNotification(profileTo, profilFrom, text, link, alt);
        }
 private async Task SetView(CStatisticNews isViews, CProfile user, CNews news)
 {
     if (isViews == null)
     {
         await context
         .StatisticNews
         .AddAsync(new CStatisticNews
         {
             News   = news,
             Like   = null,
             ViewBy = user
         });
     }
 }
Exemple #5
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 #6
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);
     }
 }
        private async Task SetLike(CStatisticNews isLike, CStatisticNews isDislike, CStatisticNews isViews, CProfile user, CNews news, string link)
        {
            if (isLike == null)
            {
                if (isDislike == null)
                {
                    if (isViews == null)
                    {
                        await context
                        .StatisticNews
                        .AddAsync(new CStatisticNews
                        {
                            News       = news,
                            Like       = user,
                            ViewBy     = user,
                            IsNotifyed = true
                        });

                        if (user.Id != news.Owner.Id)
                        {
                            await SetNotificationAsync(user, news, link);
                        }
                    }
                    else
                    {
                        if (!isViews.IsNotifyed && user.Id != news.Owner.Id)
                        {
                            await SetNotificationAsync(user, news, link);

                            isViews.IsNotifyed = true;
                        }

                        isViews.Like = user;
                        context.StatisticNews.Update(isViews);
                    }
                }
                else
                {
                    if (!isDislike.IsNotifyed && user.Id != news.Owner.Id)
                    {
                        await SetNotificationAsync(user, news, link);

                        isDislike.IsNotifyed = true;
                    }

                    isDislike.Dislike = null;
                    isDislike.Like    = user;
                    context.StatisticNews.Update(isDislike);
                }
            }
            else
            {
                isLike.Like = null;
                context.StatisticNews.Update(isLike);
            }
        }
 private async Task SetDislike(CStatisticNews isDislike, CStatisticNews isLike, CStatisticNews isViews, CProfile user, CNews news)
 {
     if (isDislike == null)
     {
         if (isLike == null)
         {
             if (isViews == null)
             {
                 await context
                 .StatisticNews
                 .AddAsync(new CStatisticNews
                 {
                     News    = news,
                     Dislike = user,
                     ViewBy  = user
                 });
             }
             else
             {
                 isViews.Dislike = user;
                 context.StatisticNews.Update(isViews);
             }
         }
         else
         {
             isLike.Like    = null;
             isLike.Dislike = user;
             context.StatisticNews.Update(isLike);
         }
     }
     else
     {
         isDislike.Dislike = null;
         context.StatisticNews.Update(isDislike);
     }
 }