Example #1
0
        private static void SetProjectUserInfoAttributes(XElement projectUser, ProjectUserInfo projectUserInfo)
        {
            foreach (var attribute in projectUser.Attributes())
            {
                if (string.Compare(attribute.Name.LocalName, "UserId", StringComparison.InvariantCultureIgnoreCase) == 0)
                {
                    projectUserInfo.UserId = attribute.Value;
                }

                if (string.Compare(attribute.Name.LocalName, "FullName", StringComparison.InvariantCultureIgnoreCase) == 0)
                {
                    projectUserInfo.FullName = attribute.Value;
                }

                if (string.Compare(attribute.Name.LocalName, "Description", StringComparison.InvariantCultureIgnoreCase) == 0)
                {
                    projectUserInfo.Description = attribute.Value;
                }

                if (string.Compare(attribute.Name.LocalName, "Email", StringComparison.InvariantCultureIgnoreCase) == 0)
                {
                    projectUserInfo.Email = attribute.Value;
                }

                if (string.Compare(attribute.Name.LocalName, "PhoneNumber", StringComparison.InvariantCultureIgnoreCase) == 0)
                {
                    projectUserInfo.PhoneNumber = attribute.Value;
                }

                if (string.Compare(attribute.Name.LocalName, "EmailType", StringComparison.InvariantCultureIgnoreCase) == 0)
                {
                    projectUserInfo.EmailType = attribute.Value;
                }
            }
        }
Example #2
0
        public async Task <ApiResult> Updateusers(int id, APIProUserViewModel p)
        {
            // 以接口的形式返回数据
            var res = new ApiResult();
            List <ProjectUserInfo> projectUserInfos  = projectUserdb.GetWhere(o => o.ProjectID == p.ProjectID && o.ProjectNodeID == p.ProjectNodeID && o.IsEnable == true && o.UserID == p.UserID);
            List <ProjectUserInfo> projectUserInfos2 = projectUserdb.GetWhere(o => o.ProjectID == p.ProjectID && o.ProjectNodeID == p.ProjectNodeID && o.IsEnable == true && o.Role == 1);
            List <ProjectUserInfo> projectUserInfos3 = projectUserdb.GetWhere(o => o.ID == id && o.IsEnable == true && o.UserID == p.UserID);
            List <ProjectUserInfo> projectUserInfos4 = projectUserdb.GetWhere(o => o.ID == id && o.IsEnable == true && o.Role == 1 && o.UserID == p.UserID);

            if (projectUserInfos.Count > 0 && projectUserInfos3.Count == 0 && p.IsEnable == true)
            {
                res.msg     = "已有此人";
                res.success = false;
            }
            else if (projectUserInfos2.Count > 0 && p.Role == 1 && p.IsEnable == true && projectUserInfos4.Count == 0)
            {
                res.msg     = "已有组长,请修改";
                res.success = false;
            }
            else
            {
                try
                {
                    ProjectUserInfo m = projectUserdb.GetId(id);
                    if (m != null)
                    {
                        m.ProjectID     = p.ProjectID;
                        m.ProjectNodeID = p.ProjectNodeID;
                        m.UserID        = p.UserID;
                        m.Role          = p.Role;
                        m.Proportion    = p.Proportion;
                        m.Sorting       = p.Sorting;
                        m.IsEnable      = p.IsEnable;
                        res.success     = projectUserdb.Update(m) > 0;
                    }
                }
                catch (Exception ex)
                {
                    res.statusCode = (int)ApiEnum.Error;
                    res.msg        = ApiEnum.Error.GetEnumText() + ex.Message;
                }
            }
            // {"success":true,"message":null,"statusCode":200,"data":null}
            return(await Task.Run(() => res));
        }
Example #3
0
        public async Task <ApiResult> Addusers(APIProUserViewModel p)
        {
            // 以接口的形式返回数据
            var res = new ApiResult();
            List <ProjectUserInfo> projectUserInfos  = projectUserdb.GetWhere(o => o.ProjectID == p.ProjectID && o.ProjectNodeID == p.ProjectNodeID && o.IsEnable == true && o.UserID == p.UserID);
            List <ProjectUserInfo> projectUserInfos2 = projectUserdb.GetWhere(o => o.ProjectID == p.ProjectID && o.ProjectNodeID == p.ProjectNodeID && o.IsEnable == true && o.Role == 1);

            if (projectUserInfos.Count > 0)
            {
                res.msg     = "已有此人";
                res.success = false;
            }
            else if (projectUserInfos2.Count > 0 && p.Role == 1 && p.IsEnable == true)
            {
                res.msg     = "已有组长,请修改";
                res.success = false;
            }
            else
            {
                try
                {
                    ProjectUserInfo m = new ProjectUserInfo()
                    {
                        ProjectID     = p.ProjectID,
                        ProjectNodeID = p.ProjectNodeID,
                        UserID        = p.UserID,
                        Role          = p.Role,
                        Proportion    = p.Proportion,
                        Sorting       = p.Sorting,
                        AddDate       = DateTime.Now,
                        IsEnable      = p.IsEnable
                    };
                    res.success = projectUserdb.Add(m) > 0;
                }
                catch (Exception ex)
                {
                    res.statusCode = (int)ApiEnum.Error;
                    res.msg        = ApiEnum.Error.GetEnumText() + ex.Message;
                }
            }
            // {"success":true,"message":null,"statusCode":200,"data":null}
            return(await Task.Run(() => res));
        }
