/// <summary> /// Validates the notification details. /// </summary> /// <param name="projectNotificationDetails">The project notification details.</param> /// <param name="projectUserInfo">The project user info.</param> /// <returns></returns> private static bool ValidateNotificationDetails(ProjectNotificationDetails projectNotificationDetails, ProjectUserInfo projectUserInfo) { bool isValid = true; if (projectUserInfo.ProjectEmailNotificationCodeId == DailyEmailNotificationCodeId) { isValid = HasNotifications(projectUserInfo.UserId, projectNotificationDetails.ProjectTeamUpdatesStatus, true) || HasNotifications(projectUserInfo.UserId, projectNotificationDetails.ItemBriefUpdateStatus, true) || HasNotifications(projectUserInfo.UserId, projectNotificationDetails.ScheduleUpdateStatus, true) || HasNotifications(projectUserInfo.UserId, projectNotificationDetails.ProjectUpdateStatus, true) || HasNotifications(projectUserInfo.UserId, projectNotificationDetails.TaskUpdateStatus, true) || HasNotifications(projectUserInfo.UserId, projectNotificationDetails.ItemListUpdateStatus, true); } else if (projectUserInfo.ProjectEmailNotificationCodeId == WeeklyEmailNotificationCodeId) { isValid = HasNotifications(projectUserInfo.UserId, projectNotificationDetails.ProjectTeamUpdatesStatus, false) || HasNotifications(projectUserInfo.UserId, projectNotificationDetails.ItemBriefUpdateStatus, false) || HasNotifications(projectUserInfo.UserId, projectNotificationDetails.ScheduleUpdateStatus, false) || HasNotifications(projectUserInfo.UserId, projectNotificationDetails.ProjectUpdateStatus, false) || HasNotifications(projectUserInfo.UserId, projectNotificationDetails.TaskUpdateStatus, false) || HasNotifications(projectUserInfo.UserId, projectNotificationDetails.ItemListUpdateStatus, false); } return(isValid); }
/// <summary> /// Adds the notification list for project. /// </summary> /// <param name="htmlWriter">The HTML writer.</param> /// <param name="projectUserInfo">The project user info.</param> /// <param name="projectNotificationDetails">The project notification details.</param> private static void AddNotificationListForProject(HtmlTextWriter htmlWriter, ProjectUserInfo projectUserInfo, ProjectNotificationDetails projectNotificationDetails, bool isProjectNotification) { htmlWriter.RenderBeginTag(HtmlTextWriterTag.Ul); // Add notification details if (isProjectNotification) { if (projectUserInfo.ProjectEmailNotificationCodeId == DailyEmailNotificationCodeId) { AddNotificationTypeList(HasNotifications(projectUserInfo.UserId, projectNotificationDetails.ProjectTeamUpdatesStatus, true), HasNotifications(projectUserInfo.UserId, projectNotificationDetails.ItemBriefUpdateStatus, true), HasNotifications(projectUserInfo.UserId, projectNotificationDetails.ScheduleUpdateStatus, true), HasNotifications(projectUserInfo.UserId, projectNotificationDetails.ProjectUpdateStatus, true), HasNotifications(projectUserInfo.UserId, projectNotificationDetails.TaskUpdateStatus, true), HasNotifications(projectUserInfo.UserId, projectNotificationDetails.ItemListUpdateStatus, true), htmlWriter); } else if (projectUserInfo.ProjectEmailNotificationCodeId == WeeklyEmailNotificationCodeId) { AddNotificationTypeList(HasNotifications(projectUserInfo.UserId, projectNotificationDetails.ProjectTeamUpdatesStatus, false), HasNotifications(projectUserInfo.UserId, projectNotificationDetails.ItemBriefUpdateStatus, false), HasNotifications(projectUserInfo.UserId, projectNotificationDetails.ScheduleUpdateStatus, false), HasNotifications(projectUserInfo.UserId, projectNotificationDetails.ProjectUpdateStatus, false), HasNotifications(projectUserInfo.UserId, projectNotificationDetails.TaskUpdateStatus, false), HasNotifications(projectUserInfo.UserId, projectNotificationDetails.ItemListUpdateStatus, false), htmlWriter); } } else { if (projectUserInfo.CompanyEmailNotificationCodeId == DailyEmailNotificationCodeId) { AddNotificationTypeList(HasNotifications(projectUserInfo.UserId, projectNotificationDetails.ProjectTeamUpdatesStatus, true), HasNotifications(projectUserInfo.UserId, projectNotificationDetails.ItemBriefUpdateStatus, true), HasNotifications(projectUserInfo.UserId, projectNotificationDetails.ScheduleUpdateStatus, true), HasNotifications(projectUserInfo.UserId, projectNotificationDetails.ProjectUpdateStatus, true), HasNotifications(projectUserInfo.UserId, projectNotificationDetails.TaskUpdateStatus, true), HasNotifications(projectUserInfo.UserId, projectNotificationDetails.ItemListUpdateStatus, true), htmlWriter); } else if (projectUserInfo.CompanyEmailNotificationCodeId == WeeklyEmailNotificationCodeId) { AddNotificationTypeList(HasNotifications(projectUserInfo.UserId, projectNotificationDetails.ProjectTeamUpdatesStatus, false), HasNotifications(projectUserInfo.UserId, projectNotificationDetails.ItemBriefUpdateStatus, false), HasNotifications(projectUserInfo.UserId, projectNotificationDetails.ScheduleUpdateStatus, false), HasNotifications(projectUserInfo.UserId, projectNotificationDetails.ProjectUpdateStatus, false), HasNotifications(projectUserInfo.UserId, projectNotificationDetails.TaskUpdateStatus, false), HasNotifications(projectUserInfo.UserId, projectNotificationDetails.ItemListUpdateStatus, false), htmlWriter); } } htmlWriter.RenderEndTag(); // end of UL // Add Link to notification page htmlWriter.AddStyleAttribute(HtmlTextWriterStyle.TextAlign, "right"); htmlWriter.AddStyleAttribute(HtmlTextWriterStyle.Width, "100%"); htmlWriter.RenderBeginTag(HtmlTextWriterTag.Div); string url = string.Format("{0}/Project/ProjectNotifications.aspx?projectid={1}", Utils.GetSystemValue("SBUserWebURL"), projectUserInfo.ProjectId); htmlWriter.AddAttribute(HtmlTextWriterAttribute.Href, url); htmlWriter.AddAttribute(HtmlTextWriterAttribute.Target, "_blank"); htmlWriter.RenderBeginTag(HtmlTextWriterTag.A); htmlWriter.Write("View Updates Report"); htmlWriter.RenderEndTag(); htmlWriter.RenderEndTag(); }
/// <summary> /// Gets the email text. /// </summary> /// <param name="userInfo">The user info.</param> /// <param name="projectUserInfos">The project user infos.</param> /// <param name="companyAdminProjectUserInfos">The company admin project user infos.</param> /// <returns></returns> private static string GetEmailText(ProjectUserInfo userInfo, List <ProjectUserInfo> projectUserInfos, List <ProjectUserInfo> companyAdminProjectUserInfos) { StringBuilder sbEmailText = new StringBuilder(); using (StringWriter swEmailText = new StringWriter(sbEmailText, CultureInfo.InvariantCulture)) { // Html text writer for generate email html content. using (HtmlTextWriter htmlWriter = new HtmlTextWriter(swEmailText)) { string projectNotificationDuration = string.Empty; htmlWriter.AddStyleAttribute(HtmlTextWriterStyle.Width, "700px"); htmlWriter.RenderBeginTag(HtmlTextWriterTag.Div); if (projectUserInfos.Count > 0) { if (userInfo.ProjectEmailNotificationCodeId == DailyEmailNotificationCodeId) { projectNotificationDuration = "yesterday"; } else if (userInfo.ProjectEmailNotificationCodeId == WeeklyEmailNotificationCodeId) { projectNotificationDuration = "in the last 7 days"; } htmlWriter.RenderBeginTag(HtmlTextWriterTag.P); htmlWriter.Write(string.Format("This is what’s been happening on all your StageBitz projects since {0}.", projectNotificationDuration)); htmlWriter.RenderEndTag(); // Sort by projects that has notifications and project name. Dictionary <ProjectUserInfo, ProjectNotificationDetails> sortedProjectUserInfos = (from pui in projectUserInfos from pnd in (from pnd in ProjectNotificationDetailsList where pui.ProjectId == pnd.ProjectId select pnd).DefaultIfEmpty().Take(1) orderby pnd == null, pui.ProjectName select new { ProjectUserInfo = pui, ProjectNotificationDetails = pnd }).ToDictionary(d => d.ProjectUserInfo, d => d.ProjectNotificationDetails); // Loop project user info list. foreach (ProjectUserInfo projectUserInfo in sortedProjectUserInfos.Keys) { ProjectNotificationDetails projectNotificationDetails = sortedProjectUserInfos[projectUserInfo]; // Add P tag with padding htmlWriter.AddStyleAttribute(HtmlTextWriterStyle.PaddingLeft, "15px"); htmlWriter.RenderBeginTag(HtmlTextWriterTag.P); // Bold the project name htmlWriter.RenderBeginTag(HtmlTextWriterTag.B); htmlWriter.Write(projectUserInfo.ProjectName); htmlWriter.RenderEndTag(); if (projectNotificationDetails != null && ValidateNotificationDetails(projectNotificationDetails, projectUserInfo)) { htmlWriter.Write(string.Format(", by {0}, has had updates to the:", projectUserInfo.CompanyName)); AddNotificationListForProject(htmlWriter, projectUserInfo, projectNotificationDetails, true); } else { htmlWriter.Write(string.Format(", by {0}, has had no updates.", projectUserInfo.CompanyName)); } htmlWriter.RenderEndTag(); // end of P } } if (companyAdminProjectUserInfos.Count > 0) { if (userInfo.CompanyEmailNotificationCodeId == DailyEmailNotificationCodeId) { projectNotificationDuration = "yesterday"; } else if (userInfo.CompanyEmailNotificationCodeId == WeeklyEmailNotificationCodeId) { projectNotificationDuration = "in the last 7 days"; } string companyText = companyAdminProjectUserInfos.Count > 1 ? "Companies" : "Company’s"; string projectUserAndCompanyUserTextOther = projectUserInfos.Count > 0 ? "other " : string.Empty; string projectUserAndCompanyUserTextAlso = projectUserInfos.Count > 0 ? "also " : string.Empty; htmlWriter.RenderBeginTag(HtmlTextWriterTag.P); htmlWriter.Write(string.Format("You are {0}a Company Administrator. Here’s what’s been happening on your {1} {2}Projects since {3}.", projectUserAndCompanyUserTextAlso, companyText, projectUserAndCompanyUserTextOther, projectNotificationDuration)); htmlWriter.RenderEndTag(); // Group by company id and sort by project name. Dictionary <int, List <ProjectUserInfo> > groupedCompanyAdminProjectUserInfos = companyAdminProjectUserInfos.OrderBy(capui => capui.CompanyName). GroupBy(capui => capui.CompanyId).ToDictionary(g => g.Key, g => g.OrderBy(pui => pui.ProjectName).ToList()); foreach (int companyId in groupedCompanyAdminProjectUserInfos.Keys) { List <ProjectUserInfo> sortedCompanyAdminProjectUserInfos = groupedCompanyAdminProjectUserInfos[companyId]; string companyName = sortedCompanyAdminProjectUserInfos[0].CompanyName; // Add P tag with padding htmlWriter.AddStyleAttribute(HtmlTextWriterStyle.PaddingLeft, "15px"); htmlWriter.RenderBeginTag(HtmlTextWriterTag.Div); htmlWriter.RenderBeginTag(HtmlTextWriterTag.B); htmlWriter.Write(string.Concat(companyName, ":")); htmlWriter.RenderEndTag(); foreach (ProjectUserInfo projectUserInfo in sortedCompanyAdminProjectUserInfos) { ProjectNotificationDetails projectNotificationDetails = ProjectNotificationDetailsList.Where(pnd => pnd.ProjectId == projectUserInfo.ProjectId).FirstOrDefault(); if (projectNotificationDetails != null) { // Add P tag with padding htmlWriter.AddStyleAttribute(HtmlTextWriterStyle.PaddingLeft, "15px"); htmlWriter.RenderBeginTag(HtmlTextWriterTag.P); // Bold the project name htmlWriter.RenderBeginTag(HtmlTextWriterTag.B); htmlWriter.Write(projectUserInfo.ProjectName); htmlWriter.RenderEndTag(); htmlWriter.Write(" has had updates to the:"); AddNotificationListForProject(htmlWriter, projectUserInfo, projectNotificationDetails, false); htmlWriter.RenderEndTag(); // end of P } } htmlWriter.RenderEndTag(); // end of P } } htmlWriter.RenderEndTag(); return(sbEmailText.ToString()); } } }