Exemplo n.º 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));
        }
Exemplo n.º 2
0
        public SubmissionModel Insert(string currentUsername, SubmissionModel input)
        {
            var user = _usersService.GetByUsername(currentUsername);

            var entity = _mapper.Map <SubmissionModel, Submission>(input, opt => opt.AfterMap((src, dest) =>
            {
                dest.CreatedAtUtc  = DateTime.UtcNow;
                dest.UserId        = user.UserId;
                dest.CreatedAtUtc  = DateTime.UtcNow;
                dest.CreatedBy     = user.UserId;
                dest.ModifiedAtUtc = DateTime.UtcNow;
                dest.ModifiedBy    = user.UserId;
                dest.VotingBox     = new VotingBox();
            }));

            _dbContext.Submissions.Add(entity);
            _dbContext.SaveChanges();

            // automatic upvote from the creator of the thread
            _upvotesService.Vote(currentUsername, entity.Id, this, false);

            return(_mapper.Map <SubmissionModel>(entity));
        }
        public ActionResult Upvote(string id)
        {
            _upvotesService.Vote(this.CurrentUsername, id, _service, false);

            return(Ok());
        }