public async Task<bool> UpdateTransaction(TransactionViewModel model) { // Get the authenticated user var username = HttpContext.Current.User.Identity.Name; User user = await _userManager.FindByNameAsync(username); // First retrieve all categories. // Select the category specified by submitted transaction data. // If no such category exists, create it and get the category id. IList<Category> categories = await _accountData.GetCategoriesAsync(); Category category = categories.FirstOrDefault(c => c.Name == model.Category); int categoryId; if (category == null) categoryId = await _accountData.InsertCategoryAsync(new Category { Name = model.Category }); else categoryId = category.Id; Transaction transaction = new Transaction { Id = model.Id, Description = model.Description, Amount = model.Amount, Reconciled = model.Reconciled, isReconciled = model.Amount.Equals(model.Reconciled), Updated_By = user.Id }; bool updateTransactionResult = await _accountData.UpdateTransactionAsync(transaction); // Update the category associated with this transaction bool updatedTransactionCategoryResult = await _accountData.UpdateTransactionCategoryAsync(transaction.Id, categoryId); return updatedTransactionCategoryResult; }
public async Task<IList<TransactionViewModel>> UpdateTransaction(TransactionViewModel model) { // update transaction bool result = await AccountManager.UpdateTransaction(model); if (!result) throw new HttpResponseException(HttpStatusCode.InternalServerError); // return updated transactions IList<TransactionViewModel> transactions = await AccountManager.GetTransactions(model.AccountId); return transactions; }