public ContentHead SaveContent(ContentHead content) { ContentHead oldContent = GetContent(content.ContentUId); List <CrossLink> removedLinks = new List <CrossLink>(); List <CrossLink> addedLinks = content.CrossLinks.ToList(); if (oldContent == null) { _context.ContentHeads.Add(content); } else { _context.ContentHeads.Attach(oldContent); _context.Entry <ContentHead>(oldContent).CurrentValues.SetValues(content); _context.Entry <ContentData>(oldContent.Data).CurrentValues.SetValues(content.Data); if (oldContent.CustomInfo != null) { _context.Entry <ContentCustomInfo>(oldContent.CustomInfo).CurrentValues.SetValues(content.CustomInfo); } } ApplyCollectionValuesCrossLinks(oldContent != null ? oldContent.CrossLinks : null, content.CrossLinks); //_context.ApplyCollectionValues<CrossLink>(oldContent != null ? oldContent.CrossLinks : null, content.CrossLinks, (c1, c2) => { return c1.PageArea == c2.PageArea; }); _context.ApplyCollectionValues <ContentTag>(oldContent != null ? oldContent.Tags : null, content.Tags, (t1, t2) => { return(t1.Tag == t2.Tag); }); _context.SaveChanges(); _log.Log($"Content '{content.Name}' ({content.Kind}) was created/updated."); return(content); }
public ContentComment SaveComment(ContentComment comment) { using (var context = new Data.CMSContext()) { ContentComment oldComment = context.ContentComments.SingleOrDefault(c => c.CommentUId == comment.CommentUId); if (oldComment == null) { context.ContentComments.Add(comment); int? position = context.ContentComments.Where(c => c.ContentUId == comment.ContentUId).Max(c => (int?) c.Position); if (position == null) comment.Position = 0; else comment.Position = position.Value + 1; } else { context.ContentComments.Attach(oldComment); context.Entry<ContentComment>(oldComment).CurrentValues.SetValues(comment); } context.SaveChanges(); IncreaseCommentCount(comment); return comment; } }
public ContentComment SaveComment(ContentComment comment) { using (var context = new Data.CMSContext()) { ContentComment oldComment = context.ContentComments.SingleOrDefault(c => c.CommentUId == comment.CommentUId); if (oldComment == null) { context.ContentComments.Add(comment); int?position = context.ContentComments.Where(c => c.ContentUId == comment.ContentUId).Max(c => (int?)c.Position); if (position == null) { comment.Position = 0; } else { comment.Position = position.Value + 1; } } else { context.ContentComments.Attach(oldComment); context.Entry <ContentComment>(oldComment).CurrentValues.SetValues(comment); } context.SaveChanges(); IncreaseCommentCount(comment); return(comment); } }
public ContentHead SaveContent(ContentHead content) { using (var context = new Data.CMSContext()) { ContentHead oldContent = GetContent(content.ContentUId); List <CrossLink> removedLinks = new List <CrossLink>(); List <CrossLink> addedLinks = content.CrossLinks.ToList(); if (oldContent == null) { context.ContentHeads.Add(content); } else { context.ContentHeads.Attach(oldContent); context.Entry <ContentHead>(oldContent).CurrentValues.SetValues(content); context.Entry <ContentData>(oldContent.Data).CurrentValues.SetValues(content.Data); if (oldContent.CustomInfo != null) { context.Entry <ContentCustomInfo>(oldContent.CustomInfo).CurrentValues.SetValues(content.CustomInfo); } } //context.ApplyCollectionValues<CrossLink>(oldContent != null ? oldContent.CrossLinks : null, content.CrossLinks, (t1, t2) => { return t1.PageArea == t2.PageArea; }); ApplyCollectionValuesCrossLinks(oldContent != null ? oldContent.CrossLinks : null, content.CrossLinks); context.ApplyCollectionValues <ContentTag>(oldContent != null ? oldContent.Tags : null, content.Tags, (t1, t2) => { return(t1.Tag == t2.Tag); }); context.SaveChanges(); } return(content); }
private void IncreaseCommentCount(ContentComment comment) { using (var context = new Data.CMSContext()) { ContentCommentCount oldCount = context.ContentCommentCounts.SingleOrDefault(c => c.ContentUId == comment.ContentUId); if (oldCount == null) context.ContentCommentCounts.Add(new ContentCommentCount() { ContentUId = comment.ContentUId, Count = 1 }); else oldCount.Count++; context.SaveChanges(); } }
public void LogPageView(string contentUId) { ContentPageViewCount pageCount = _context.ContentPageViewCounts.SingleOrDefault(c => c.ContentUId == contentUId); if (pageCount == null) { _context.ContentPageViewCounts.Add(pageCount = new ContentPageViewCount() { ContentUId = contentUId, Count = 0 }); } else { _context.ContentPageViewCounts.Attach(pageCount); } pageCount.Count++; _context.SaveChanges(); }
public void RemoveContent(string contentUId) { using (var context = new Data.CMSContext()) { ContentHead content = context.ContentHeads.SingleOrDefault(c => c.ContentUId == contentUId); if (content == null) { return; } context.ContentHeads.Remove(content); context.SaveChanges(); } }
public void RemoveFile(string fileUId) { using (var context = new Data.CMSContext()) { File file = context.Files.SingleOrDefault(f => f.FileUId == fileUId); if (file == null) { return; } context.Files.Remove(file); context.SaveChanges(); } }
/// <summary> /// Adds a news crosslink for the contect at the given area. /// </summary> /// <param name="contentUId">The content Id</param> /// <param name="area">The crosslink area</param> /// <param name="changeDisplayOrderBy">Used to change the crosslink display order</param> /// <returns></returns> public void AddCrossLink(string contentUId, string area, short changeDisplayOrderBy = 0) { short oldOrder = 0; using (var context = new Data.CMSContext()) { // max crosslink order short maxOrder = -1; if (context.CrossLinks.Any(c => c.PageArea == area)) { maxOrder = context.CrossLinks.Where(c => c.PageArea == area).Select(c => c.DisplayOrder).DefaultIfEmpty().Max(); } CrossLink link = context.CrossLinks.SingleOrDefault(c => c.ContentUId == contentUId && c.PageArea == area); if (link == null) { link = new CrossLink() { ContentUId = contentUId, PageArea = area, DisplayOrder = (short)(maxOrder + 1) }; context.CrossLinks.Add(link); } // calcs the new crosslink order oldOrder = link.DisplayOrder; short order = (short)(link.DisplayOrder + changeDisplayOrderBy); // if is a order chage and it its ut of bounds, get out of here if (changeDisplayOrderBy < 0 && oldOrder == 0) { return; } if (changeDisplayOrderBy > 0 && oldOrder == maxOrder) { return; } // set the new order link.DisplayOrder = order; // change the other link display order CrossLink link2 = null; link2 = context.CrossLinks.SingleOrDefault(c => c.ContentUId != contentUId && c.PageArea == area && c.DisplayOrder == order); if (link2 != null) { link2.DisplayOrder = oldOrder; } context.SaveChanges(); } }
public void LogPageView(string contentUId) { using (var context = new Data.CMSContext()) { ContentPageViewCount pageCount = context.ContentPageViewCounts.SingleOrDefault(c => c.ContentUId == contentUId); if (pageCount == null) { context.ContentPageViewCounts.Add(pageCount = new ContentPageViewCount() { ContentUId = contentUId, Count = 0 }); } pageCount.Count++; context.SaveChanges(); } }
private void UpdateShareCount(string id, long count) { using (var context = new Data.CMSContext()) { ContentShareCount oldCount = context.ContentSharesCounts.SingleOrDefault(c => c.ContentUId == id); if (oldCount == null) { context.ContentSharesCounts.Add(new ContentShareCount() { ContentUId = id, Count = count }); } else { oldCount.Count = count; } context.SaveChanges(); } }
public void UpdateCommentCount(string id, int count) { using (var context = new Data.CMSContext()) { ContentCommentCount oldCount = context.ContentCommentCounts.SingleOrDefault(c => c.ContentUId == id); if (oldCount == null) { context.ContentCommentCounts.Add(new ContentCommentCount() { ContentUId = id, Count = count }); } else { oldCount.Count = count; } context.SaveChanges(); } }
private void IncreaseCommentCount(ContentComment comment) { using (var context = new Data.CMSContext()) { ContentCommentCount oldCount = context.ContentCommentCounts.SingleOrDefault(c => c.ContentUId == comment.ContentUId); if (oldCount == null) { context.ContentCommentCounts.Add(new ContentCommentCount() { ContentUId = comment.ContentUId, Count = 1 }); } else { oldCount.Count++; } context.SaveChanges(); } }
public void SaveFile(File file, FileStorages storage) { using (var context = new Data.CMSContext()) { file.Data.StoredData = EncryptFiles ? CryptUtil.EncryptBytes(file.Data.StoredData) : file.Data.StoredData; file.Data.StoredThumbData = EncryptFiles ? CryptUtil.EncryptBytes(file.Data.StoredThumbData) : file.Data.StoredThumbData; var oldfile = context.Files.SingleOrDefault(f => f.FileUId == file.FileUId); if (oldfile == null) { context.Files.Add(file); } else { context.Files.Remove(oldfile); context.Files.Add(file); } context.SaveChanges(); } }
public void RemoveCrossLink(string contentUId, string area) { using (var context = new Data.CMSContext()) { CrossLink link = context.CrossLinks.SingleOrDefault(c => c.ContentUId == contentUId && c.PageArea == area); if (link == null) { return; } int order = link.DisplayOrder; context.CrossLinks.Remove(link); context.SaveChanges(); // update orders context.Database.ExecuteSqlCommand( "UPDATE CrossLinks SET DisplayOrder = DisplayOrder - 1 WHERE PageArea = {0} AND DisplayOrder > {1}", area, order); } }
public void UpdateCommentCount(string id, int count) { using (var context = new Data.CMSContext()) { ContentCommentCount oldCount = context.ContentCommentCounts.SingleOrDefault(c => c.ContentUId == id); if (oldCount == null) context.ContentCommentCounts.Add(new ContentCommentCount() { ContentUId = id, Count = count }); else oldCount.Count = count; context.SaveChanges(); } }
public void RemoveContent(string contentUId) { using (var context = new Data.CMSContext()) { ContentHead content = context.ContentHeads.SingleOrDefault(c => c.ContentUId == contentUId); if (content == null) return; context.ContentHeads.Remove(content); context.SaveChanges(); } }
public ContentHead SaveContent(ContentHead content) { using (var context = new Data.CMSContext()) { ContentHead oldContent = GetContent(content.ContentUId); List<CrossLink> removedLinks = new List<CrossLink>(); List<CrossLink> addedLinks = content.CrossLinks.ToList(); if (oldContent == null) { context.ContentHeads.Add(content); } else { context.ContentHeads.Attach(oldContent); context.Entry<ContentHead>(oldContent).CurrentValues.SetValues(content); context.Entry<ContentData>(oldContent.Data).CurrentValues.SetValues(content.Data); if(oldContent.CustomInfo!=null) context.Entry<ContentCustomInfo>(oldContent.CustomInfo).CurrentValues.SetValues(content.CustomInfo); } //context.ApplyCollectionValues<CrossLink>(oldContent != null ? oldContent.CrossLinks : null, content.CrossLinks, (t1, t2) => { return t1.PageArea == t2.PageArea; }); ApplyCollectionValuesCrossLinks(oldContent != null ? oldContent.CrossLinks : null, content.CrossLinks); context.ApplyCollectionValues<ContentTag>(oldContent != null ? oldContent.Tags : null, content.Tags, (t1, t2) => { return t1.Tag == t2.Tag; }); context.SaveChanges(); } return content; }
public void RemoveFile(string fileUId) { using (var context = new Data.CMSContext()) { File file = context.Files.SingleOrDefault(f => f.FileUId == fileUId); if (file == null) return; context.Files.Remove(file); context.SaveChanges(); } }
public void LogPageView(string contentUId) { using (var context = new Data.CMSContext()) { ContentPageViewCount pageCount = context.ContentPageViewCounts.SingleOrDefault(c => c.ContentUId == contentUId); if (pageCount == null) context.ContentPageViewCounts.Add(pageCount = new ContentPageViewCount() { ContentUId = contentUId, Count = 0 }); pageCount.Count++; context.SaveChanges(); } }
/// <summary> /// Adds a news crosslink for the contect at the given area. /// </summary> /// <param name="contentUId">The content Id</param> /// <param name="area">The crosslink area</param> /// <param name="changeDisplayOrderBy">Used to change the crosslink display order</param> /// <returns></returns> public void AddCrossLink(string contentUId, string area, short changeDisplayOrderBy = 0) { short oldOrder = 0; using (var context = new Data.CMSContext()) { // max crosslink order short maxOrder = -1; if (context.CrossLinks.Any(c => c.PageArea == area)) { maxOrder = context.CrossLinks.Where(c => c.PageArea == area).Select(c => c.DisplayOrder).DefaultIfEmpty().Max(); } CrossLink link = context.CrossLinks.SingleOrDefault(c => c.ContentUId == contentUId && c.PageArea == area); if (link==null) { link = new CrossLink() { ContentUId = contentUId, PageArea = area, DisplayOrder = (short)(maxOrder + 1) }; context.CrossLinks.Add(link); } // calcs the new crosslink order oldOrder = link.DisplayOrder; short order = (short)(link.DisplayOrder + changeDisplayOrderBy); // if is a order chage and it its ut of bounds, get out of here if (changeDisplayOrderBy < 0 && oldOrder == 0) return; if (changeDisplayOrderBy > 0 && oldOrder == maxOrder) return; // set the new order link.DisplayOrder = order; // change the other link display order CrossLink link2 = null; link2 = context.CrossLinks.SingleOrDefault(c => c.ContentUId != contentUId && c.PageArea == area && c.DisplayOrder == order); if (link2!=null) link2.DisplayOrder = oldOrder; context.SaveChanges(); } }
public void RemoveCrossLink(string contentUId, string area) { using (var context = new Data.CMSContext()) { CrossLink link = context.CrossLinks.SingleOrDefault(c => c.ContentUId == contentUId && c.PageArea == area); if (link == null) return; int order = link.DisplayOrder; context.CrossLinks.Remove(link); context.SaveChanges(); // update orders context.Database.ExecuteSqlCommand( "UPDATE CrossLinks SET DisplayOrder = DisplayOrder - 1 WHERE PageArea = {0} AND DisplayOrder > {1}", area, order); } }
private void UpdateShareCount(string id, long count) { using (var context = new Data.CMSContext()) { ContentShareCount oldCount = context.ContentSharesCounts.SingleOrDefault(c => c.ContentUId == id); if (oldCount == null) context.ContentSharesCounts.Add(new ContentShareCount() { ContentUId = id, Count = count }); else oldCount.Count = count; context.SaveChanges(); } }