public IHttpActionResult PutMyToDos(int id, MyToDos myToDos) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != myToDos.Id) { return(BadRequest()); } db.Entry(myToDos).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!MyToDosExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
/// <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; }
public IHttpActionResult GetMyToDos(int id) { MyToDos myToDos = db.MyToDos.Find(id); if (myToDos == null) { return(NotFound()); } return(Ok(myToDos)); }
public IHttpActionResult PostMyToDos(MyToDos myToDos) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.MyToDos.Add(myToDos); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = myToDos.Id }, myToDos)); }
public IHttpActionResult DeleteMyToDos(int id) { MyToDos myToDos = db.MyToDos.Find(id); if (myToDos == null) { return(NotFound()); } db.MyToDos.Remove(myToDos); db.SaveChanges(); return(Ok(myToDos)); }
/// <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); } } }
private async Task AddToDo() { //离线模式 if (App.isInOfflineMode || App.IsNoNetwork) { NewToDo.ID = Guid.NewGuid().ToString(); NewToDo.Category = this.SelectedCate; //0 for insert,1 for add if (LocalSettingHelper.GetValue("AddMode") == "0") { MyToDos.Insert(0, NewToDo); } else { MyToDos.Add(NewToDo); } await SerializerHelper.SerializerToJson <ObservableCollection <ToDo> >(MyToDos, SerializerFileNames.ToDoFileName); Messenger.Default.Send(new GenericMessage <ObservableCollection <ToDo> >(MyToDos), MessengerTokens.UpdateTile); NewToDo = new ToDo(); IsLoading = Visibility.Collapsed; } else if (App.IsNoNetwork) { //TO DO: Store the schedule in SendingQueue } else { //在线模式 var result = await PostHelper.AddSchedule(LocalSettingHelper.GetValue("sid"), NewToDo.Content, "0", SelectedCate.ToString()); if (!string.IsNullOrEmpty(result)) { ToDo newSchedule = ToDo.ParseJsonTo(result); if (LocalSettingHelper.GetValue("AddMode") == "0") { MyToDos.Insert(0, newSchedule); UpdateDisplayList(SelectedCate); } else { MyToDos.Add(newSchedule); UpdateDisplayList(SelectedCate); } await PostHelper.SetMyOrder(LocalSettingHelper.GetValue("sid"), ToDo.GetCurrentOrderString(MyToDos)); NewToDo = new ToDo(); Messenger.Default.Send(new GenericMessage <ObservableCollection <ToDo> >(MyToDos), MessengerTokens.UpdateTile); IsLoading = Visibility.Collapsed; await SerializerHelper.SerializerToJson <ObservableCollection <ToDo> >(MyToDos, SerializerFileNames.ToDoFileName); } } }