예제 #1
0
        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);
        }
예제 #2
0
        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;
            }
        }
예제 #3
0
        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);
            }
        }
예제 #4
0
        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);
        }
예제 #5
0
 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();
     }
 }
예제 #6
0
        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();
        }
예제 #7
0
 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();
     }
 }
예제 #8
0
 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();
            }
        }
예제 #10
0
        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();
            }
        }
예제 #11
0
 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();
     }
 }
예제 #12
0
 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();
     }
 }
예제 #13
0
 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();
     }
 }
예제 #14
0
        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);
            }
        }
예제 #16
0
 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();
     }
 }
예제 #17
0
 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();
     }
 }
예제 #18
0
        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;
        }
예제 #19
0
 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();
     }
 }
예제 #20
0
        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();
            }
        }
예제 #21
0
        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();
            }
        }
예제 #22
0
        /// <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();

            }
        }
예제 #23
0
        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);

            }
        }
예제 #24
0
 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();
     }
 }