private static ScheduleItem projectScheduleItem(oxite_Conferences_ScheduleItem si) { if (si == null) { return(null); } if (si.PublishedDate.HasValue && si.PublishedDate.Value.ToUniversalTime() > DateTime.UtcNow) { return(null); } return(new ScheduleItem( null, si.ScheduleItemID, si.Title, si.Body, si.Location, si.Code, si.Type, si.StartTime, si.EndTime, si.Slug, Enumerable.Empty <Speaker>(), si.oxite_Conferences_ScheduleItemTagRelationships.Select(sitr => new ScheduleItemTag(sitr.TagID, sitr.TagDisplayName)).ToList(), Enumerable.Empty <ScheduleItemComment>(), Enumerable.Empty <ScheduleItemUser>(), si.CreatedDate, si.ModifiedDate, si.PublishedDate, Enumerable.Empty <File>() )); }
private static ScheduleItem projectScheduleItem(oxite_Conferences_ScheduleItem si) { return(new ScheduleItem( null, si.ScheduleItemID, si.Title, si.Body, si.Location, si.Code, si.Type, si.StartTime, si.EndTime, si.Slug, Enumerable.Empty <Speaker>(), si.oxite_Conferences_ScheduleItemTagRelationships.Select(sitr => new ScheduleItemTag(sitr.TagID, sitr.TagDisplayName)).ToList(), Enumerable.Empty <ScheduleItemComment>(), si.CreatedDate, si.ModifiedDate )); }
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()); }
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)); } }