示例#1
0
        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);
        }
示例#2
0
        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}"));
            }
        }
示例#3
0
        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}"));
            }
        }