Пример #1
0
        public static SMItemUser GetByID(int SMItemUserID, IEnumerable <string> includeList = null)
        {
            SMItemUser obj = null;
            string     key = cacheKeyPrefix + SMItemUserID + GetCacheIncludeText(includeList);

            SMItemUser tmpClass = null;

            if (Cache.IsEnabled)
            {
                if (Cache.IsEmptyCacheItem(key))
                {
                    return(null);
                }
                tmpClass = Cache[key] as SMItemUser;
            }

            if (tmpClass != null)
            {
                obj = tmpClass;
            }
            else
            {
                using (Entities entity = new Entities())
                {
                    IQueryable <SMItemUser> itemQuery = AddIncludes(entity.SMItemUser, includeList);
                    obj = itemQuery.FirstOrDefault(n => n.SMItemUserID == SMItemUserID);
                }
                Cache.Store(key, obj);
            }

            return(obj);
        }
Пример #2
0
 public SMItemUser(SMItemUser objectToCopy)
 {
     CMMicrositeID    = objectToCopy.CMMicrositeID;
     LanguageID       = objectToCopy.LanguageID;
     MicrositeDefault = objectToCopy.MicrositeDefault;
     SMItemUserID     = objectToCopy.SMItemUserID;
     UserID           = objectToCopy.UserID;
 }
