public static TemplateStruct New(string title, string body, string destination) { var result = new TemplateStruct(); result.Title = title; result.Body = body; result.Destination = destination; result.Create = DateTime.Now; return(result); }
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); }
static Email CreateEmail(TemplateStruct template) { var result = default(Email); BCT.Execute(d => { if (string.IsNullOrEmpty(template.Destination)) { return; } var email = new Email(); email.Title = template.Title; email.Body = template.Body; email.Destination = template.Destination; email.StateEnum = FessooFramework.Objects.Data.DefaultState.Created; d.SaveChanges(); result = email; }); return(result); }