예제 #1
0
 public ExtendedUserData(string UserName)
 {
     using (CarrotCMSDataContext _db = CarrotCMSDataContext.Create()) {
         vw_carrot_UserData rc = CompiledQueries.cqFindUserByName(_db, UserName);
         LoadUserData(rc);
     }
 }
예제 #2
0
		public static int GetSimilar(Guid SiteID, Guid CategoryID, string categorySlug) {
			using (CarrotCMSDataContext _db = CarrotCMSDataContext.Create()) {
				IQueryable<carrot_ContentCategory> query = CompiledQueries.cqGetContentCategoryNoMatch(_db, SiteID, CategoryID, categorySlug);

				return query.Count();
			}
		}
예제 #3
0
 public ExtendedUserData(Guid UserID)
 {
     using (CarrotCMSDataContext _db = CarrotCMSDataContext.Create()) {
         vw_carrot_UserData rc = CompiledQueries.cqFindUserByID(_db, UserID);
         LoadUserData(rc);
     }
 }
예제 #4
0
        public static void SaveSerialized(Guid itemID, string sKey, string sData)
        {
            using (CarrotCMSDataContext _db = CarrotCMSDataContext.Create()) {
                bool bAdd = false;

                carrot_SerialCache itm = CompiledQueries.SearchSeriaCache(_db, itemID, sKey);

                if (itm == null)
                {
                    bAdd = true;
                    itm  = new carrot_SerialCache();
                    itm.SerialCacheID = Guid.NewGuid();
                    itm.SiteID        = SiteData.CurrentSiteID;
                    itm.ItemID        = itemID;
                    itm.EditUserId    = SecurityData.CurrentUserGuid;
                    itm.KeyType       = sKey;
                }

                itm.SerializedData = sData;
                itm.EditDate       = DateTime.UtcNow;

                if (bAdd)
                {
                    _db.carrot_SerialCaches.InsertOnSubmit(itm);
                }
                _db.SubmitChanges();
            }
        }
예제 #5
0
 public int GetSitePageCount(ContentPageType.PageType entryType)
 {
     using (CarrotCMSDataContext _db = CarrotCMSDataContext.Create()) {
         int iCount = CannedQueries.GetAllByTypeList(_db, this.SiteID, false, entryType).Count();
         return(iCount);
     }
 }
예제 #6
0
        public static bool AddUserToRole(string userName, string roleName)
        {
            using (CarrotCMSDataContext _db = CarrotCMSDataContext.Create()) {
                membership_Role role = (from r in _db.membership_Roles
                                        where r.Name == roleName
                                        select r).FirstOrDefault();

                membership_User user = (from u in _db.membership_Users
                                        where u.UserName == userName
                                        select u).FirstOrDefault();

                membership_UserRole usrRole = (from r in _db.membership_Roles
                                               join ur in _db.membership_UserRoles on r.Id equals ur.RoleId
                                               join u in _db.membership_Users on ur.UserId equals u.Id
                                               where r.Name == roleName &&
                                               u.UserName == userName
                                               select ur).FirstOrDefault();

                if (usrRole == null && role != null && user != null)
                {
                    usrRole        = new membership_UserRole();
                    usrRole.UserId = user.Id;
                    usrRole.RoleId = role.Id;
                    _db.membership_UserRoles.InsertOnSubmit(usrRole);
                    _db.SubmitChanges();

                    return(true);
                }
                return(false);
            }
        }
예제 #7
0
        public static List <UserProfile> GetCreditUserProfileSearch(string searchTerm)
        {
            List <UserProfile> usrs    = null;
            List <string>      admins  = null;
            List <string>      editors = null;

            using (CarrotCMSDataContext _db = CarrotCMSDataContext.Create()) {
                admins = (from ur in _db.membership_UserRoles
                          join u in _db.membership_Users on ur.UserId equals u.Id
                          join r in _db.membership_Roles on ur.RoleId equals r.Id
                          join ud in _db.carrot_UserDatas on u.Id equals ud.UserKey
                          where r.Name == CMSGroup_Admins
                          select ud.UserKey.ToLower()).ToList();

                editors = (from sm in _db.carrot_UserSiteMappings
                           join ud in _db.carrot_UserDatas on sm.UserId equals ud.UserId
                           where sm.SiteID == SiteData.CurrentSiteID
                           select ud.UserKey.ToLower()).ToList();

                usrs = (from u in _db.membership_Users
                        join ud1 in _db.carrot_UserDatas on u.Id equals ud1.UserKey into ud2
                        from ud in ud2.DefaultIfEmpty()
                        where (u.UserName.ToLower().Contains(searchTerm.ToLower()) ||
                               u.Email.ToLower().Contains(searchTerm.ToLower())) &&
                        admins.Union(editors).Contains(u.Id.ToLower())
                        select new UserProfile(u, ud)).Take(50).ToList();
            }

            return(usrs);
        }
