/// <summary> /// Creates an instance of <see cref="WorkShiftVm"/> with the given model and work shift prototype viewModel /// </summary> /// <param name="model"></param> /// <param name="prototype"></param> public WorkShiftVm(Model.WorkShift model, WorkShiftPrototypeVm prototype) { Model = model; Prototype = prototype; StartSeconds = model.StartSeconds; EndSeconds = model.EndSeconds; IsOpen = model.IsOpen; //add workbreak models foreach (var workBreak in model.WorkBreaks) { var wbreak = new WorkBreakVm(workBreak); wbreak.DeleteCommand = new Commands.Command(o => Breaks.Remove(wbreak)); Breaks.Add(wbreak); } //auto add future workbreak models Breaks.CollectionChanged += (s, e) => { if (e.NewItems != null) foreach (WorkBreakVm wbreak in e.NewItems) { Model.WorkBreaks.Add(wbreak.Model); } if(e.OldItems!=null) foreach (WorkBreakVm wbreak in e.OldItems) { Model.WorkBreaks.Remove(wbreak.Model); } }; ToggleIsOpenCommand = new Commands.Command(o => IsOpen = !IsOpen); }
/// <summary> /// Creates a temporary break at the given time with duration of zero, and adds it to Breaks /// </summary> /// <param name="seconds"></param> /// <returns></returns> public WorkBreakVm AddTemporaryBreak(int seconds) { var wbreak = new WorkBreakVm(new Model.WorkBreak { WorkShift = Model, StartSeconds = seconds, EndSeconds = seconds, }); wbreak.DeleteCommand = new Commands.Command(o => Breaks.Remove(wbreak)); Breaks.Add(wbreak); return wbreak; }