public static void SubmitLocalTaskChanges(Data.TaskList taskList, TaskChanges localchanges) { foreach (var change in localchanges) { switch (change.TaskChangeType) { case TaskChangeType.None: break; case TaskChangeType.Create: InsertTask(taskList, change.NewTask); break; case TaskChangeType.Change: UpdateTask(taskList, change.NewTask); break; case TaskChangeType.ChangeAndMove: UpdateTask(taskList, change.NewTask); MoveTask(taskList, change.NewTask); break; case TaskChangeType.Delete: DeleteTask(taskList, change.Id); break; default: throw new ArgumentOutOfRangeException(); } } if (localchanges.Count > 0) { TasksReferenceManager.SaveReferencesToXml(taskList.Title); } }
private List <TaskChanges> GetDiff(TaskItem oldTask, TaskItem newTask, string newCategories) { List <TaskChanges> changes = new List <TaskChanges>(); var oType = oldTask.GetType(); foreach (var oProperty in oType.GetProperties()) { var oOldValue = oProperty.GetValue(oldTask, null); var oNewValue = oProperty.GetValue(newTask, null); if (Equals(oOldValue, oNewValue)) { continue; } if (oProperty.Name == "Changes" || oProperty.Name == "User") { continue; } string oldValue = "", newValue = ""; var diff = new TaskChanges { ModifiedOn = DateTime.Now, TaskId = newTask.Id }; if (oProperty.Name == "Categories") { oldValue = string.Join(", ", oldTask.Categories.Select(c => c.Category.Name)); if (oldValue == newCategories) { continue; } newValue = newCategories; } else { oldValue = oOldValue == null ? "" : oOldValue.ToString(); newValue = oNewValue == null ? "" : oNewValue.ToString(); } diff.Description = oProperty.Name + " was changed from \"" + oldValue + "\" to \"" + newValue + "\""; changes.Add(diff); } return(changes); }
public void Update(TaskChanges changes) { OnPropertyChanged("Item[]"); }