private static PostCommentSmall projectPostCommentSmall(oxite_Comment comment, oxite_Blogs_PostCommentRelationship pcr, oxite_User user)
 {
     if (user.Username != "Anonymous")
     {
         return(new PostCommentSmall(new CommentSmall(comment.CommentID, comment.CreatedDate, getUserAuthenticated(comment, user)), pcr.Slug));
     }
     else
     {
         return(new PostCommentSmall(new CommentSmall(comment.CommentID, comment.CreatedDate, getUserAnonymous(comment, user)), pcr.Slug));
     }
 }
Exemple #2
0
 private static ScheduleItemCommentSmall projectScheduleItemCommentSmall(oxite_Comment comment, oxite_Conferences_ScheduleItemCommentRelationship sicr, oxite_User user)
 {
     if (user.Username != "Anonymous")
     {
         return(new ScheduleItemCommentSmall(new CommentSmall(comment.CommentID, comment.CreatedDate, getUserAuthenticated(comment, user)), sicr.Slug));
     }
     else
     {
         return(new ScheduleItemCommentSmall(new CommentSmall(comment.CommentID, comment.CreatedDate, getUserAnonymous(comment, user)), sicr.Slug));
     }
 }
Exemple #3
0
        private ScheduleItemComment projectComment(oxite_Comment comment, oxite_Conferences_ScheduleItemCommentRelationship sicr, oxite_Conferences_ScheduleItem si, oxite_Conferences_Event e, oxite_User user)
        {
            ScheduleItemCommentSmall parent = comment.ParentCommentID != comment.CommentID ? getParentComment(comment.ParentCommentID) : null;
            Language language = new Language(comment.oxite_Language.LanguageID)
            {
                DisplayName = comment.oxite_Language.LanguageDisplayName,
                Name        = comment.oxite_Language.LanguageName
            };

            if (user.Username != "Anonymous")
            {
                return(new ScheduleItemComment(comment.Body, comment.CreatedDate, getUserAuthenticated(comment, user), comment.CreatorIP, comment.UserAgent, comment.CommentID, language, comment.ModifiedDate, parent, new ScheduleItemSmall(si.ScheduleItemID, e.EventName, si.Slug, si.Title), sicr.Slug, (EntityState)comment.State));
            }
            else
            {
                return(new ScheduleItemComment(comment.Body, comment.CreatedDate, getUserAnonymous(comment, user), comment.CreatorIP, comment.UserAgent, comment.CommentID, language, comment.ModifiedDate, parent, new ScheduleItemSmall(si.ScheduleItemID, e.EventName, si.Slug, si.Title), sicr.Slug, (EntityState)comment.State));
            }
        }
        private PostComment projectComment(oxite_Comment comment, oxite_Blogs_PostCommentRelationship pcr, oxite_Blogs_Post p, oxite_Blogs_Blog b, oxite_User user)
        {
            PostCommentSmall parent   = comment.ParentCommentID != comment.CommentID ? getParentComment(comment.ParentCommentID) : null;
            Language         language = new Language(comment.oxite_Language.LanguageID)
            {
                DisplayName = comment.oxite_Language.LanguageDisplayName,
                Name        = comment.oxite_Language.LanguageName
            };

            if (user.Username != "Anonymous")
            {
                return(new PostComment(comment.Body, comment.CreatedDate, getUserAuthenticated(comment, user), comment.CreatorIP, comment.UserAgent, comment.CommentID, language, comment.ModifiedDate, parent, new PostSmall(p.PostID, b.BlogName, p.Slug, p.Title), pcr.Slug, (EntityState)comment.State));
            }
            else
            {
                return(new PostComment(comment.Body, comment.CreatedDate, getUserAnonymous(comment, user), comment.CreatorIP, comment.UserAgent, comment.CommentID, language, comment.ModifiedDate, parent, new PostSmall(p.PostID, b.BlogName, p.Slug, p.Title), pcr.Slug, (EntityState)comment.State));
            }
        }
 private static Comment getComment(oxite_Comment comment, UserBase user)
 {
     return(new Comment
     {
         Body = comment.Body,
         Created = comment.CreatedDate,
         Creator = user,
         CreatorIP = comment.CreatorIP,
         CreatorUserAgent = comment.UserAgent,
         ID = comment.CommentID,
         Language = new Language
         {
             DisplayName = comment.oxite_Language.LanguageDisplayName,
             ID = comment.oxite_Language.LanguageID,
             Name = comment.oxite_Language.LanguageName
         },
         Modified = comment.ModifiedDate,
         State = (EntityState)comment.State
     });
 }
