Example #1
0
        public async Task HandleAsync(CreateUserCommand command)
        {
            var user = await _userRepository.GetUserByEmailAsync(command.Email);

            if (user != null)
            {
                throw new StocqresException($"User with mail {command.Email} currently exist");
            }
            user = new Domain.User(command.UserId, command.Username, command.Email);
            user.SetPassword(command.Password, _passwordHasher);
            await _userRepository.CreateAsync(user);

            await _userRepository.SaveAsync();
        }
Example #2
0
            public async Task <Domain.User> Save(Model model)
            {
                if (await db.Users.SingleOrDefaultAsync(s => s.Email == model.Email) != null)
                {
                    throw new HttpException(400, "Email já cadastrado");
                }

                var user = new Domain.User
                {
                    Name     = model.Name,
                    LastName = model.LastName,
                    Email    = model.Email
                };

                user.SetPassword(model.Password);

                db.Users.Add(user);

                await db.SaveChangesAsync();

                return(new Domain.User {
                    Id = user.Id, Name = user.Name, LastName = user.LastName, Email = user.Email
                });
            }