コード例 #1
0
        public async Task <ActionResult> AddCardToCollection(string id, string cardId,
                                                             CancellationToken cancellationToken)
        {
            try
            {
                Guid.TryParse(HttpContext.User.Identity.Name, out var userId);
                Guid.TryParse(cardId, out var cardGuid);
                Guid.TryParse(id, out var collectionId);

                if (!await collectionService.IsIdExistAsync(collectionId, userId))
                {
                    return(BadRequest(new { message = $"Нет коллекции с указанным идентификатором: \"{collectionId}\"" }));
                }

                if (await collectionService.AddCardToCollectionAsync(collectionId, cardGuid, userId))
                {
                    return(Ok());
                }

                throw new AppException("Не получилось добавить карту в коллекцию");
            }
            catch (AppException ex)
            {
                return(BadRequest(new { message = ex.Message }));
            }
        }
コード例 #2
0
        public async Task <ActionResult> AddCardToCollection(string collectionName, string cardId,
                                                             CancellationToken cancellationToken)
        {
            try
            {
                Guid.TryParse(HttpContext.User.Identity.Name, out var userId);
                Guid.TryParse(cardId, out var cardGuid);
                if (!await collectionService.IsNameExistAsync(collectionName, userId))
                {
                    return(BadRequest(new { message = "No collection with name \"" + collectionName + "\"" }));
                }

                if (await collectionService.AddCardToCollectionAsync(collectionName, cardGuid, userId))
                {
                    return(Ok());
                }

                throw new AppException("Couldn't add card to a collection");
            }
            catch (AppException ex)
            {
                return(BadRequest(new { message = ex.Message }));
            }
        }