public async Task <ActionResult <List <int> > > DeleteListsAsync([FromQuery(Name = "id")] List <int> ids) { var lists = await _context.TodoLists.GetAsync(l => l.Id != DefaultList.id); foreach (var id in ids) { if (id == DefaultList.id) { return(BadRequest("Cannot delete default list.")); } else { var list = lists.FirstOrDefault(t => t.Id == id); if (list == null) { return(NotFound()); } else { PositionAdjuster.AdjustForDelete(list, lists.ToList <ISortable>()); _context.TodoLists.Delete(list); } } } await _context.SaveChangesAsync(); return(ids); }
public async Task <ActionResult <int> > DeleteListAsync(int id) { if (id == DefaultList.id) { // we do not delete the default list return(BadRequest("Cannot delete default list")); } else { var list = await _context.TodoLists.GetAsync(id); if (list == null) { return(NotFound()); } else { var lists = await _context.TodoLists.GetAsync(l => l.Id != DefaultList.id); PositionAdjuster.AdjustForDelete(list, lists.ToList <ISortable>()); _context.TodoLists.Delete(list); await _context.SaveChangesAsync(); return(id); } } }
private async Task DeleteItem(TodoListItem item) { var items = await _context.TodoItems.GetAsync(t => t.TodoListId == item.TodoListId); PositionAdjuster.AdjustForDelete(item, items.ToList <ISortable>()); var references = await _context.TodoReferences.GetAsync(r => r.Item.Id == item.Id); foreach (var reference in references) { var group = await _context.TodoReferences.GetAsync(r => r.TodoQueryId == reference.TodoQueryId); PositionAdjuster.AdjustForDelete(reference, references.ToList <ISortable>()); _context.TodoReferences.Delete(reference); } _context.TodoItems.Delete(item); }
public async Task <ActionResult <int> > DeleteDefinitionAsync(int id) { var definition = await _context.Definitions.GetAsync(id); if (definition == null) { return(NotFound()); } else { var lists = await _context.Definitions.GetAsync(d => d.DashboardFolderId == definition.DashboardFolderId); PositionAdjuster.AdjustForDelete(definition, lists.ToList <ISortable>()); _context.Definitions.Delete(definition); await _context.SaveChangesAsync(); return(id); } }
public async Task <ActionResult <int> > DeleteFolderAsync(int id) { var folder = await _context.Folders.GetAsync(id); if (folder == null) { return(NotFound()); } else { var folders = await _context.Folders.GetAsync(); PositionAdjuster.AdjustForDelete(folder, folders.ToList <ISortable>()); _context.Folders.Delete(folder); await _context.SaveChangesAsync(); return(id); } }
MergeResultsAsync(int queryId, IList <TodoItemReference> lastResults, IList <TodoListItem> matchedItems) { // remove stale result items var mergedResults = new List <TodoItemReference>(); foreach (TodoItemReference result in lastResults) { var item = matchedItems.FirstOrDefault(i => i.Id == result.Item.Id); if (item != null) { // result still relevant, remove it from matching list matchedItems.Remove(item); mergedResults.Add(result); } else { // result is stale, remove it from result set PositionAdjuster.AdjustForDelete(result, lastResults.ToList <ISortable>()); _context.TodoReferences.Delete(result); } } // append new ones foreach (TodoListItem item in matchedItems) { var result = new TodoItemReference() { Item = item, Position = mergedResults.Count, TodoQueryId = queryId }; mergedResults.Add(result); await _context.TodoReferences.AddAsync(result); } return(mergedResults); }
public async Task <ActionResult <DefinitionElement> > UpdateDefinitionElementAsync(int id, [FromBody] DefinitionElement element) { var current = await _context.Definitions.GetAsync(id); if (current == null) { return(NotFound()); } if (current.DashboardFolderId == element.DashboardFolderId) { // not reparenting, adjust positions var newPeers = await _context.Definitions.GetAsync(d => d.DashboardFolderId == element.DashboardFolderId); PositionAdjuster.AdjustForUpdate(element, newPeers.ToList <ISortable>(), current); } else { // we are reparenting, adjust old peer positions var oldPeers = await _context.Definitions.GetAsync(d => d.DashboardFolderId == current.DashboardFolderId); PositionAdjuster.AdjustForDelete(current, oldPeers.ToList <ISortable>()); // and new peer positions var newPeers = await _context.Definitions.GetAsync(d => d.DashboardFolderId == element.DashboardFolderId); PositionAdjuster.AdjustForCreate(element, newPeers.ToList <ISortable>()); } current.UpdateFrom(element); _context.Definitions.Update(current); await _context.SaveChangesAsync(); return(current.ToElement()); }