Esempio n. 1
0
        public void AddArticle(Article article)
        {
            var user = GetCurrentUser();

            article.InsertDate = DateTime.Now;
            article.InsertUser = user.UserName;
            article.AddedDate  = DateTime.Now;
            article.UserId     = user.Id;
            _context.Articles.Add(article);
            _context.SaveChanges();
            _logger.LogEvent(article.GetType().Name, article.Id, "Add");
        }
        public ArticleComment DeleteComment(int id)
        {
            var comment  = _context.ArticleComments.Find(id);
            var children = _context.ArticleComments.Where(c => c.ParentId == id).ToList();

            foreach (var child in children)
            {
                child.IsDeleted             = true;
                _context.Entry(child).State = EntityState.Modified;
                _context.SaveChanges();
            }
            comment.IsDeleted             = true;
            _context.Entry(comment).State = EntityState.Modified;
            _context.SaveChanges();
            _logger.LogEvent(comment.GetType().Name, comment.Id, "Delete");
            return(comment);
        }