public async Task <ApiResponse <Result> > Handle(Command request, CancellationToken cancellationToken) { AppUser user; if (!await userService.UserExists(request.Email)) { var resultr = await userService.CreateMinimunUser(userName : request.Email, password : request.Password); if (!resultr.Succeeded) { return(ApiResponse <Result> .FailureFrom(resultr.Errors.Select(c => c.Description))); } } else { return(ApiResponse <Result> .FailureFrom("User already exists, retrive your access code by sending email to [email protected]")); } user = await userService.GetUser(request.Email); string token = await userService.GenerateToken(userName : request.Email); var result = new Result() { Authenticated = true, AccessToken = token, UserId = user.Id, Message = "OK", }; return(ApiResponse <Result> .SuccessFrom(result)); }
public async Task <ApiResponse <Result> > Handle(Command request, CancellationToken cancellationToken) { var identityResult = await authUser.CreateMinimunUser(request.Email, request.Password); if (!identityResult.Succeeded) { return(ApiResponse <Result> .FailureFrom(identityResult.Errors.Select(c => c.Description))); } var newUser = await authUser.GetUser(request.Email); var token = await authUser.GenerateToken(request.Email); var ong = mapper.Map <Domain.Ong>(request); string newId = generateIdService.GenerateId(); ong.Id = newId; ong.Owner = newUser; heroContext.Ongs.Add(ong); return(ApiResponse <Result> .SuccessFrom(new Result() { UserId = newUser.Id, AccessToken = token })); }