public void UpdateCollectedMoney(long id)
        {
            double  money   = db.Investments.Where(inv => inv.Project.Id == id).Select(inv => inv.Amount).Sum();
            Project project = db.Projects.Find(id);

            project.CollectedMoney = money;

            db.SaveChanges();

            if (project.Goal <= project.CollectedMoney)
            {
                UpdateStatus(id, ProjectStatus.FUNDED);
            }
            else
            {
                UpdateStatus(id, ProjectStatus.IN_PROGRESS);
            }
        }
        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");
            }
        }
Esempio n. 3
0
 public void CreateNew(User user)
 {
     db.Users.Add(user);
     db.SaveChanges();
 }