Пример #1
0
        public CommentModel Insert(string currentUsername, CommentModel input)
        {
            UserModel user = _usersService.GetByUsername(currentUsername);

            var entity = _mapper.Map <CommentModel, Comment>(input, opt => opt.AfterMap((src, dest) =>
            {
                dest.VotingBox = new VotingBox();
            }));

            _dbContext.Comments.Add(entity);
            _dbContext.SaveChanges();
            _dbContext.Entry(entity).Reference(c => c.User).Load();

            // automatic upvote from the poster
            _upvotesService.Vote(user.Username, entity.Id, this, false);

            _dbContext.Entry(entity.VotingBox).Collection(c => c.Upvotes).Load();

            return(MapToDto(currentUsername)(entity));
        }