示例#1
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);
        }
示例#2
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);
        }
示例#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 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;
            }
        }
示例#5
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;
        }