Beispiel #1
0
        public async Task <Maybe <RegisteredUserResponse> > Register(RegisterUserRequest user)
        {
            var isUserExist = await _finder.FindByEmail(user.Email);

            if (isUserExist.HasError)
            {
                var createdUser = await _writer.SaveAsync(new User
                {
                    Id    = Guid.NewGuid(),
                    Email = user.Email,
                });

                return(new Maybe <RegisteredUserResponse>(new RegisteredUserResponse
                {
                    Id = createdUser.Id,
                    Email = createdUser.Email,
                }));
            }

            return(new Maybe <RegisteredUserResponse>("User with specified email already exists."));
        }
Beispiel #2
0
 public async Task <IdentityResult> Create(User user, string password)
 {
     if (user != null)
     {
         var userFound = _userFinder.FindByEmail(user.Email);
         if (userFound == null)
         {
             userFound = new User {
                 Email = user.Email, UserName = user.Email
             };
             try
             {
                 _userRepository.Create(userFound, password);
                 await Database.SaveAsync();
             }
             catch (Exception ex)
             {
                 return(IdentityResult.Failed(ex.Message));
             }
             return(IdentityResult.Success);
         }
     }
     return(IdentityResult.Failed("Found user"));
 }