Пример #3
0
        public static void SendSiteMapApprovalEmailAlerts(int userID, int?micrositeID, int?languageID, bool isAdmin, bool?approval)
        {
            if (Settings.EnableApprovals && Settings.SendApprovalEmails)
            {
                MailMessage email  = new MailMessage();
                SmtpClient  client = new SmtpClient();
                if (!approval.HasValue)
                {
                    string key = "ContentManager_SiteMapApprovalEmails_" + userID + "_" + micrositeID + "_" + languageID;
                    if (!Settings.EnableCaching || HttpContext.Current == null || HttpContext.Current.Cache == null || HttpContext.Current.Cache[key] == null)
                    {
                        User     userEntity     = User.GetByID(userID);
                        Language languageEntity = null;
                        if (languageID.HasValue)
                        {
                            languageEntity = Language.GetByID(languageID.Value);
                        }
                        //Don't send Admin Email if Admin is the one who edited
                        if (!isAdmin)
                        {
                            //Send Admin Email
                            email.From = new MailAddress(Globals.Settings.FromEmail);
                            if (!String.IsNullOrEmpty(Settings.ApprovalAdminEmailAddresses))
                            {
                                foreach (string s in Settings.ApprovalAdminEmailAddresses.Split(';'))
                                {
                                    email.To.Add(new MailAddress(s));
                                }
                            }
                            else                             //Send to all Admins
                            {
                                foreach (UserRole admin in UserRole.UserRoleGetWithUserByRoleName("Admin"))
                                {
                                    email.To.Add(new MailAddress(admin.User.Email, admin.User.Name));
                                }
                            }

                            email.IsBodyHtml = true;
                            email.Body       = userEntity.Name + " has updated the" + (languageEntity != null ? " " + languageEntity.Culture : "") + (micrositeID.HasValue ? micrositeID == -1 ? " Microsite Default" : " " + CMMicrosite.GetByID(micrositeID.Value).Name : "") + " <a href=\"" + Helpers.RootPath + "admin/content-manager/sitemap.aspx" + (micrositeID.HasValue ? "?micrositeid=" + micrositeID.Value : "") + (languageEntity != null ? (micrositeID.HasValue ? "&" : "?") + "language=" + languageEntity.CultureName : "") + "\">Sitemap</a>";
                            email.Subject    = Globals.Settings.SiteTitle + " - Sitemap Approval Required";

                            client.Send(email);
                        }

                        //Send Editor Email
                        email      = new MailMessage();
                        email.From = new MailAddress(Globals.Settings.FromEmail);

                        List <SMItemUser> allEditors;
                        if (micrositeID.HasValue && micrositeID > 0)
                        {
                            allEditors = SMItemUser.SMItemUserGetByCMMicrositeID(micrositeID);
                        }
                        else if (micrositeID.HasValue && micrositeID == -1)
                        {
                            allEditors = SMItemUser.SMItemUserGetByMicrositeDefault(true);
                        }
                        else
                        {
                            allEditors = SMItemUser.GetAll().Where(s => s.CMMicrositeID == null && !s.MicrositeDefault).ToList();
                        }

                        if (languageID.HasValue)
                        {
                            allEditors = allEditors.Where(s => s.LanguageID == languageID.Value).ToList();
                        }

                        foreach (SMItemUser id in allEditors)
                        {
                            if (id.UserID != userID)
                            {
                                User editor = User.GetByID(id.UserID);
                                email.To.Add(new MailAddress(editor.Email, editor.Name));
                            }
                        }

                        if (email.To.Count > 0)
                        {
                            email.IsBodyHtml = true;
                            email.Body       = userEntity.Name + " has updated the" + (languageEntity != null ? " " + languageEntity.Culture : "") + (micrositeID.HasValue ? micrositeID == -1 ? " Microsite Default" : " " + CMMicrosite.GetByID(micrositeID.Value).Name : "") + " <a href=\"" + Helpers.RootPath + "admin/content-manager/sitemap.aspx" + (micrositeID.HasValue ? "?micrositeid=" + micrositeID.Value : "") + (languageEntity != null ? (micrositeID.HasValue ? "&" : "?") + "language=" + languageEntity.CultureName : "") + "\">Sitemap</a>, which you have also edited.  The Sitemap is still awaiting approval from an Admin.";
                            email.Subject    = Globals.Settings.SiteTitle + " - Sitemap Edited";

                            client = new SmtpClient();
                            client.Send(email);
                        }
                        //Only send email alerts every 10 minutes per user that changes sitemap
                        if (Settings.EnableCaching && HttpContext.Current != null && HttpContext.Current.Cache != null)
                        {
                            HttpContext.Current.Cache.Insert(key, true, null, DateTime.Now.AddMinutes(10), TimeSpan.Zero);
                        }
                    }
                }
                else                 //Approve/Denied
                {
                    //Send Editors Email
                    email      = new MailMessage();
                    email.From = new MailAddress(Globals.Settings.FromEmail);

                    List <SMItemUser> allEditors;
                    if (micrositeID.HasValue && micrositeID > 0)
                    {
                        allEditors = SMItemUser.SMItemUserGetByCMMicrositeID(micrositeID);
                    }
                    else if (micrositeID.HasValue && micrositeID == -1)
                    {
                        allEditors = SMItemUser.SMItemUserGetByMicrositeDefault(true);
                    }
                    else
                    {
                        allEditors = SMItemUser.GetAll().Where(s => s.CMMicrositeID == null && !s.MicrositeDefault).ToList();
                    }

                    if (languageID.HasValue)
                    {
                        allEditors = allEditors.Where(s => s.LanguageID == languageID.Value).ToList();
                    }

                    foreach (SMItemUser id in allEditors)
                    {
                        if (id.UserID != userID)
                        {
                            User editor = User.GetByID(id.UserID);
                            email.To.Add(new MailAddress(editor.Email, editor.Name));
                        }
                    }

                    SMItemUser.DeleteAll(micrositeID, languageID);

                    if (email.To.Count > 0)
                    {
                        Language languageEntity = null;
                        if (languageID.HasValue)
                        {
                            languageEntity = Language.GetByID(languageID.Value);
                        }

                        email.IsBodyHtml = true;
                        email.Body       = "An Admin has " + (approval.Value ? "approved" : "denied") + " the changes to the" + (languageEntity != null ? " " + languageEntity.Culture : "") + (micrositeID.HasValue ? micrositeID == -1 ? " Microsite Default" : " " + CMMicrosite.GetByID(micrositeID.Value).Name : "") + " <a href=\"" + Helpers.RootPath + "admin/content-manager/sitemap.aspx" + (micrositeID.HasValue ? "?micrositeid=" + micrositeID.Value : "") + (languageEntity != null ? (micrositeID.HasValue ? "&" : "?") + "language=" + languageEntity.CultureName : "") + "\">Sitemap</a> that you made.";
                        email.Subject    = Globals.Settings.SiteTitle + " - Sitemap " + (approval.Value ? "Approved" : "Denied");

                        client = new SmtpClient();
                        client.Send(email);
                    }
                }
            }
        }