예제 #8
0
        public static int GetHistoryListCount(Guid siteID, bool showLatestOnly, DateTime?editDate, Guid?editUserID)
        {
            Guid userID = Guid.Empty;

            if (editUserID.HasValue)
            {
                userID = editUserID.Value;
            }

            DateTime dateStart = DateTime.UtcNow.Date.AddDays(-2);
            DateTime dateEnd   = DateTime.UtcNow.Date.AddDays(1);

            if (editDate.HasValue)
            {
                dateStart = editDate.Value.Date.AddDays(-8);
                dateEnd   = editDate.Value.Date.AddDays(1);
            }

            using (CarrotCMSDataContext _db = CarrotCMSDataContext.Create()) {
                return((from h in _db.vw_carrot_EditHistories
                        where h.SiteID == siteID &&
                        (!showLatestOnly || h.IsLatestVersion == true) &&
                        (!editDate.HasValue ||
                         (h.EditDate.Date >= dateStart.Date && h.EditDate.Date <= dateEnd.Date)) &&
                        (!editUserID.HasValue || h.EditUserId == userID)
                        select h).Count());
            }
        }
예제 #9
0
        public static List <ApplicationUser> GetCreditUserSearch(string searchTerm)
        {
            List <ApplicationUser> usrs    = null;
            List <string>          admins  = null;
            List <string>          editors = null;

            using (CarrotCMSDataContext _db = CarrotCMSDataContext.Create()) {
                admins = (from ur in _db.membership_UserRoles
                          join u in _db.membership_Users on ur.UserId equals u.Id
                          join r in _db.membership_Roles on ur.RoleId equals r.Id
                          join ud in _db.carrot_UserDatas on u.Id equals ud.UserKey
                          where r.Name == CMSGroup_Admins
                          select ud.UserKey.ToLower()).ToList();

                editors = (from sm in _db.carrot_UserSiteMappings
                           join ud in _db.carrot_UserDatas on sm.UserId equals ud.UserId
                           where sm.SiteID == SiteData.CurrentSiteID
                           select ud.UserKey.ToLower()).ToList();
            }

            using (var securityHelper = new SecurityHelper()) {
                usrs = (from u in securityHelper.DataContext.Users
                        where (u.UserName.ToLower().Contains(searchTerm.ToLower()) ||
                               u.Email.ToLower().Contains(searchTerm.ToLower())) &&
                        admins.Union(editors).Contains(u.Id.ToLower())
                        select securityHelper.UserManager.FindByName(u.UserName)).Take(50).ToList();
            }

            return(usrs);
        }
예제 #10
0
        public bool VerifyUserHasSiteAccess(Guid siteID, Guid userID)
        {
            //all admins have rights to all sites
            if (SecurityData.IsAdmin)
            {
                return(true);
            }

            // if user is neither admin nor editor, they should not be in the backend of the site
            if (!(SecurityData.IsSiteEditor || SecurityData.IsAdmin))
            {
                return(false);
            }

            using (CarrotCMSDataContext _db = CarrotCMSDataContext.Create()) {
                // by this point, the user is probably an editor, make sure they have rights to this site
                IQueryable <Guid> lstSiteIDs = (from l in _db.carrot_UserSiteMappings
                                                where l.UserId == userID &&
                                                l.SiteID == siteID
                                                select l.SiteID);

                return(lstSiteIDs.Any());
            }

            return(false);
        }
