Ejemplo n.º 1
0
        public static TemplateStruct GetTemplate_UserStatistics(Guid userId)
        {
            var template = default(TemplateStruct);

            BCT.Execute(d =>
            {
                var user = d.MainDb.UserAccesses.FirstOrDefault(q => q.Id == userId);
                if (user == null)
                {
                    return;
                }
                var profile = d.MainDb.UserProfiles.FirstOrDefault(q => q.Id == user.UserProfileId);
                if (profile == null)
                {
                    return;
                }
                var stat = d.BulletinDb.UserStatistics.FirstOrDefault(q => q.UserId == userId);
                if (stat == null)
                {
                    return;
                }

                var now   = DateTime.Now;
                var title = title_UserStatistics
                            .Replace("{Timeperiod}", now.Date.ToShortDateString());

                var productYesterday = StatisticsHelper.GetProductStatisticsByPeriod(user.Id, now.Date.AddDays(-1), now);
                var productWeek      = StatisticsHelper.GetProductStatisticsByPeriod(user.Id, now.Date.AddDays(-7), now);
                var productMonth     = StatisticsHelper.GetProductStatisticsByPeriod(user.Id, now.Date.AddDays(-30), now);

                var table = table_UserStatistics
                            .Replace("{ProductDay}", productYesterday.BulletinCount.ToString())
                            .Replace("{ProductWeek}", productWeek.BulletinCount.ToString())
                            .Replace("{ProductMonth}", productMonth.BulletinCount.ToString())
                            .Replace("{InstanceDay}", productYesterday.InstanceCount.ToString())
                            .Replace("{InstanceWeek}", productWeek.InstanceCount.ToString())
                            .Replace("{InstanceMonth}", productMonth.InstanceCount.ToString());

                var body = body_UserStatistics
                           .Replace("{Views}", stat.TotalViews.ToString())
                           .Replace("{Messages}", stat.TotalMessages.ToString())
                           .Replace("{Calls}", stat.TotalCalls.ToString())
                           .Replace("{Table}", table);

                template = TemplateStruct.New(title, body, profile.Email);
            });
            return(template);
        }
Ejemplo n.º 2
0
 public static void SendStatistics(string userLogin)
 {
     BCT.Execute(d =>
     {
         //Находим пользователя
         var user = d.MainDb.UserAccesses.FirstOrDefault(q => q.Login == userLogin);
         if (user == null)
         {
             ConsoleHelper.SendMessage($"AvitoPublicateBulletin => Пользователь с логином {userLogin} не найден");
             return;
         }
         var userId = user.Id;
         var stat   = d.BulletinDb.UserStatistics.FirstOrDefault(q => q.UserId == userId);
         if (stat == null)
         {
             StatisticsHelper.ComputeUserStatistics(userLogin);
         }
         var template = EmailTemplateHelper.GetTemplate_UserStatistics(userId);
         var email    = CreateEmail(template);
         SendEmail(email);
     });
 }