public async Task <int> EditExpensesAsync(Expense dExpenseToUpdate, int id) { var result = -1; var entiry = _ctx.Expenses.Include(d => d.ExpenseDetail).FirstOrDefault(x => x.Id == id); try { if (entiry != null) { entiry.ExpenseTitle = dExpenseToUpdate.ExpenseTitle; entiry.ExpensesAmount = dExpenseToUpdate.ExpensesAmount; entiry.ExpenseDate = dExpenseToUpdate.ExpenseDate; entiry.ExpenseCategoryId = dExpenseToUpdate.ExpenseCategoryId; entiry.CurrencyId = dExpenseToUpdate.CurrencyId; entiry.updateDate = DateTime.UtcNow; entiry.ExpenseDetail = dExpenseToUpdate.ExpenseDetail; entiry.Signature = dExpenseToUpdate.Signature; entiry.PaymentMethod = dExpenseToUpdate.PaymentMethod; entiry.PaymentType = dExpenseToUpdate.PaymentType; _ctx.Entry(entiry).State = EntityState.Modified; //_ctx.Expenses.Update(entiry); result = await _ctx.SaveChangesAsync(); } } catch (Exception) { throw; } return(result); }
public async Task <bool> UpdateExpenseRuleAsync(ExpenseRule expRule, int id) { bool vResult = false; var entiry = _ctx.ExpenseRules.FirstOrDefault(x => x.Id == id); try { if (entiry != null) { entiry.RuleName = expRule.RuleName; entiry.SearchText = expRule.SearchText; entiry.IsActiveRule = expRule.IsActiveRule; entiry.Priority = expRule.Priority; entiry.ExpenseCategoryId = expRule.ExpenseCategoryId; entiry.CurrencyId = expRule.CurrencyId; entiry.PaymentMethod = expRule.PaymentMethod; entiry.PaymentType = expRule.PaymentType; entiry.updateDate = DateTime.UtcNow; _ctx.Entry(entiry).State = EntityState.Modified; await _ctx.SaveChangesAsync(); vResult = true; } } catch (Exception) { throw; } return(vResult); }