Exemple #6
0
        public ScheduleItemComment Save(ScheduleItemComment comment)
        {
            oxite_Comment commentToSave = null;

            if (comment.ID != Guid.Empty)
            {
                commentToSave = context.oxite_Comments.FirstOrDefault(c => c.CommentID == comment.ID);
            }

            if (commentToSave == null)
            {
                commentToSave = new oxite_Comment();

                commentToSave.CommentID   = comment.ID != Guid.Empty ? comment.ID : Guid.NewGuid();
                commentToSave.CreatedDate = commentToSave.ModifiedDate = DateTime.UtcNow;

                context.oxite_Comments.InsertOnSubmit(commentToSave);
            }
            else
            {
                commentToSave.ModifiedDate = DateTime.UtcNow;
            }

            oxite_Conferences_ScheduleItem scheduleItem = (from si in context.oxite_Conferences_ScheduleItems join e in context.oxite_Conferences_Events on si.EventID equals e.EventID where /*e.SiteID == siteID && */ string.Compare(e.EventName, comment.ScheduleItem.EventName, true) == 0 && string.Compare(si.Slug, comment.ScheduleItem.Slug, true) == 0 select si).FirstOrDefault();

            if (scheduleItem == null)
            {
                throw new InvalidOperationException(string.Format("ScheduleItem in Event {0} at slug {1} could not be found to add the comment to", comment.ScheduleItem.EventName, comment.ScheduleItem.Slug));
            }
            context.oxite_Conferences_ScheduleItemCommentRelationships.InsertOnSubmit(
                new oxite_Conferences_ScheduleItemCommentRelationship
            {
                CommentID      = commentToSave.CommentID,
                ScheduleItemID = scheduleItem.ScheduleItemID,
                Slug           = comment.Slug
            }
                );

            commentToSave.ParentCommentID = comment.Parent != null && comment.Parent.ID != Guid.Empty ? comment.Parent.ID : commentToSave.CommentID;
            commentToSave.Body            = comment.Body;
            commentToSave.CreatorIP       = comment.CreatorIP;
            commentToSave.State           = (byte)comment.State;
            commentToSave.UserAgent       = comment.CreatorUserAgent;
            commentToSave.oxite_Language  = context.oxite_Languages.Where(l => l.LanguageName == comment.Language.Name).FirstOrDefault();

            if (comment.CreatorUserID != Guid.Empty)
            {
                commentToSave.CreatorUserID = comment.CreatorUserID;
            }
            else
            {
                oxite_User anonymousUser = context.oxite_Users.FirstOrDefault(u => u.Username == "Anonymous");
                if (anonymousUser == null)
                {
                    throw new InvalidOperationException("Could not find anonymous user");
                }
                commentToSave.CreatorUserID = anonymousUser.UserID;

                commentToSave.CreatorName        = comment.CreatorName;
                commentToSave.CreatorEmail       = comment.CreatorEmail;
                commentToSave.CreatorHashedEmail = comment.CreatorEmailHash;
                commentToSave.CreatorUrl         = comment.CreatorUrl;
            }

            context.SubmitChanges();

            return((
                       from c in context.oxite_Comments
                       join sicr in context.oxite_Conferences_ScheduleItemCommentRelationships on c.CommentID equals sicr.CommentID
                       join si in context.oxite_Conferences_ScheduleItems on sicr.ScheduleItemID equals si.ScheduleItemID
                       join e in context.oxite_Conferences_Events on si.EventID equals e.EventID
                       join u in context.oxite_Users on c.CreatorUserID equals u.UserID
                       where /*e.SiteID == siteID && */ string.Compare(e.EventName, comment.ScheduleItem.EventName, true) == 0 && string.Compare(si.Slug, scheduleItem.Slug, true) == 0 && string.Compare(sicr.Slug, comment.Slug, true) == 0
                       select projectComment(c, sicr, si, e, u)
                       ).FirstOrDefault());
        }
Exemple #7
0
 private static UserAnonymous getUserAnonymous(oxite_Comment comment, oxite_User user)
 {
     return(new UserAnonymous(comment.CreatorName, comment.CreatorEmail, comment.CreatorHashedEmail, comment.CreatorUrl));
 }
