public DailyPlanViewModel(DbContext dbContext, DailyPlan plan, CurrentWeekViewModel weekViewModel) { _dbContext = dbContext; WeekViewModel = weekViewModel; Plan = plan; Tasks = new ObservableCollection <TaskViewModel>(); var tasks = _dbContext.Tasks.GetItems() .Where(x => x.PlanId == Plan.Id) .Select((x, i) => new TaskViewModel(x, i, this, null)); tasks.ForEach(t => Tasks.Add(t)); AllTasks = Tasks.Count; CompletedTasks = Tasks.Count(t => t.IsCompleted); Status = GetStatus(); IsSuccessful = GetSuccess(); Highlight = Date == DateTime.Now.ToShortDateString(); }
public ScratchesViewModel(DbContext dbContext, INavigation navigation, CurrentWeekViewModel currentWeekViewModel) { _dbContext = dbContext; _currentWeekViewModel = currentWeekViewModel; Navigation = navigation; var scratches = _dbContext.DailyPlans.GetItems() .Where(p => p.IsScratch) .Select(x => new ScratchViewModel(_dbContext, x) { ScratchesViewModel = this }); Scratches = new ObservableCollection <ScratchViewModel>(); scratches.ForEach(x => Scratches.Add(x)); CreateScratchCommand = new Command(CreateScratch); DeleteScratchCommand = new Command(DeleteScratch); SaveScratchCommand = new Command(SaveScratch); SavePlanCommand = new Command(SavePlan); }