Example #4
0
        public List <ProjectUserInfo> GetProjectUsers(string filePath)
        {
            var projectUsers = new List <ProjectUserInfo>();

            var xml     = XDocument.Load(filePath);
            var project = xml.Root;

            if (project != null && string.Compare(project.Name.LocalName, "Project", StringComparison.InvariantCultureIgnoreCase) == 0)
            {
                // recover the project files
                foreach (var element in project.Elements())
                {
                    if (string.Compare(element.Name.LocalName, "Users", StringComparison.InvariantCultureIgnoreCase) == 0)
                    {
                        foreach (var projectUser in element.Elements())
                        {
                            if (string.Compare(projectUser.Name.LocalName, "User", StringComparison.InvariantCultureIgnoreCase) == 0)
                            {
                                if (!projectUser.HasAttributes)
                                {
                                    continue;
                                }

                                var projectUserInfo = new ProjectUserInfo();

                                SetProjectUserInfoAttributes(projectUser, projectUserInfo);

                                projectUsers.Add(projectUserInfo);
                            }
                        }
                    }
                }
            }

            return(projectUsers);
        }
        /// <summary>
        /// Sends the email notifications.
        /// </summary>
        /// <param name="dateToConsider">The date to consider.</param>
        public static void SendEmailNotifications(DateTime dateToConsider)
        {
            // Handles the concurrent issues. (this class should not access concurrently)
            if (ProjectNotificationDetailsList.Count == 0)
            {
                using (StageBitzDB dataContext = new StageBitzDB())
                {
                    // Set code values.
                    DailyEmailNotificationCodeId  = Utils.GetCodeIdByCodeValue("UserEmailNotificationType", "DAILY");
                    WeeklyEmailNotificationCodeId = Utils.GetCodeIdByCodeValue("UserEmailNotificationType", "WEEKLY");
                    NoEmailNotificationCodeId     = Utils.GetCodeIdByCodeValue("UserEmailNotificationType", "NOTATALL");

                    bool isWeeklyEmailSendDate = false;

                    NotificationBL notificationBL = new NotificationBL(dataContext);
                    ProjectBL      projectBL      = new ProjectBL(dataContext);

                    DateTime endDate  = dateToConsider;
                    int      dateDiff = 1;

                    // If weekly email day set date diff as 7 days.
                    if (dateToConsider.DayOfWeek == (DayOfWeek)Enum.Parse(typeof(DayOfWeek), Utils.GetSystemValue("EmailNotificationDayOfWeek")))
                    {
                        dateDiff = 7;
                        isWeeklyEmailSendDate = true;
                    }

                    // Get project notifications static list.
                    ProjectNotificationDetailsList = notificationBL.GetUserEmailNotifications(dateToConsider, dateDiff);

                    // Get all project ids with notifications.
                    List <int> projectIds = ProjectNotificationDetailsList.Select(pnd => pnd.ProjectId).Distinct().ToList <int>();

                    // Get all user ids need to send email notifications.
                    List <int> allUsers = projectBL.GetAllProjectUserAndCompanyUserIds(projectIds);

                    // Send emails for all users.
                    foreach (int userId in allUsers)
                    {
                        // Get project user infos
                        List <ProjectUserInfo> projectUserInfoList = projectBL.GetProjectUserInfo(userId);

                        // Get company admin user infos
                        List <ProjectUserInfo> companyAdminProjectUserInfoList = projectBL.GetCompanyAdminProjectUserInfo(projectIds, userId);

                        // remove duplicate project user infos from company admin project list.
                        companyAdminProjectUserInfoList.RemoveAll(capui => projectUserInfoList.Exists(pui => (capui.ProjectId == pui.ProjectId && capui.UserId == pui.UserId)));

                        if (projectUserInfoList.Count > 0 || companyAdminProjectUserInfoList.Count > 0)
                        {
                            ProjectUserInfo user = null;

                            // Get first one.
                            if (projectUserInfoList.Count > 0)
                            {
                                user = projectUserInfoList.FirstOrDefault();
                            }
                            else if (companyAdminProjectUserInfoList.Count > 0)
                            {
                                user = companyAdminProjectUserInfoList.FirstOrDefault();
                            }

                            if (user != null)
                            {
                                // Filter project user infos.
                                List <ProjectUserInfo> projectUserInfos = GetFilteredProjectUserInfoForUser(user.UserId, user.ProjectEmailNotificationCodeId, projectUserInfoList, isWeeklyEmailSendDate, true);

                                // Filter company admin user infos.
                                List <ProjectUserInfo> companyAdminProjectUserInfos = GetFilteredProjectUserInfoForUser(user.UserId, user.CompanyEmailNotificationCodeId, companyAdminProjectUserInfoList, isWeeklyEmailSendDate, false);

                                if (projectUserInfos.Count > 0 || companyAdminProjectUserInfos.Count > 0)
                                {
                                    // Gets the email content.
                                    string emailText = GetEmailText(user, projectUserInfos, companyAdminProjectUserInfos);

                                    // Send the email.
                                    EmailSender.SendNotificationEmail(user.UserEmail, user.UserName, emailText);
                                }
                            }
                        }
                    }
                }

                // Clear static project notification details list.
                ProjectNotificationDetailsList.Clear();
            }
        }
        /// <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>
        /// 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>
        /// 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());
                }
            }
        }