示例#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))));
        }
示例#2
0
        public async Task <IActionResult> CreateCard([FromRoute] string tableID, [FromRoute] string listID, [FromRoute] int cardIndex, [FromBody] CreateCardData data)
        {
            if (string.IsNullOrEmpty(data.Title))
            {
                return(BadRequest());
            }

            CardList list = CardListCollection.FindListByTableAndId(new ObjectId(tableID), new ObjectId(listID));

            list.Content[cardIndex] = new Card()
            {
                Title       = data.Title,
                Description = data.Description
            };

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

            return(Ok(list));
        }
示例#3
0
        public async Task <IActionResult> DeleteCard([FromRoute] string tableID, [FromRoute] string listID, [FromRoute] int cardIndex)
        {
            if (cardIndex < 0 || cardIndex < 0)
            {
                return(BadRequest());
            }

            CardList fromList = CardListCollection.FindListByTableAndId(new ObjectId(tableID), new ObjectId(listID));

            if (fromList == null || fromList.Content.Count <= cardIndex)
            {
                return(BadRequest());
            }

            fromList.Content.RemoveAt(cardIndex);

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

            return(Ok(CardListCollection.FindOneList(new ObjectId(tableID), new ObjectId(listID))));
        }