/// <summary> /// 添加or修改内容 /// </summary> /// <returns></returns> private async Task AddOrModifyToDo() { try { if (EditedToDo != null) { if (_addMode == AddMode.None) { return; } if (string.IsNullOrEmpty(EditedToDo.Content)) { await ToastService.SendToastAsync(ResourcesHelper.GetResString("ContentEmpty")); return; } ShowPaneOpen = false; //显示进度条 IsLoading = Visibility.Visible; //添加 if (_addMode == AddMode.Add) { await AddOrRestoreAndSyncNewToDo(); } //修改 else if (_addMode == AddMode.Modify) { await ModifyAndSyncToDo(); } } } catch (Exception ex) { var task = ExceptionHelper.WriteRecordAsync(ex, nameof(MainViewModel), nameof(AddOrModifyToDo)); } }
/// <summary> /// 修改待办事项 /// </summary> /// <returns></returns> private async Task ModifyAndSyncToDo() { IsLoading = Visibility.Visible; //修改当前列表 var itemToModify = AllToDos.ToList().Find(sche => { if (sche.ID == EditedToDo.ID) { return(true); } else { return(false); } }); itemToModify.Content = EditedToDo.Content; itemToModify.Category = CateVM.Categories[AddingCate].CateColorID; itemToModify.CreateTime = DateTime.Now.ToString(); UpdateDisplayList(CateVM.Categories[SelectedCate].CateColorID); //离线模式 if (App.IsInOfflineMode) { await SerializerHelper.SerializerToJson <ObservableCollection <ToDo> >(AllToDos, SerializerFileNames.ToDoFileName); EditedToDo = new ToDo(); Messenger.Default.Send(new GenericMessage <ObservableCollection <ToDo> >(AllToDos), MessengerTokens.UpdateTile); return; } //非离线模式 else if (App.CanSendRequest) { try { var resultUpdate = await CloudService.UpdateContent(itemToModify.ID, itemToModify.Content, itemToModify.CreateTime, itemToModify.Category); if (resultUpdate) { AllToDos.ToList().Find(sche => { if (sche.ID == EditedToDo.ID) { return(true); } else { return(false); } }).Content = EditedToDo.Content; EditedToDo = new ToDo(); Messenger.Default.Send(new GenericMessage <ObservableCollection <ToDo> >(AllToDos), MessengerTokens.UpdateTile); } } catch (COMException) { await ToastService.SendToastAsync(ResourcesHelper.GetResString("RequestError")); } } IsLoading = Visibility.Collapsed; }