Пример #1
0
        public async Task <bool> Handle(RegisterUserCommand request, CancellationToken cancellationToken)
        {
            try
            {
                var user = new User()
                {
                    Id           = Guid.NewGuid(),
                    Email        = request.Email,
                    FirstName    = request.FirstName,
                    LastName     = request.LastName,
                    PasswordHash = request.PasswordHash,
                    RoleId       = request.RoleId
                };

                await _dbContext.AddAsync(user);

                await _dbContext.SaveChangesAsync();

                return(true);
            }
            catch (Exception e)
            {
                Log.Error(e, $"Error has occured durin registration user: {request.Email}");
                return(false);
            }
        }
        public async Task <int> Handle(UpdateCurrentRefreshTokensCommand request, CancellationToken cancellationToken)
        {
            var dbTokens = await _dbContext.RefreshTokens.Where(r => r.UserId.Equals(request.UserId)).ToArrayAsync();

            _dbContext.RefreshTokens.RemoveRange(dbTokens);
            await _dbContext.SaveChangesAsync();

            await _dbContext.AddAsync(_mapper.Map <RefreshToken>(request.NewRefreshToken), cancellationToken);

            return(await _dbContext.SaveChangesAsync(cancellationToken));
        }
Пример #3
0
        public async Task <int> Handle(AddCommentCommand request, CancellationToken cancellationToken)
        {
            try
            {
                var comment = new Comment()
                {
                    Id         = request.Id,
                    CreateDate = DateTime.Now,
                    NewsId     = request.NewsId,
                    Text       = request.Text,
                    UserId     = request.UserId
                };

                await _dbContext.AddAsync(comment);

                return(await _dbContext.SaveChangesAsync());
            }
            catch (Exception e)
            {
                Log.Error(e, $"Error has occured durin comment insertion newsId: " +
                          $"{request.NewsId}, userId: {request.UserId}, text: {request.Text}");
                return(0);
            }
        }