/// <summary> /// 修改待办事项 /// </summary> /// <returns></returns> private async Task ModifyToDo() { IsLoading = Visibility.Visible; //离线模式 if (App.isInOfflineMode) { //修改当前列表 MyToDos.ToList().Find(sche => { if (sche.ID == NewToDo.ID) { return(true); } else { return(false); } }).Content = NewToDo.Content; await SerializerHelper.SerializerToJson <ObservableCollection <ToDo> >(MyToDos, SerializerFileNames.ToDoFileName, true); Messenger.Default.Send(new GenericMessage <string>(""), MessengerTokens.RemoveScheduleUI); NewToDo = new ToDo(); Messenger.Default.Send(new GenericMessage <ObservableCollection <ToDo> >(MyToDos), MessengerTokens.UpdateTile); return; } //非离线模式 else { var resultUpdate = await PostHelper.UpdateContent(NewToDo.ID, NewToDo.Content, NewToDo.Category); if (resultUpdate) { MyToDos.ToList().Find(sche => { if (sche.ID == NewToDo.ID) { return(true); } else { return(false); } }).Content = NewToDo.Content; Messenger.Default.Send(new GenericMessage <string>(""), MessengerTokens.RemoveScheduleUI); NewToDo = new ToDo(); Messenger.Default.Send(new GenericMessage <ObservableCollection <ToDo> >(MyToDos), MessengerTokens.UpdateTile); } } IsLoading = Visibility.Collapsed; }
/// <summary> /// 完成待办事项 /// </summary> /// <param name="id">待办事项的ID</param> /// <returns></returns> private async Task CompleteTodo(string id) { try { var currentMemo = MyToDos.ElementAt(MyToDos.ToList().FindIndex(sch => { if (sch.ID == id) { return(true); } else { return(false); } })); currentMemo.IsDone = !currentMemo.IsDone; await SerializerHelper.SerializerToJson <ObservableCollection <ToDo> >(MyToDos, "myschedules.sch", true); if (!App.isInOfflineMode) { var isDone = await PostHelper.FinishSchedule(id, currentMemo.IsDone? "1" : "0"); if (isDone) { await PostHelper.SetMyOrder(LocalSettingHelper.GetValue("sid"), ToDo.GetCurrentOrderString(MyToDos)); Messenger.Default.Send(new GenericMessage <ObservableCollection <ToDo> >(MyToDos), MessengerTokens.UpdateTile); } } else { Messenger.Default.Send(new GenericMessage <ObservableCollection <ToDo> >(MyToDos), MessengerTokens.UpdateTile); } } catch (Exception e) { var task = ExceptionHelper.WriteRecord(e); } }
/// <summary> /// 删除todo /// </summary> /// <param name="id">ID</param> /// <returns></returns> /// 先从列表删除,然后把列表内容都序列化保存,接着: /// 1.如果已经登陆的,尝试发送请求; /// 2.离线模式,不用管 private async Task DeleteToDo(string id) { try { var itemToDeleted = MyToDos.ToList().Find(s => { if (s.ID == id) { return(true); } else { return(false); } }); DeletedToDos.Add(itemToDeleted); await SerializerHelper.SerializerToJson <ObservableCollection <ToDo> >(DeletedToDos, SerializerFileNames.DeletedFileName, true); MyToDos.Remove(itemToDeleted); UpdateDisplayList(SelectedCate); await SerializerHelper.SerializerToJson <ObservableCollection <ToDo> >(MyToDos, SerializerFileNames.ToDoFileName, true); if (!App.isInOfflineMode) { var result = await PostHelper.DeleteSchedule(id); await PostHelper.SetMyOrder(LocalSettingHelper.GetValue("sid"), ToDo.GetCurrentOrderString(MyToDos)); } Messenger.Default.Send(new GenericMessage <ObservableCollection <ToDo> >(MyToDos), MessengerTokens.UpdateTile); } catch (Exception e) { var task = ExceptionHelper.WriteRecord(e); } }
/// <summary> /// 改变类别 /// </summary> /// <param name="id"></param> /// <returns></returns> private async Task ChangeCategory(string id) { var scheduleToChange = MyToDos.ToList().Find(s => { if (s.ID == id) { return(true); } else { return(false); } }); if (scheduleToChange != null) { scheduleToChange.Category++; if (!App.IsNoNetwork && !App.isInOfflineMode) { await PostHelper.UpdateContent(id, scheduleToChange.Content, scheduleToChange.Category); } } }