public bool AddSpending(string category, decimal amount) { if (category == null || category.Length == 0 || amount <= 0) { return(false); } int categoryID = GetCategoryID(category); if (categoryID < 0) { return(false); } Spending spending = GetSpending(categoryID); if (spending != null) { spending.IncreaseAmount(amount); balance.Amount -= amount; return(true); } int id = spendings.Count; spendings.Add(new Spending(id, categoryID, amount)); balance.Amount -= amount; return(true); }
private Spending GetSpending(int categoryID) { Spending spending = null; foreach (Spending s in spendings) { if (s.CategoryID == categoryID && s.Date.Equals(DateTime.Today)) { spending = s; break; } } return(spending); }
public decimal ShowSpendingsInCategoryByInterval(string category, DateTime start, DateTime end) { if (category == null || category.Length == 0) { return(0); } Spending spending = null; int catID = GetCategoryID(category); foreach (Spending s in spendings) { if (s.CategoryID == catID && s.Date.CompareTo(start) >= 0 && s.Date.CompareTo(end) <= 0) { spending = s; break; } } return(spending == null ? 0 : spending.Amount); }