/// <summary> Creates a new task. </summary> public StudyTask(IStudyTasksService client, string name, string userId, TimeSpan estimate) { if (client == null) { throw new ArgumentNullException(nameof(client)); } if (string.IsNullOrWhiteSpace(name)) { throw new ArgumentException(nameof(name)); } if (userId == null) { throw new ArgumentNullException(nameof(userId)); } this.MessageObject = new StudyTaskService() { Name = name, UserId = userId, Estimate = estimate }; this.service = client; this.Name = name; this.Estimate = estimate; this.TimeSpans = new ObservableCollection <TaskTimeSpan>(); this.TimeSpans.CollectionChanged += OnTimeSpansChanged; this.PropertyChanged += OnPropertyChanged; }
/// <summary> Creates a <see cref="StudyTask"/> instance representing an already existing task in the database. </summary> public StudyTask(IStudyTasksService service, StudyTaskService task) { if (service == null) { throw new ArgumentNullException(nameof(service)); } if (task == null) { throw new ArgumentNullException(nameof(task)); } if (task.Id == 0) { throw new ArgumentException(); } if (task.UserId == null) { throw new ArgumentNullException(nameof(task.UserId)); } this.MessageObject = task; this.service = service; this.Name = this.MessageObject.Name; this.Estimate = this.MessageObject.Estimate; //retrieve time spans from database: var timeSpans = service.GetTimeSpansFor(task.Id).Select(timeSpanDB => new TaskTimeSpan(service, timeSpanDB, this)); this.TimeSpans = new ObservableCollection <TaskTimeSpan>(timeSpans); this.TimeSpans.CollectionChanged += OnTimeSpansChanged; this.PropertyChanged += OnPropertyChanged; }