コード例 #1
0
        public AccountChange AddAccountChange(AutomatedCashFlow flow, Account account, int sign)
        {
            AccountChange change = new AccountChange();

            change.AccountChangeId     = Guid.NewGuid().ToString();
            change.UpdatedBalance      = Math.Round(account.Available + (flow.Amount * sign), 2);
            account.Available          = change.UpdatedBalance;
            change.Account             = account;
            change.DateAdded           = DateTime.Now;
            change.AutomatedCashFlowId = flow.ID;
            change.AccountId           = account.Id;
            return(change);
        }
コード例 #2
0
        public void AddAccountChange(ManualCashFlow flow)
        {
            AccountChange change = new AccountChange();

            change.AccountChangeId = Guid.NewGuid().ToString();
            using (FinPlannerContext _context = new FinPlannerContext())
            {
                Account          account        = _context.Account.Find(flow.AccountId);
                CFClassification classification = _context.CFClassifications.Find(flow.CFClassificationId);
                change.UpdatedBalance         = Math.Round(account.Available + (flow.Amount * classification.Sign), 2);
                account.Available             = change.UpdatedBalance;
                change.DateAdded              = DateTime.Now;
                change.ManualCashFlowId       = flow.Id;
                _context.Entry(account).State = EntityState.Modified;
                _context.AccountChange.Add(change);
                _context.SaveChanges();
            }
        }
コード例 #3
0
        public AutomateReturn AddTransaction(YodleeTransactionLevel transaction, string accId, List <CFType> types, ManualCashFlow manual, List <CFClassification> classifications, Account account)
        {
            AutomateReturn automateReturn = new AutomateReturn();

            automateReturn.AutomatedCashFlow = new AutomatedCashFlow()
            {
                ID                 = Guid.NewGuid().ToString(),
                AccountId          = accId,
                Amount             = transaction.amount.amount,
                CFClassificationId = GetCFClassification(transaction, classifications),
                CFTypeId           = types.Where(x => x.YodleeId == transaction.categoryId).Select(x => x.Id).FirstOrDefault(),
                DateBooked         = transaction.transactionDate,
                DateCaptured       = transaction.createdDate,
                SourceOfExpense    = GetSource(transaction),
                YodleeId           = transaction.id
            };
            if (automateReturn.AutomatedCashFlow.DateBooked == DateTime.MinValue)
            {
                automateReturn.AutomatedCashFlow.DateBooked = automateReturn.AutomatedCashFlow.DateCaptured;
            }

            if (manual != null)
            {
                automateReturn.ManualCashFlow = manual;
                automateReturn.ManualCashFlow.AutomatedCashFlowId = automateReturn.AutomatedCashFlow.ID;
                automateReturn.AutomatedCashFlow.CFTypeId         = manual.CFTypeId;
                automateReturn.AccountChange = new AccountChange()
                {
                    AccountChangeId = ""
                };
                automateReturn.AutomatedCashFlow.Validated = true;
            }
            else
            {
                AccountChange change = new AccountChange();
                automateReturn.AccountChange  = change.AddAccountChange(automateReturn.AutomatedCashFlow, account, GetCFClassificationSign(transaction, classifications));
                automateReturn.ManualCashFlow = new ManualCashFlow()
                {
                    Id = ""
                };
                automateReturn.AutomatedCashFlow.Validated = false;
            }
            return(automateReturn);
        }
コード例 #4
0
        public ReturnModel Save()
        {
            ManualCashFlow flow        = new ManualCashFlow(this);
            ReturnModel    returnModel = new ReturnModel();

            using (FinPlannerContext _context = new FinPlannerContext())
            {
                _context.Add(flow);
                try
                {
                    _context.SaveChanges();
                    AccountChange change = new AccountChange();
                    change.AddAccountChange(flow);
                    returnModel.result = true;
                    return(returnModel);
                }
                catch (Exception e)
                {
                    returnModel.returnStr = e.Message;
                    returnModel.result    = false;
                    return(returnModel);
                }
            }
        }