/// <summary> /// Initializes a new instance of the <see cref="WorkProfileVm"/> class from the model. /// </summary> /// <param name="entity">The model.</param> /// <param name="access"></param> /// <param name="dataService"></param> public WorkProfileVm(WorkProfile entity, AccessType access) : base(access) { IsReadonly = (access < AccessType.Update); _model = entity; InitializeData(); }
/// <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); } }; }