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");
            }
        }
Example #2
0
        public InvestmentPagingData GetInvestments(List<SortOption> sortData, int pageSize, int pageNum)
        {
            var modelMapper = new InvestmentMapper();
            var investments = investmentRepository.GetInvestments(sortData);

            var investmentsDtos = new List<InvestmentDto>();
            foreach (var investment in investments)
            {
                var investmentDto = modelMapper.DtoFrom(investment);
                investmentsDtos.Add(investmentDto);
            }

            var pages = pageSize > 0 ? investmentsDtos.Count / pageSize : 0;
            var rows = investmentsDtos.GetRange((pageNum) * pageSize, pageSize);

            var investmentPagingData = new InvestmentPagingData()
            {
                Pages = pages,
                Rows = rows
            };
            return investmentPagingData;
        }
        public List <UserInvestmentDto> GetAllByProjectID(long id)
        {
            List <Investment> investments = db.Investments.Where(inv => inv.Project.Id == id).Include(p => p.Backer).Include(p => p.Project).ToList();

            return(investments.Select(investment => InvestmentMapper.Map(investment)).ToList());
        }