public void Create(BudgetAddViewModel model) { // var budget = new Budget() { Amount = model.Amount, YearMonth = model.Month }; // _budgetRepositoryStub.Save(budget); var budget = this._budgetRepository.Read(x => x.YearMonth == model.Month); if (budget == null) { this._budgetRepository.Save(new Budget() { Amount = model.Amount, YearMonth = model.Month }); var handler = this.Created; handler?.Invoke(this, EventArgs.Empty); } else { budget.Amount = model.Amount; this._budgetRepository.Save(budget); var handler = this.Updated; handler?.Invoke(this, EventArgs.Empty); } }
private void UpdateBudget(BudgetAddViewModel model, Budgets budget) { budget.Amount = model.Amount; this.budgetRepository.Save(budget); var handler = this.Updated; handler?.Invoke(this, EventArgs.Empty); }
private void AddBudget(BudgetAddViewModel model) { budgetRepository.Save(new Budgets { Amount = model.Amount, YearMonth = model.Month }); var handler = this.Created; handler?.Invoke(this, EventArgs.Empty); }
public void Create(BudgetAddViewModel model) { var budget = this.budgetRepository.Read(a => a.YearMonth == model.Month); if (budget == null) { AddBudget(model); } else { UpdateBudget(model, budget); } }