public async Task <RegistrationConfirmationResult> Handle( ConfirmAccountRegistration request, CancellationToken cancellationToken ) { var result = new RegistrationConfirmationResult(); var user = (from u in _context.Users where u.Id.Equals(request.UserId) select u) .FirstOrDefault(); if (user == null) { result.Result = RegistrationConfirmationEnum.BadConfirmation; } if (user.EmailConfirmed) { result.Result = RegistrationConfirmationEnum.AlreadyConfirmed; } else { result.Result = RegistrationConfirmationEnum.ConfirmationSuccesfull; user.EmailConfirmed = true; _context.Users.Update(user); await _context.SaveChangesAsync(cancellationToken); } if (!request.ConfirmationToken.Equals(request.UserId)) { result.Result = RegistrationConfirmationEnum.BadConfirmation; } return(result); }
public async Task <VoteDTO> Handle( VoteForPost request, CancellationToken cancellationToken ) { var currentVote = (from v in _context.Votes where v.PostId == request.PostId select v) .FirstOrDefault(); var post = _context.Posts.FirstOrDefault(x => x.Id == request.PostId); if (currentVote == null) { var newVote = new Infrastructure.Models.Vote() { PostId = request.PostId, UserId = (Guid)request.UserId, Up = request.Up, CreationDate = DateTime.Now }; _context.Votes.Add(newVote); post.CurrentRating += request.Up ? 1 : -1; } else { if (currentVote.Up == request.Up) { _context.Votes.Remove(currentVote); post.CurrentRating += currentVote.Up ? -1 : 1; } else { currentVote.Up = request.Up; _context.Votes.Update(currentVote); post.CurrentRating += currentVote.Up ? 2 : -2; } } _context.Posts.Update(post); await _context.SaveChangesAsync(cancellationToken); var dto = _mapper.Map <Infrastructure.Models.Vote, VoteDTO>(currentVote); return(dto); }
public async Task <PostDTO> Handle( CreateNewPost request, CancellationToken cancellationToken) { var post = new Infrastructure.Models.Post() { Name = request.Name, Content = request.Content, CommunityId = request.CommunityId, CreationDate = DateTime.Now, CreatorUserId = (Guid)request.UserId }; _context.Posts.Add(post); await _context.SaveChangesAsync(cancellationToken); AddTagsToPost(request.Tags, post.Id); return(_mapper.Map <Infrastructure.Models.Post, PostDTO>(post)); }
public async Task <CommentDTO> Handle( CreateNewComment request, CancellationToken cancellationToken ) { var newComment = new Infrastructure.Models.Comment() { Content = request.Content, ParentRepliedCommentId = request.ParentRepliedCommentId, PostId = request.PostId, UserId = (Guid)request.UserId, CreationDate = DateTime.Now }; _context.Comments.Add(newComment); await _context.SaveChangesAsync(cancellationToken); var dto = _mapper.Map <Infrastructure.Models.Comment, CommentDTO>(newComment); return(dto); }