public BudgetDetailModel CreateDetail(Budget budget, int month = -1, int year = -1) { var model = new BudgetDetailModel { Id = budget.Id.ToString(), Name = budget.Name, Amount = budget.Amount, CriticalThreshold = budget.CriticalThreshold, WarningThreshold = budget.WarningThreshold, ThresholdStatus = budget.ThresholdStatus, TransactionLimit = budget.TransactionLimit, Url = _UrlHelper.Link("GETBudget", new { id = budget.Id.ToString() }) }; // build the date var now = DateTime.UtcNow; year = year < 0 ? now.Year : year; month = month < 0 ? now.Month : month; var startDate = new DateTime(year, month, 1, 0, 0, 0); var endDate = new DateTime(year, month, DateTime.DaysInMonth(year, month), 23, 59, 59); model.Balance = budget.Balance(startDate, endDate); model.Transactions = Create( budget.Transactions.Where( t => !t.IsDeleted && (t.TransactionDate >= startDate && t.TransactionDate <= endDate)).ToList(), budget.Id.ToString()); model.TransactionCount = model.Transactions.Count(); return(model); }
public Budget Parse(BudgetDetailModel budgetModel) { var budget = new Budget { Amount = budgetModel.Amount.HasValue ? budgetModel.Amount.Value : 0, Name = budgetModel.Name }; if (budgetModel.TransactionLimit.HasValue) { budget.TransactionLimit = budgetModel.TransactionLimit.Value; } if (budgetModel.CriticalThreshold.HasValue) { budget.CriticalThreshold = budgetModel.CriticalThreshold.Value; } if (budgetModel.WarningThreshold.HasValue) { budget.WarningThreshold = budgetModel.WarningThreshold.Value; } return(budget); }