public IActionResult Edit(Category category) { if (ModelState.IsValid) { _context.Update(category); _context.SaveChanges(); return(RedirectToAction("Index")); } return(View(category)); }
public async Task <IActionResult> Edit(int id, [Bind("ToDoItemID,UserEmail,Title,Description,AddedDate,DueDate,Done,DoneDate")] ToDoItem toDoItem) { if (id != toDoItem.ToDoItemID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(toDoItem); await _context.SaveChangesAsync(); toDoItem.UserEmail = User.Identity.Name; await _context.SaveChangesAsync(); if (toDoItem.Done) { toDoItem.DoneDate = DateTime.Now.ToString(); await _context.SaveChangesAsync(); } else { toDoItem.DoneDate = "Unknown"; await _context.SaveChangesAsync(); } } catch (DbUpdateConcurrencyException) { if (!ToDoItemExists(toDoItem.ToDoItemID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(toDoItem)); }
public IActionResult Edit(Item item) { if (ModelState.IsValid) { _context.Update(item); _context.SaveChanges(); return(RedirectToAction("Index")); } //ViewBag.CategoryId = new SelectList(_context.Categories, "CategoryId", "Category", item.CategoryId); return(View(item)); }
public async Task EditAsync(Item <Guid, string> item) { var entity = await _context.ToDoItems.SingleOrDefaultAsync(p => p.Id == item.Id); entity.Id = item.Id; entity.Title = item.Title; entity.Color = item.Color; entity.Completed = item.IsCompleted; _context.Update(entity); await _context.SaveChangesAsync(); }
public async Task <ToDo> UpdateToDoWithEntity(int id, ToDo toDo) { try { _context.Update(toDo); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ToDoExists(toDo.Id)) { return(null); } else { throw; } } return(toDo); }
public IActionResult SaveChanges(ToDoList updatedToDoList) { ToDoList toDoList = _ToDoListDb.ToDoList.Find(updatedToDoList.ToDoListId); //merging the databaseSuper with the updateSuper one property at a time //This is to prevent losing information in the databaseSuper that might not //but in the updatedSuper toDoList.ToDoListId = updatedToDoList.ToDoListId; toDoList.TaskDescription = updatedToDoList.TaskDescription; toDoList.DueDate = updatedToDoList.DueDate; toDoList.Complete = updatedToDoList.Complete; toDoList.UserId = updatedToDoList.UserId; //creates a log of changes for this entry. A way to tracking our work _ToDoListDb.Entry(toDoList).State = Microsoft.EntityFrameworkCore.EntityState.Modified; _ToDoListDb.Update(toDoList); _ToDoListDb.SaveChanges(); return(RedirectToAction(nameof(Index))); }