コード例 #1
0
        public void CreateNewInvestment(long projectId, InvestmentDto investmentDto)
        {
            var  id     = User.FindFirstValue(ClaimTypes.NameIdentifier);
            long userId = Int64.Parse(id);

            investmentService.CreateNew(userId, projectId, investmentDto);
        }
コード例 #2
0
        public static Investment Map(User user, Project project, InvestmentDto investmentDto)
        {
            Investment investment = new Investment();

            investment.Backer  = user;
            investment.Project = project;
            investment.Amount  = investmentDto.Amount;
            investment.Date    = DateTime.Now;

            return(investment);
        }
コード例 #3
0
        public InvestmentDto Read(long id)
        {
            var investPoco = _repository.Read(id);

            if (investPoco != null)
            {
                InvestmentDto dto = Mapper.Map <InvestmentDto>(investPoco);
                return(dto);
            }
            else
            {
                return(null);
            }
        }
コード例 #4
0
        public GetInvestments()
        {
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri("http://localhost:51285/");
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                // New code:
                HttpResponseMessage response = client.GetAsync("api.invest.com/investments/3").Result;
                if (response.IsSuccessStatusCode)
                {
                    InvestmentDto investment = JsonConvert.DeserializeObject <InvestmentDto>(
                        response.Content.ReadAsStringAsync().Result);
                }
            }
        }
コード例 #5
0
        public void CreateNew(long userId, long projectId, InvestmentDto investmentDto)
        {
            User    user    = userService.GetById(userId);
            Project project = projectService.GetById(projectId);

            TransactionStatus transactionResult = BankService.MakeTransaction(investmentDto.Amount);

            if (transactionResult == TransactionStatus.COMPLETED)
            {
                Investment investment = InvestmentMapper.Map(user, project, investmentDto);

                db.Investments.Add(investment);
                db.SaveChanges();

                projectService.UpdateCollectedMoney(projectId);
            }
            else
            {
                throw new TransactionErrorException("Transaction execution error");
            }
        }