示例#1
0
        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);
        }
示例#2
0
        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);
                }
            }
        }
        public async Task <ActionResult <TodoQuery> > CreateQueryAsync([FromBody] TodoQuery query)
        {
            // adjust predicate positions to match their positions in collection
            PositionAdjuster.AdjustChildren(query.Predicates.ToList <ISortable>());

            await _context.TodoQueries.AddAsync(query);

            await _context.SaveChangesAsync();

            return(CreatedAtRoute("GetQuery", new { id = query.Id }, query));
        }
        public async Task <ActionResult <DashboardFolder> > CreateFolderAsync([FromBody] DashboardFolder folder)
        {
            var folders = await _context.Folders.GetAsync();

            PositionAdjuster.AdjustForCreate(folder, folders.ToList <ISortable>(), folder.Definitions.ToList <ISortable>());

            await _context.Folders.AddAsync(folder);

            await _context.SaveChangesAsync();

            return(CreatedAtRoute("GetFolder", new { id = folder.Id }, folder));
        }
示例#5
0
        public async Task <ActionResult <DashboardDefinition> > CreateDefinitionAsync([FromBody] DashboardDefinition definition)
        {
            var definitions = await _context.Definitions.GetAsync(d => d.DashboardFolderId == definition.DashboardFolderId);

            PositionAdjuster.AdjustForCreate(definition, definitions.ToList <ISortable>(), definition.Tiles.ToList <ISortable>());

            await _context.Definitions.AddAsync(definition);

            await _context.SaveChangesAsync();

            return(CreatedAtRoute("GetDefinition", new { id = definition.Id }, definition));
        }
示例#6
0
        public async Task <ActionResult <TodoList> > CreateListAsync([FromBody] TodoList list)
        {
            var lists = await _context.TodoLists.GetAsync(l => l.Id != DefaultList.id);

            PositionAdjuster.AdjustForCreate(list, lists.ToList <ISortable>(), list.Items.ToList <ISortable>());

            await _context.TodoLists.AddAsync(list);

            await _context.SaveChangesAsync();

            return(CreatedAtRoute("GetList", new { id = list.Id }, list));
        }
示例#7
0
        public async Task <ActionResult <TodoListItem> > CreateItemAsync([FromBody] TodoListItem item)
        {
            // sort items based on requested position
            var items = await _context.TodoItems.GetAsync(t => t.TodoListId == item.TodoListId);

            PositionAdjuster.AdjustForCreate(item, items.ToList <ISortable>());

            await _context.TodoItems.AddAsync(item);

            await _context.SaveChangesAsync();

            return(CreatedAtRoute("GetItem", new { id = item.Id }, item));
        }
        public async Task <ActionResult <DashboardFolder> > UpdateFolderAsync(int id, [FromBody] DashboardFolder folder)
        {
            var current = await FetchFolderAsync(id);

            if (current == null)
            {
                return(NotFound());
            }

            var folders = await _context.Folders.GetAsync();

            PositionAdjuster.AdjustForUpdate(folder, folders.ToList <ISortable>(), current, folder.Definitions.ToList <ISortable>());

            current.UpdateFrom(folder);
            _context.Folders.Update(current);
            await _context.SaveChangesAsync();

            return(current);
        }
示例#9
0
        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);
        }
示例#10
0
        public async Task <ActionResult <TodoQuery> > UpdateQueryAsync(int id, [FromBody] TodoQuery query)
        {
            var current = await FetchQueryAsync(id);

            if (current == null)
            {
                return(NotFound());
            }

            // adjust predicate positions to match their positions in collection
            PositionAdjuster.AdjustChildren(query.Predicates.ToList <ISortable>());

            current.UpdateFrom(query);

            _context.TodoQueries.Update(current);
            await _context.SaveChangesAsync();

            return(current);
        }
        public async Task <ActionResult <FolderElement> > UpdateFolderElementAsync(int id, [FromBody] FolderElement element)
        {
            var current = await FetchFolderAsync(id);

            if (current == null)
            {
                return(NotFound());
            }

            var folders = await _context.Folders.GetAsync();

            PositionAdjuster.AdjustForUpdate(element, folders.ToList <ISortable>(), current);

            current.UpdateFrom(element);

            _context.Folders.Update(current);
            await _context.SaveChangesAsync();

            return(current.ToElement());
        }
示例#12
0
        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);
            }
        }
示例#14
0
        public async Task <ActionResult <TodoListItem> > UpdateItemAsync(int id, [FromBody] TodoListItem item)
        {
            var current = await _context.TodoItems.GetAsync(id);

            if (current == null)
            {
                return(NotFound());
            }

            // update item positions for todo list
            var items = await _context.TodoItems.GetAsync(t => t.TodoListId == item.TodoListId);

            PositionAdjuster.AdjustForUpdate(item, items.ToList <ISortable>(), current);
            current.UpdateFrom(item);

            _context.TodoItems.Update(current);
            await _context.SaveChangesAsync();

            return(current);
        }
示例#15
0
        public async Task <ActionResult <TodoItemReference> > MoveReferenceAsync(int id, [FromBody] TodoItemReference reference)
        {
            var current = await _context.TodoReferences.GetAsync(id);

            if (current == null)
            {
                return(NotFound());
            }

            // re-arrange other references affected by move
            var references = await _context.TodoReferences.GetAsync(r => r.TodoQueryId == reference.TodoQueryId);

            PositionAdjuster.AdjustForUpdate(reference, references.ToList <ISortable>(), current);

            // move reference to desired location
            current.UpdateFrom(reference);

            _context.TodoReferences.Update(current);
            await _context.SaveChangesAsync();

            return(current);
        }
示例#16
0
        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);
        }
示例#17
0
        public async Task <ActionResult <TodoList> > UpdateListAsync(int id, [FromBody] TodoList list)
        {
            var current = await FetchTodoListAsync(id);

            if (current == null)
            {
                return(NotFound());
            }

            if (id != DefaultList.id)
            {
                // if default list being updated, no need to mess with list ordering
                var lists = await _context.TodoLists.GetAsync(l => l.Id != DefaultList.id);

                PositionAdjuster.AdjustForUpdate(list, lists.ToList <ISortable>(), current, list.Items.ToList <ISortable>());
            }

            current.UpdateFrom(list);
            _context.TodoLists.Update(current);
            await _context.SaveChangesAsync();

            return(current);
        }
示例#18
0
        public async Task <ActionResult <TodoElement> > UpdateListElementAsync(int id, [FromBody] TodoElement element)
        {
            var current = await _context.TodoLists.GetAsync(id, s => s.Items);

            if (current == null)
            {
                return(NotFound());
            }

            if (id != DefaultList.id)
            {
                // if default list is being updated, no need to adjust other lists positions
                var lists = await _context.TodoLists.GetAsync(l => l.Id != DefaultList.id);

                PositionAdjuster.AdjustForUpdate(element, lists.ToList <ISortable>(), current);
            }

            current.UpdateFrom(element);
            _context.TodoLists.Update(current);
            await _context.SaveChangesAsync();

            return(current.ToElement());
        }
        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());
        }
示例#20
0
 private void Start()
 {
     playerSpawnManager = facade.GetComponent <MainPlayerSpawnManager>();
     spawnManager       = facade.GetComponent <PlayerSpawnManager>();
     adjuster           = facade.GetComponent <PositionAdjuster>();
 }