/// <summary> /// Initializes all commands and Shift colors and, at last, Loads data /// </summary> /// <param name="dataService"></param> private void InitializeData() { UOW = new Dal.SoheilEdmContext(); WorkProfileDataService = new WorkProfileDataService(UOW); if (_model == null) { _model = WorkProfile.CreateDefault(); WorkProfileDataService.AttachModel(_model); } else _model = WorkProfileDataService.GetSingle(_model.Id); SaveCommand = new Command(Save, CanSave); AskForIncreaseNumberOfShifts = new Command(o => IsPrototypeChangeAskVisible = true); IncreaseNumberOfShifts = new Command(o => { IsPrototypeChangeAskVisible = false; NumberOfShiftsModifier++; }); ShiftColors.Add(new ShiftColorVm { Color = DefaultColors.Shift.Day }); ShiftColors.Add(new ShiftColorVm { Color = DefaultColors.Shift.Evening }); ShiftColors.Add(new ShiftColorVm { Color = DefaultColors.Shift.Night }); ShiftColors.Add(new ShiftColorVm { Color = DefaultColors.Shift.Reserve1 }); ShiftColors.Add(new ShiftColorVm { Color = DefaultColors.Shift.Reserve2 }); ShiftColors.Add(new ShiftColorVm { Color = DefaultColors.Shift.Reserve3 }); //fill vm with _model data Load(); ShiftPrototypes.CollectionChanged += (s, e) => { if (e.NewItems != null) foreach (WorkShiftPrototypeVm proto in e.NewItems) { _model.WorkShiftPrototypes.Add(proto.Model); } if (e.OldItems != null) foreach (WorkShiftPrototypeVm proto in e.OldItems) { _model.WorkShiftPrototypes.Remove(proto.Model); } }; }
public static WorkProfile CreateNew(WorkProfileDataService dataService) { int id = dataService.AddModel(WorkProfile.CreateDefault()); return dataService.GetSingle(id); }