public async Task <bool> Deposit(TransactionActionModel model) { Transaction transaction = new Transaction() { AccountId = (int)model.ToAccountId, OperationId = model.OperationId, Amount = model.Amount, Date = DateTime.Now, ToAccountId = (int)model.ToAccountId }; await _ITransactionRepo.Add(transaction); var account = await _IAccountRepo.GetAccountByIDWithouInclude((int)model.ToAccountId); if (account.CurrencyId == model.CurrencyId) { account.Amount = account.Amount + model.Amount; } else { var ratio = await GetRatioByFromAndToID(model.CurrencyId, account.CurrencyId); account.Amount += model.Amount * ratio.Ratio; } return(await _IAccountRepo.Update(account)); }
public ActionResult Delete(int ID) { TransactionActionModel model = new TransactionActionModel(); var transaction = transactionsServices.GetTransactionsByID(ID); model.ID = transaction.ID; return(PartialView("_Delete", model)); }
public async Task <bool> Transfer(TransactionActionModel model) { Transaction transaction = new Transaction() { AccountId = (int)model.FromAccountId, OperationId = model.OperationId, Amount = model.Amount, Date = DateTime.Now, FromAccountId = (int)model.FromAccountId, ToAccountId = (int)model.ToAccountId }; Transaction transaction2 = new Transaction() { AccountId = (int)model.ToAccountId, OperationId = model.OperationId, Amount = model.Amount, Date = DateTime.Now, FromAccountId = (int)model.FromAccountId, ToAccountId = (int)model.ToAccountId }; await _ITransactionRepo.Add(transaction); await _ITransactionRepo.Add(transaction2); var fromAccount = await _IAccountRepo.GetAccountByIDWithouInclude((int)model.FromAccountId); var toAccount = await _IAccountRepo.GetAccountByIDWithouInclude((int)model.ToAccountId); if (fromAccount.CurrencyId == toAccount.CurrencyId) { toAccount.Amount = toAccount.Amount + model.Amount; fromAccount.Amount = fromAccount.Amount - model.Amount; } else { var ratio = await GetRatioByFromAndToID(model.CurrencyId, fromAccount.CurrencyId); fromAccount.Amount -= model.Amount * ratio.Ratio; toAccount.Amount += model.Amount * ratio.Ratio; } var from = await _IAccountRepo.Update(fromAccount); var to = await _IAccountRepo.Update(toAccount); if (from && to) { return(true); } return(false); }
public JsonResult ActionIncome(TransactionActionModel model) { JsonResult json = new JsonResult(); var result = false; if (model.ID > 0) //we are trying to edit a record { var transaction = transactionsServices.GetTransactionsByID(model.ID); transaction.BudgetsID = (int)model.BudgetsID; transaction.BudgetsName = model.BudgetsName; transaction.TransactionName = model.TransactionName; transaction.Place = model.Place; transaction.Price = model.Price; transaction.Date = model.Date; result = transactionsServices.UpdateTransactions(transaction); } else //we are trying to create a record { Transactions transaction = new Transactions(); transaction.BudgetsID = (int)model.BudgetsID; transaction.BudgetsName = model.BudgetsName; transaction.TransactionName = model.TransactionName; transaction.Place = model.Place; transaction.Price = model.Price; transaction.Date = model.Date; result = transactionsServices.SaveTransactions(transaction); } if (result) { json.Data = new { Success = true }; } else { json.Data = new { Success = false, Message = "Unable to perform action on Transactions." }; } return(json); }
public JsonResult Delete(TransactionActionModel model) { JsonResult json = new JsonResult(); var result = false; var transaction = transactionsServices.GetTransactionsByID(model.ID); result = transactionsServices.DeleteTransactions(transaction); if (result) { json.Data = new { Success = true }; } else { json.Data = new { Success = false, Message = "Unable to perform action on transaction." }; } return(json); }
public ActionResult ActionExpense(int?ID) { TransactionActionModel model = new TransactionActionModel(); if (ID.HasValue) //we are trying to edit a record { var transaction = transactionsServices.GetTransactionsByID(ID.Value); model.ID = transaction.ID; model.BudgetsID = transaction.BudgetsID; model.BudgetsName = transaction.BudgetsName; model.TransactionName = transaction.TransactionName; model.Place = transaction.Place; model.Price = transaction.Price; model.Date = transaction.Date; } model.Budgets = budgetServices.GetAllBudgets(); model.DebtCards = debtCardServices.GetAllDebtCards(); return(PartialView("_ActionExpense", model)); }
public async Task <IActionResult> Transfer([FromBody] TransactionActionModel model) { var result = await _ISupervisor.Transfer(model); return(Ok(result)); }