public async Task <ActionResult> Edit(ToDo item) { if (ModelState.IsValid) { context.Update(item); await context.SaveChangesAsync(); TempData["Success"] = "Edited the item successfully"; return(RedirectToAction("Index")); } return(View(item)); }
public IActionResult UpdateToDo(int id, [FromBody] ToDo toDo) { var existing = _context.ToDos.AsNoTracking().FirstOrDefault(x => x.Id == id); if (existing == null) { return(NotFound()); } _context.Update(toDo); _context.SaveChanges(); return(Ok(toDo)); }
public async Task <IActionResult> Edit(int id, [Bind("id,taskName,isCompleted")] TodoItem todoItem) { if (id != todoItem.id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(todoItem); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TodoItemExists(todoItem.id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(todoItem)); }
public async Task <IActionResult> Edit(string id, [Bind("Id,Title,Uid,UName,Type,Creator,Date,Msg")] Log log) { if (id != log.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(log); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!LogExists(log.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(log)); }
public async Task <IActionResult> Edit(string id, [Bind("Id,classDescription,collegeId,majorId,classId,customerId")] Attribution attribution) { if (id != attribution.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(attribution); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AttributionExists(attribution.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(attribution)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,TodoTask,DateCreated,DateStarted,DateFinish,TotalHours,Done")] ToDo toDo) { if (id != toDo.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(toDo); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ToDoExists(toDo.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(toDo)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Value")] Tag tag) { if (id != tag.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(tag); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TagExists(tag.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(tag)); }
public async Task <IActionResult> Edit(string id, [Bind("Id,Check,Title,DueAt")] ToDo toDo) { if (id != toDo.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(toDo); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ToDoExists(toDo.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(toDo)); }
public async Task <IActionResult> Edit(long?id, [Bind("ID,Name,Description,Date,Finished")] ToDo dados) { //Verifica se os dados estão corretos para poder realizar a autualização if (ModelState.IsValid) { //Caso os dados estejam corretos ele atualiza try { _context.Update(dados); await _context.SaveChangesAsync(); } //Prevenção de erros na hora de atualizar catch (DbUpdateConcurrencyException) { if (!_context.ToDo.Any(e => e.ID == id)) { return(NotFound()); } } //Caso der tudo OK ele retornar para a visão listagem return(RedirectToAction(nameof(Index))); } /* Caso os dados estejam errados a página é regarregada, * com os memos dados para serem corrijidos. */ return(View(dados)); }
public async Task <IActionResult> Edit(int id, [Bind("ID,Title,ModifiedOn,Description,EstimatedHour")] ToDoItem toDoItem) { if (id != toDoItem.ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(toDoItem); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ToDoItemExists(toDoItem.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(toDoItem)); }
public async Task <IActionResult> Edit(int id, [Bind("ID,Title,Date,Description,Status")] Tasks tasks) { if (id != tasks.ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(tasks); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TasksExists(tasks.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(tasks)); }
public void Update(long id) { ToDo thingToUpdate = context.ToDos.FirstOrDefault(c => c.Id == 1); context.Update(thingToUpdate); context.SaveChanges(); }
public OutputModel Put(int id, [FromBody] ToDoItem item) { try { if (ModelState.IsValid) { var currItem = db.TblToDo.SingleOrDefault(p => p.id.Equals(id)); currItem.title = item.title; currItem.description = item.description; currItem.expiryDate = item.expiryDate; currItem.percentCompleted = item.percentCompleted; db.Update(currItem); db.SaveChanges(); output.status = "success"; output.data = currItem; output.message = "Data Berhasil Diubah"; } else { output.status = "error"; output.message = "Data Gagal Diubah"; output.data = null; } } catch (Exception ex) { output.status = "error"; output.message = ex.Message; output.data = null; } return(output); }
public async Task <IActionResult> Edit(string id, [Bind("Name,StuId,Email,TeachName,PhoneNumber,EmergencyContact,MergencyPeoplePhone,Langtineadress")] User user) { if (id != user.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(user); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserExists(user.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(user)); }
public IActionResult EditTask(ToDo item) { if (ModelState.IsValid) { context.Update(item); context.SaveChanges(); } return(View(item)); }
public async Task Update(TodoList item) { if (item == null) { throw new ArgumentNullException(nameof(item)); } _context.Update(item); await _context.SaveChangesAsync(); }
public async Task <ActionResult> Edit(int Id) { //Console.WriteLine(Id); TodoList item = await context.ToDoLists.FindAsync(Id); item.IsChecked = !item.IsChecked; context.Update(item); await context.SaveChangesAsync(); return(RedirectToAction("Index")); }
public async Task <ActionResult> Edit(TodoList item) { if (ModelState.IsValid) { _context.Update(item); await _context.SaveChangesAsync(); TempData["Success"] = "İtem Başarıyla Güncellendi!"; return(RedirectToAction("Index")); } return(View(item)); }
public async Task <ActionResult> Edit(TodoList item) { if (ModelState.IsValid) { context.Update(item); await context.SaveChangesAsync(); TempData["Success"] = "The item has been updated!"; return(RedirectToAction("Index")); } return(View(item)); }
public async Task <IActionResult> PatchTodoItem(long id, ToDoItem todoItem) { if (id != todoItem.Id) { return(BadRequest()); } var oldItem = await _context.ToDoItems.FindAsync(id); if (oldItem == null) { return(NotFound()); } oldItem.IsComplete = todoItem.IsComplete; _context.Update(oldItem); await _context.SaveChangesAsync(); return(NoContent()); }
public async Task <IActionResult> Edit(int id, [Bind("TaskId,Name,Category,Color,UnitPrice,AvailableQuantity")] ToDoViewModel updatedtaskDetails) { if (id != updatedtaskDetails.TaskId) { return(NotFound()); } var task = await _context.ToDo.FindAsync(id); if (task == null) { return(NotFound()); } if (ModelState.IsValid) { try { task.Title = updatedtaskDetails.Title; task.Completed = updatedtaskDetails.Completed; task.UnitPrice = updatedtaskDetails.UnitPrice; task.AvailableQuantity = updatedtaskDetails.AvailableQuantity; _context.Update(task); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!tasksExists(updatedtaskDetails.TaskId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(updatedtaskDetails)); }
public async Task <IActionResult> Edit(int entityId, [Bind("entityId")] ToDoModel editedToDo) { if (entityId != editedToDo.TaskId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(editedToDo); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (ToDoExist(editedToDo.TaskId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(List))); } return(View(editedToDo)); //if (editedToDo.ShortName != null && editedToDo.Description != null) //{ // var toDoEntityToReplace = await _context.ToDo.SingleOrDefaultAsync(p => p.TaskId == entityId); // toDoEntityToReplace.ShortName = editedToDo.ShortName; // toDoEntityToReplace.Description = editedToDo.Description; // return RedirectToAction("List"); //} //ModelState.ClearValidationState("ShortName"); //ModelState.ClearValidationState("Description"); //return View(ToDoList[entityId]); }
public void Update(ToDoItem entity) { var item = _context.ToDoItems.Find(entity.ToDoItemId); if (!string.IsNullOrWhiteSpace(entity.TaskName)) { item.TaskName = entity.TaskName; } if (!string.IsNullOrWhiteSpace(entity.Content)) { item.Content = entity.Content; } if (entity.DeadLine != null) { item.DeadLine = entity.DeadLine; } item.Updated = DateTime.Now; item.IsComplete = entity.IsComplete; _context.Update(item); _context.SaveChanges(); }
public IActionResult Put([FromBody] ToDoItem todo) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var toDoItem = _context.ToDoItems.FirstOrDefault(a => a.Id == todo.Id); if (toDoItem == null) { toDoItem = new ToDoItem(); } toDoItem.Title = todo.Title; toDoItem.status = todo.status; toDoItem.Description = todo.Description; toDoItem.StartDate = todo.StartDate; toDoItem.TargetDate = toDoItem.TargetDate; _context.Update(toDoItem); _context.SaveChanges(); return(NoContent()); }
public async Task <IActionResult> PatchToDoItemAsync(Guid key, Delta <ToDoItem> delta) { await LogRequestAsync(Request); if (delta.GetChangedPropertyNames().Contains("Id")) { return(BadRequest()); } var item = await _context.ToDoItems.FindAsync(key); if (item == null) { return(NotFound()); } delta.Patch(item); _context.Update(item); try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ToDoItemExists(key)) { return(NotFound()); } else { throw; } } return(Updated(item)); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } if (Item.From > Item.To) { ModelState.AddModelError("Item.To", "End date should be greater than start date"); return(Page()); } if (Item.Id == 0) { todos.ToDo.Add(Item); } else { //TODO: better to fetch and then update todos.Update(Item); } await todos.SaveChangesAsync(); return(RedirectToPage("./Index")); }
public void Update(Table table) { using var context = new ToDoContext(); context.Update(table); context.SaveChanges(); }