示例#1
0
        public async Task <ActionResult> GetCollection(Guid id, CancellationToken token)
        {
            var collection = await collectionStorage.FindCollection(id, token);

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

            if (User.Owns(collection))
            {
                return(Ok(collection));
            }
            return(Forbid());
        }
示例#2
0
        public async Task <ActionResult> CreateCard([FromBody] CardDto cardDto, CancellationToken token)
        {
            var newCard    = new Card(cardDto.CollectionId, cardDto.Word, cardDto.Translation, cardDto.Img, User.Identity.Name);
            var collection = await collectionStorage.FindCollection(cardDto.CollectionId, token);

            if (collection == null)
            {
                return(UnprocessableEntity("collection does not exist"));
            }
            if (!User.Owns(collection))
            {
                return(Forbid());
            }

            await cardStorage.AddCard(newCard, token);

            var response = new
            {
                idCard = newCard.Id
            };

            return(Ok(response));
        }