Exemple #1
0
        [HttpGet("/table/{tableID}/{listID}/move")] //?toList=&cardIndex=&newCardIndex=
        public async Task <IActionResult> MoveCard([FromRoute] string tableID, [FromRoute] string listID, [FromQuery(Name = "toList")] string toListID, [FromQuery] int cardIndex, [FromQuery] int newCardIndex)
        {
            ObjectId table = new ObjectId(tableID);

            if (cardIndex < 0 || newCardIndex < 0)
            {
                return(BadRequest());
            }

            if (listID == toListID)
            {
                CardList list = CardListCollection.FindListByTableAndId(table, new ObjectId(listID));
                if (list == null || list.Content.Count <= cardIndex)
                {
                    return(BadRequest());
                }

                Card card = list.Content[cardIndex];
                list.Content.RemoveAt(cardIndex);
                list.Content.Insert(newCardIndex, card);

                if (!CardListCollection.UpdateContent(list))
                {
                    return(BadRequest());
                }
            }
            else
            {
                CardList fromList = CardListCollection.FindListByTableAndId(table, new ObjectId(listID));
                if (fromList == null || fromList.Content.Count <= cardIndex)
                {
                    return(BadRequest());
                }

                CardList toList = CardListCollection.FindListByTableAndId(table, new ObjectId(toListID));
                if (toList == null)
                {
                    return(BadRequest());
                }

                Card card = fromList.Content[cardIndex];
                fromList.Content.RemoveAt(cardIndex);

                toList.Content.Insert(newCardIndex, card);

                if (!CardListCollection.UpdateContent(fromList))
                {
                    return(BadRequest());
                }
                if (!CardListCollection.UpdateContent(toList))
                {
                    return(BadRequest());
                }
            }

            return(Ok(CardListCollection.FindAllInTable(new ObjectId(tableID))));
        }
Exemple #2
0
 public List <CardList> GetLists([FromRoute] string tableID)
 {
     return(CardListCollection.FindAllInTable(new ObjectId(tableID)));
 }