Ejemplo n.º 1
0
        public void CreateComment(string content, Comment parentComment, User user, Thread thread)
        {
            var entityComment = _mapper.Map <DAL.Entities.Comment>(parentComment);
            var entityUser    = _mapper.Map <DAL.Entities.User>(user) ?? throw new Exception("User cannot be null");
            var entityThread  = _mapper.Map <DAL.Entities.Thread>(thread) ?? throw new Exception("Thread cannot be null");

            var newComment = new DAL.Entities.Comment()
            {
                Thread   = entityThread,
                User     = entityUser,
                Content  = content,
                Parent   = entityComment,
                Created  = DateTime.Now,
                Modified = DateTime.Now,
                Votes    = new List <CommentVote>()
            };

            _context.Comments.Add(newComment);

            var comment = new DAL.Entities.CommentVote()
            {
                VoteScore = 1,
                VoteBy    = entityUser
            };

            newComment.Votes.Add(comment);

            _context.SaveChanges();
        }
Ejemplo n.º 2
0
        public void EditThread(Thread thread)
        {
            var entityThread = _context.Threads.Find(thread.ThreadId);

            if (entityThread == null)
            {
                return;
            }

            entityThread.Title    = thread.Title;
            entityThread.Content  = thread.Content;
            entityThread.Modified = DateTime.Now;

            _context.Threads.Update(entityThread);
            _context.SaveChanges();
        }
Ejemplo n.º 3
0
        public int CreateThread(Thread thread)
        {
            var entityThread = _mapper.Map <DAL.Entities.Thread>(thread);

            entityThread.Created  = DateTime.Now;
            entityThread.Modified = DateTime.Now;

            var threadVote = new ThreadVote()
            {
                VoteBy    = entityThread.User,
                VoteScore = 1
            };

            entityThread.Votes.Add(threadVote);

            _context.Threads.Add(entityThread);
            _context.SaveChanges();

            return(entityThread.ThreadId);
        }