예제 #11
0
        public bool AddToSite(Guid siteID)
        {
            using (CarrotCMSDataContext _db = CarrotCMSDataContext.Create()) {
                carrot_UserSiteMapping map = (from m in _db.carrot_UserSiteMappings
                                              where m.UserId == this.UserId &&
                                              m.SiteID == siteID
                                              select m).FirstOrDefault();

                if (map == null)
                {
                    _siteIDs = null;

                    map = new carrot_UserSiteMapping();
                    map.UserSiteMappingID = Guid.NewGuid();
                    map.SiteID            = siteID;
                    map.UserId            = this.UserId;

                    _db.carrot_UserSiteMappings.InsertOnSubmit(map);
                    _db.SubmitChanges();

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
예제 #12
0
 public static int GetCommentCountByContent(Guid siteID, Guid rootContentID, DateTime postDate, string postIP)
 {
     using (CarrotCMSDataContext _db = CarrotCMSDataContext.Create()) {
         return((from c in CannedQueries.FindCommentsByDate(_db, siteID, rootContentID, postDate, postIP)
                 select c).Count());
     }
 }
예제 #13
0
        public void Save()
        {
            using (CarrotCMSDataContext _db = CarrotCMSDataContext.Create()) {
                carrot_TextWidget s = CompiledQueries.cqTextWidgetByID(_db, this.TextWidgetID);

                if (s == null)
                {
                    s = new carrot_TextWidget();
                    s.TextWidgetID       = Guid.NewGuid();
                    s.SiteID             = this.SiteID;
                    s.TextWidgetAssembly = this.TextWidgetAssembly;
                    _db.carrot_TextWidgets.InsertOnSubmit(s);
                }

                s.ProcessBody      = this.ProcessBody;
                s.ProcessPlainText = this.ProcessPlainText;
                s.ProcessHTMLText  = this.ProcessHTMLText;
                s.ProcessComment   = this.ProcessComment;
                s.ProcessSnippet   = this.ProcessSnippet;

                _db.SubmitChanges();

                this.TextWidgetID = s.TextWidgetID;
            }
        }
예제 #14
0
 public static int GetAllCommentCountBySite(Guid siteID)
 {
     using (CarrotCMSDataContext _db = CarrotCMSDataContext.Create()) {
         return((from c in CannedQueries.GetSiteContentComments(_db, siteID)
                 select c).Count());
     }
 }
예제 #15
0
 public static int GetCommentCountBySiteAndType(Guid siteID, ContentPageType.PageType pageType, bool?approved, bool?spam)
 {
     using (CarrotCMSDataContext _db = CarrotCMSDataContext.Create()) {
         return((from c in CannedQueries.GetSiteContentCommentsByPostType(_db, siteID, pageType, approved, spam)
                 select c).Count());
     }
 }
예제 #16
0
 public static int GetCommentCountByContent(Guid rootContentID, bool?approved, bool?spam)
 {
     using (CarrotCMSDataContext _db = CarrotCMSDataContext.Create()) {
         return((from c in CannedQueries.GetContentPageComments(_db, rootContentID, approved, spam)
                 select c).Count());
     }
 }
예제 #17
0
        public static void AddUserToRole(Guid UserId, string roleName)
        {
            using (CarrotCMSDataContext _db = CarrotCMSDataContext.Create()) {
                membership_Role role = (from r in _db.membership_Roles
                                        where r.Name.ToLower() == roleName.ToLower()
                                        select r).FirstOrDefault();

                membership_User user = (from u in _db.membership_Users
                                        join ud in _db.carrot_UserDatas on u.Id equals ud.UserKey
                                        where ud.UserId == UserId
                                        select u).FirstOrDefault();

                membership_UserRole usrRole = (from r in _db.membership_Roles
                                               join ur in _db.membership_UserRoles on r.Id equals ur.RoleId
                                               join u in _db.membership_Users on ur.UserId equals u.Id
                                               join ud in _db.carrot_UserDatas on u.Id equals ud.UserKey
                                               where r.Name.ToLower() == roleName.ToLower() &&
                                               ud.UserId == UserId
                                               select ur).FirstOrDefault();

                if (usrRole == null && role != null && user != null)
                {
                    usrRole        = new membership_UserRole();
                    usrRole.UserId = user.Id;
                    usrRole.RoleId = role.Id;
                    _db.membership_UserRoles.InsertOnSubmit(usrRole);
                    _db.SubmitChanges();
                }
            }
        }
예제 #18
0
        public void Save()
        {
            using (CarrotCMSDataContext _db = CarrotCMSDataContext.Create()) {
                bool            bNew = false;
                carrot_UserData usr  = CompiledQueries.cqFindUserTblByID(_db, this.UserId);

                if (usr == null)
                {
                    usr         = new carrot_UserData();
                    usr.UserKey = this.UserKey;
                    usr.UserId  = Guid.NewGuid();
                    bNew        = true;
                }

                usr.UserNickName = this.UserNickName;
                usr.FirstName    = this.FirstName;
                usr.LastName     = this.LastName;
                usr.UserBio      = this.UserBio;

                if (bNew)
                {
                    _db.carrot_UserDatas.InsertOnSubmit(usr);
                }

                _db.SubmitChanges();

                this.UserId = usr.UserId;

                //grab fresh copy from DB
                vw_carrot_UserData rc = CompiledQueries.cqFindUserByID(_db, usr.UserId);
                LoadUserData(rc);
            }
        }
예제 #19
0
        public void Save()
        {
            using (CarrotCMSDataContext _db = CarrotCMSDataContext.Create()) {
                bool bNew           = false;
                carrot_ContentTag s = CompiledQueries.cqGetContentTagByID(_db, this.ContentTagID);

                if (s == null || (s != null && s.ContentTagID == Guid.Empty))
                {
                    s = new carrot_ContentTag();
                    s.ContentTagID = Guid.NewGuid();
                    s.SiteID       = this.SiteID;
                    bNew           = true;
                }

                s.TagSlug  = ContentPageHelper.ScrubSlug(this.TagSlug);
                s.TagText  = this.TagText;
                s.IsPublic = this.IsPublic;

                if (bNew)
                {
                    _db.carrot_ContentTags.InsertOnSubmit(s);
                }

                _db.SubmitChanges();

                this.ContentTagID = s.ContentTagID;
            }
        }
예제 #20
0
 public static List <UserRole> GetRoleList()
 {
     using (CarrotCMSDataContext _db = CarrotCMSDataContext.Create()) {
         return((from r in _db.membership_Roles
                 orderby r.Name
                 select new UserRole(r)).ToList());
     }
 }
예제 #21
0
 public static IQueryable <ExtendedUserData> GetUsers()
 {
     using (CarrotCMSDataContext _db = CarrotCMSDataContext.Create()) {
         IQueryable <ExtendedUserData> lstUsr = (from u in CompiledQueries.cqGetUserList(_db)
                                                 select new ExtendedUserData(u));
         return(lstUsr);
     }
 }
예제 #22
0
 public static UserRole FindRole(string RoleName)
 {
     using (CarrotCMSDataContext _db = CarrotCMSDataContext.Create()) {
         return((from r in _db.membership_Roles
                 where r.Name.ToLower() == RoleName.ToLower()
                 select new UserRole(r)).FirstOrDefault());
     }
 }
예제 #23
0
 public static UserRole FindRoleByID(string roleID)
 {
     using (CarrotCMSDataContext _db = CarrotCMSDataContext.Create()) {
         return((from r in _db.membership_Roles
                 where r.Id == roleID
                 select new UserRole(r)).FirstOrDefault());
     }
 }
예제 #24
0
        public static int GetSimilar(Guid siteID, Guid rootSnippetID, string categorySlug)
        {
            using (CarrotCMSDataContext _db = CarrotCMSDataContext.Create()) {
                IQueryable <vw_carrot_ContentSnippet> query = CompiledQueries.cqGetContentSnippetNoMatch(_db, siteID, rootSnippetID, categorySlug);

                return(query.Count());
            }
        }
예제 #25
0
        public static int GetSimilar(Guid SiteID, Guid TagID, string tagSlug)
        {
            using (CarrotCMSDataContext _db = CarrotCMSDataContext.Create()) {
                IQueryable <carrot_ContentTag> query = CompiledQueries.cqGetContentTagNoMatch(_db, SiteID, TagID, tagSlug);

                return(query.Count());
            }
        }
예제 #26
0
        public List <ContentSnippet> GetContentSnippetList()
        {
            using (CarrotCMSDataContext _db = CarrotCMSDataContext.Create()) {
                List <ContentSnippet> _types = (from d in CompiledQueries.cqGetSnippetsBySiteID(_db, this.SiteID)
                                                select new ContentSnippet(d)).ToList();

                return(_types);
            }
        }
예제 #27
0
 public List <ExtendedUserData> GetMappedUsers()
 {
     using (CarrotCMSDataContext _db = CarrotCMSDataContext.Create()) {
         return((from l in _db.carrot_UserSiteMappings
                 join u in _db.vw_carrot_UserDatas on l.UserId equals u.UserId
                 where l.SiteID == this.SiteID
                 select new ExtendedUserData(u)).ToList());
     }
 }
예제 #28
0
        public static List <PostComment> GetCommentsByContentPage(Guid rootContentID, bool bActiveOnly)
        {
            using (CarrotCMSDataContext _db = CarrotCMSDataContext.Create()) {
                IQueryable <vw_carrot_Comment> lstComments = (from c in CannedQueries.GetContentPageComments(_db, rootContentID, bActiveOnly)
                                                              select c);

                return(lstComments.Select(x => new PostComment(x)).ToList());
            }
        }
예제 #29
0
        public static List <PostComment> GetAllCommentsBySite(Guid siteID)
        {
            using (CarrotCMSDataContext _db = CarrotCMSDataContext.Create()) {
                IQueryable <PostComment> s = (from c in CannedQueries.GetSiteContentComments(_db, siteID)
                                              select new PostComment(c));

                return(s.ToList());
            }
        }
예제 #30
0
 public List <SiteData> GetSiteList()
 {
     using (CarrotCMSDataContext _db = CarrotCMSDataContext.Create()) {
         return((from m in _db.carrot_UserSiteMappings
                 join s in _db.carrot_Sites on m.SiteID equals s.SiteID
                 where m.UserId == this.UserId
                 select new SiteData(s)).ToList());
     }
 }