Ejemplo n.º 1
0
        public async Task <TResponse> Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate <TResponse> next)
        {
            using (var transaction = _context.BeginTransaction())
            {
                var result = await next();

                await _context.SaveChangesAsync();

                await transaction.CommitAsync();

                return(result);
            }
        }
Ejemplo n.º 2
0
        public async Task <UserInfo> Register(RegisterInfo registerInfo)
        {
            var user = await _context.Users.FirstOrDefaultAsync(x => x.UserSettingInfo.Login == registerInfo.Login);

            if (user != null)
            {
                throw new UserAlreadyExistException();
            }

            PasswordHelper.CreatePasswordHash(registerInfo.Password, out var hash, out var salt);

            var settingInfo = new UserSettingInfo()
            {
                Login        = registerInfo.Login,
                PasswordHash = hash,
                PasswordSalt = salt,
            };

            var newUser = UserInfo.Create(
                registerInfo.FirstName,
                registerInfo.LastName,
                Domain.Enums.Role.User,
                settingInfo);

            using var transaction = _context.BeginTransaction();

            try
            {
                var entity = _context.Users.Add(newUser);
                await _context.SaveChangesAsync();

                await transaction.CommitAsync();

                return(entity.Entity);
            }
            catch (Exception e)
            {
                await transaction.RollbackAsync();

                throw e;
            }
        }