Exemple #8
0
 private static User getUserAuthenticated(oxite_Comment comment, oxite_User user)
 {
     return(new User(user.UserID, user.Username, user.DisplayName, user.Email, user.HashedEmail, (EntityState)user.Status));
 }
        public void SaveComment(Post post, Comment comment)
        {
            oxite_Comment persistenceComment = null;
            Guid          commentID          = comment.ID;

            if (comment.ID != Guid.Empty)
            {
                persistenceComment = context.oxite_Comments.Where(c => c.CommentID == comment.ID).FirstOrDefault();
            }

            if (persistenceComment == null)
            {
                if (commentID == Guid.Empty)
                {
                    commentID = Guid.NewGuid();
                }

                persistenceComment = new oxite_Comment {
                    CommentID = commentID
                };

                context.oxite_Comments.InsertOnSubmit(persistenceComment);
            }

            persistenceComment.PostID         = post.ID;
            persistenceComment.Body           = comment.Body;
            persistenceComment.CreatedDate    = comment.Created ?? DateTime.UtcNow;
            persistenceComment.CreatorIP      = comment.CreatorIP;
            persistenceComment.ModifiedDate   = DateTime.UtcNow;
            persistenceComment.State          = (byte)comment.State;
            persistenceComment.UserAgent      = comment.CreatorUserAgent;
            persistenceComment.oxite_Language = context.oxite_Languages.Where(l => l.LanguageName == comment.Language.Name).FirstOrDefault();

            if (comment.Creator is User)
            {
                oxite_User persistenceUser = context.oxite_Users.Where(u => u.Username.ToLower() == comment.Creator.Name.ToLower()).FirstOrDefault();

                if (persistenceUser == null)
                {
                    throw new InvalidOperationException(string.Format("User {0} could not be found", comment.Creator.Name));
                }

                persistenceComment.oxite_User = persistenceUser;
            }
            else
            {
                oxite_User anonymousUser = context.oxite_Users.Where(u => u.Username == "Anonymous").FirstOrDefault();

                if (anonymousUser == null)
                {
                    throw new InvalidOperationException("Could not find anonymous user");
                }

                if (persistenceComment.oxite_CommentAnonymous == null)
                {
                    persistenceComment.oxite_CommentAnonymous = new oxite_CommentAnonymous();
                }

                persistenceComment.oxite_CommentAnonymous.Email       = comment.Creator.Email;
                persistenceComment.oxite_CommentAnonymous.HashedEmail = comment.Creator.HashedEmail;
                persistenceComment.oxite_CommentAnonymous.Name        = comment.Creator.Name;
                persistenceComment.oxite_CommentAnonymous.Url         = comment.Creator.Url;
                persistenceComment.oxite_User = anonymousUser;
            }

            context.SubmitChanges();

            comment.ID      = commentID;
            comment.Created = persistenceComment.CreatedDate;
        }
        public PostComment Save(PostComment comment, Guid siteID, string blogName, string postSlug)
        {
            oxite_Comment commentToSave = null;

            if (comment.ID != Guid.Empty)
            {
                commentToSave = context.oxite_Comments.FirstOrDefault(c => c.CommentID == comment.ID);
            }

            if (commentToSave == null)
            {
                commentToSave = new oxite_Comment();

                commentToSave.CommentID   = comment.ID != Guid.Empty ? comment.ID : Guid.NewGuid();
                commentToSave.CreatedDate = commentToSave.ModifiedDate = DateTime.UtcNow;

                context.oxite_Comments.InsertOnSubmit(commentToSave);
            }
            else
            {
                commentToSave.ModifiedDate = DateTime.UtcNow;
            }

            oxite_Blogs_Post post = (from p in context.oxite_Blogs_Posts join b in context.oxite_Blogs_Blogs on p.BlogID equals b.BlogID where b.SiteID == siteID && string.Compare(b.BlogName, blogName, true) == 0 && string.Compare(p.Slug, postSlug, true) == 0 select p).FirstOrDefault();

            if (post == null)
            {
                throw new InvalidOperationException(string.Format("Post in blog {0} at slug {1} could not be found to add the comment to", blogName, postSlug));
            }
            context.oxite_Blogs_PostCommentRelationships.InsertOnSubmit(
                new oxite_Blogs_PostCommentRelationship
            {
                CommentID = commentToSave.CommentID,
                PostID    = post.PostID,
                Slug      = comment.Slug
            }
                );

            commentToSave.ParentCommentID = comment.Parent != null && comment.Parent.ID != Guid.Empty ? comment.Parent.ID : commentToSave.CommentID;
            commentToSave.Body            = comment.Body;
            commentToSave.CreatorIP       = comment.CreatorIP;
            commentToSave.State           = (byte)comment.State;
            commentToSave.UserAgent       = comment.CreatorUserAgent;
            commentToSave.oxite_Language  = context.oxite_Languages.Where(l => l.LanguageName == comment.Language.Name).FirstOrDefault();

            if (comment.CreatorUserID != Guid.Empty)
            {
                commentToSave.CreatorUserID = comment.CreatorUserID;
            }
            else
            {
                oxite_User anonymousUser = context.oxite_Users.FirstOrDefault(u => u.Username == "Anonymous");
                if (anonymousUser == null)
                {
                    throw new InvalidOperationException("Could not find anonymous user");
                }
                commentToSave.CreatorUserID = anonymousUser.UserID;

                commentToSave.CreatorName        = comment.CreatorName;
                commentToSave.CreatorEmail       = comment.CreatorEmail;
                commentToSave.CreatorHashedEmail = comment.CreatorEmailHash;
                commentToSave.CreatorUrl         = comment.CreatorUrl;
            }

            context.SubmitChanges();

            return((
                       from c in context.oxite_Comments
                       join pcr in context.oxite_Blogs_PostCommentRelationships on c.CommentID equals pcr.CommentID
                       join p in context.oxite_Blogs_Posts on pcr.PostID equals p.PostID
                       join b in context.oxite_Blogs_Blogs on p.BlogID equals b.BlogID
                       join u in context.oxite_Users on c.CreatorUserID equals u.UserID
                       where b.SiteID == siteID && string.Compare(b.BlogName, blogName, true) == 0 && string.Compare(p.Slug, postSlug, true) == 0 && string.Compare(pcr.Slug, comment.Slug, true) == 0
                       select projectComment(c, pcr, p, b, u)
                       ).FirstOrDefault());
        }