public IActionResult Post([FromBody] ToDoEdit toDoEdit) { var todo = new ToDo { Id = Guid.NewGuid(), Title = toDoEdit.Title, Completed = toDoEdit.Completed }; _toDoService.Insert(todo); return(Ok(todo)); }
public ActionResult Edit(int id) { var service = CreateToDoService(); var detail = service.GetToDoById(id); var model = new ToDoEdit { GroupID = detail.GroupID, ToDoID = detail.ToDoID, Title = detail.Title, Details = detail.Details }; return(View(model)); }
public bool UpdateToDo(ToDoEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .ToDos .Single(e => e.ToDoID == model.ToDoID); entity.Title = model.Title; entity.Details = model.Details; entity.GroupID = model.GroupID; entity.ModifiedUtc = DateTimeOffset.UtcNow; entity.IsDone = model.IsDone; return(ctx.SaveChanges() == 1); } }
public IActionResult Post([FromBody] ToDoEdit toDoEdit) { var todo = new ToDo { Id = Guid.NewGuid(), Title = toDoEdit.Title, Completed = toDoEdit.Completed }; if (!_memoryCache.TryGetValue(Key, out List <ToDo> todos)) { todos = _toDos; } todos.Add(todo); var options = new MemoryCacheEntryOptions().SetAbsoluteExpiration(TimeSpan.FromDays(1)); _memoryCache.Set(Key, todos, options); return(Ok(todo)); }
private bool SetStarState(int toDoId, bool newState) { // Create the service var userId = Guid.Parse(User.Identity.GetUserId()); var service = new ToDoService(userId); // Get the note var detail = service.GetToDoById(toDoId); // Create the NoteEdit model instance with the new star state var updatedToDo = new ToDoEdit { ToDoID = detail.ToDoID, GroupID = detail.GroupID, Title = detail.Title, Details = detail.Details, IsDone = newState }; // Return a value indicating whether the update succeeded return(service.UpdateToDo(updatedToDo)); }
public ActionResult Edit(int id, ToDoEdit model) { if (!ModelState.IsValid) { return(View(model)); } if (model.ToDoID != id) { ModelState.AddModelError("", "Id Mismatch"); return(View(model)); } var service = CreateToDoService(); if (service.UpdateToDo(model)) { TempData["SaveResult"] = "Your note was updated."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Your note could not be updated."); return(View()); }