public async Task RegisterAsync(Guid userId) { var user = await _userRepository.GetUserOrFailAsync(userId); var investor = await _investorRepository.GetAsync(userId); if (investor != null) { throw new InvestorExistsSerExc( $"Investor with user id {userId} already exists."); } investor = new Investor(user); await _investorRepository.AddAsync(investor); }
public async Task <SaveInvestorResponse> SaveAsync(Investor investor) { try { await _investorRepository.AddAsync(investor); await _unitOfWork.CompleteAsync(); return(new SaveInvestorResponse(investor)); } catch (Exception ex) { return(new SaveInvestorResponse($"Um erro ocorreu durante a criação do investidor: {ex.Message}")); } }
public async Task <InvestorResponse> SaveAsync(int userId, Investor investor) { var existingUser = await userRepository.FindById(userId); if (existingUser == null) { return(new InvestorResponse("User not found")); } try { investor.UserId = userId; await investorRepository.AddAsync(investor); await unitOfWork.CompleteAsync(); return(new InvestorResponse(investor)); } catch (Exception ex) { return(new InvestorResponse($"An error ocurred while saving the investor: {ex.Message}")); } }