public void Delete(long id) { ToDo thing = context.ToDos.Single(c => c.Id == id); context.Remove(thing); context.SaveChanges(); }
public async Task deleteTodoList(int userid, int todoListID) { var userexists = _toDoContext.Users.Where(a => a.ID == userid).First(); var listexists = _toDoContext.TodoLists.Where(a => a.TodoListID == todoListID).First(); if (userexists == null || listexists == null) { throw new Exception(); } else { _toDoContext.Remove(listexists); await _toDoContext.SaveChangesAsync(); } }
public async Task DeleteAsync(int toDoId, CancellationToken ct = default(CancellationToken)) { var toDoItem = await _uow.ToDoItems.SingleAsync(t => t.Id == toDoId, ct); _uow.Remove(toDoItem); await _uow.SaveChangesAsync(ct); }
public void DeleteToDo(int todoId) { var currToDo = context.ToDos.Where(t => t.Id == todoId).FirstOrDefault(); context.Remove(currToDo); context.SaveChanges(); }
public async Task <IActionResult> deleteList(int listId) { User user = await _context.users.Include(u => u.lists).FirstOrDefaultAsync(u => u.id == currentUser); if (user == default(User)) { return(Json(new jsonResponse { success = false, errMsg = "Invalid UID" })); } ToDoList list = await _context.lists.Include(l => l.items).FirstOrDefaultAsync(l => l.id == listId); if (list == default(ToDoList) && !user.lists.Contains(list)) { return(Json(new jsonResponse { success = false, errMsg = "List does not exist" })); } try { _context.Remove(list); // remove list - cascade delete removes items _context.SaveChanges(); } catch { return(Json(new jsonResponse { success = false, errMsg = "Failed to delete list" })); } return(Json(new jsonResponse { success = true })); }
public void Delete(long id) { ToDo thing = context.ToDos.FirstOrDefault(c => c.Id == id); context.Remove(thing); context.SaveChanges(); }
public void DeleteToDo(int id) { var item = _context.ToDoItems.Find(id); _context.Remove(item); _context.SaveChanges(); }
public void Remove(IBaseModel removedItem) { using (var context = new ToDoContext()) { var deletedEntity = _mapper.Map <TodoItems>(removedItem); context.Remove(deletedEntity); context.SaveChanges(); } }
public async Task <ActionResult> Delete(int Id) { //Console.WriteLine(Id); TodoList item = await context.ToDoLists.FindAsync(Id); context.Remove(item); await context.SaveChangesAsync(); return(RedirectToAction("Index")); }
public virtual async Task Delete <T>(int key) where T : class { T existing = _context.Set <T>().Find(key); if (existing != null) { _context.Remove(existing); await _context.SaveChangesAsync(); } }
public void DeleteToDo(long id) { foreach (var item in toDoContext.ToDos) { if (item.Id == id) { toDoContext.Remove(item); } } toDoContext.SaveChanges(); }
public async Task DeleteToDoItemByIdAsync(int id) { var item = await _toDoContext.ToDoItems.SingleOrDefaultAsync(item => item.Id == id); if (item == null) { throw new NotFoundException($"{id} does not exist"); } _toDoContext.Remove(item); await _toDoContext.SaveChangesAsync(); }
public IActionResult DeleteToDo(int id) { var toDo = _context.ToDos.FirstOrDefault(x => x.Id == id); if (toDo == null) { return(NotFound()); } _context.Remove(toDo); _context.SaveChanges(); return(NoContent()); }
public static async Task DeleteToDoItem(ToDoItemModel toDoDelete) { try { await using var toDoContext = new ToDoContext(); toDoContext.Remove(toDoDelete); await toDoContext.SaveChangesAsync(); PostToDoItem(toDoContext); } catch (Exception ex) { //Handle exception - Typically I use a service like rollbar Debug.WriteLine(ex); } }
public async Task <ActionResult <ToDoItem> > DeleteTask(int id) { if (ModelState.IsValid) { var toDoItem = await _toDoContext.ToDoItems.FindAsync(id); _toDoContext.Remove(toDoItem); var output = await _toDoContext.SaveChangesAsync(); if (output > 0) { return(Ok("ToDo deleted successfully")); } } return(BadRequest("Some error happened")); }
public void Delete <T>(T entity) where T : class { _context.Remove(entity); }
public void DeleteToDo(int id) { _context.Remove(GetToDo(id)); }