Example #1
0
        public OperationResult RequestForWithdraw(Invest model)
        {
            return(InvokeOperations.InvokeOperation(() =>
            {
                var investor = context.Users
                               .First(x => x.Id == model.UserId);

                var lastPeriod = context.Periods
                                 .Where(x => x.InvestmentProgramId == model.InvestmentProgramId)
                                 .OrderByDescending(x => x.Number)
                                 .First();

                var invRequest = new InvestmentRequests
                {
                    Id = Guid.NewGuid(),
                    UserId = model.UserId,
                    Amount = model.Amount,
                    Date = DateTime.UtcNow,
                    InvestmentProgramtId = model.InvestmentProgramId,
                    Status = InvestmentRequestStatus.New,
                    Type = InvestmentRequestType.Withdrawal,
                    PeriodId = lastPeriod.Id
                };

                context.Add(invRequest);
                context.SaveChanges();
            }));
        }
Example #2
0
 public static InvestmentProgramRequest ToInvestmentRequest(this InvestmentRequests inv)
 {
     return(new InvestmentProgramRequest
     {
         Id = inv.Id,
         Date = inv.Date,
         Status = inv.Status,
         Type = inv.Type,
         Amount = inv.Amount
     });
 }
Example #3
0
        public OperationResult Invest(Invest model)
        {
            return(InvokeOperations.InvokeOperation(() =>
            {
                var investor = context.Users
                               .Include(x => x.Wallets)
                               .First(x => x.Id == model.UserId);
                var wallet = investor.Wallets.First(x => x.Currency == Currency.GVT);
                var lastPeriod = context.Periods
                                 .Where(x => x.InvestmentProgramId == model.InvestmentProgramId)
                                 .OrderByDescending(x => x.Number)
                                 .First();

                var tx = new WalletTransactions
                {
                    Id = Guid.NewGuid(),
                    Type = WalletTransactionsType.InvestToProgram,
                    WalletId = wallet.Id,
                    Amount = model.Amount,
                    Date = DateTime.UtcNow,
                    InvestmentProgramtId = model.InvestmentProgramId
                };

                var invRequest = new InvestmentRequests
                {
                    Id = Guid.NewGuid(),
                    UserId = model.UserId,
                    Amount = model.Amount,
                    Date = DateTime.UtcNow,
                    InvestmentProgramtId = model.InvestmentProgramId,
                    Status = InvestmentRequestStatus.New,
                    Type = InvestmentRequestType.Invest,
                    PeriodId = lastPeriod.Id,
                    WalletTransactionId = tx.Id
                };

                wallet.Amount -= model.Amount;

                context.Add(invRequest);
                context.Add(tx);
                context.SaveChanges();
            }));
        }