예제 #1
0
        public async Task <ActionResult <CardsCollection> > CreateDefaultAsync(CancellationToken cancellationToken)
        {
            try
            {
                Guid.TryParse(HttpContext.User.Identity.Name, out var uId);
                if (await collectionService.IsNameExistAsync(defaultCollectionName, uId))
                {
                    return(BadRequest(new { message = $"Коллекция с именем \"{defaultCollectionName}\" уже существует" }));
                }

                var cardCollection = collectionService.CreateCollection(uId, defaultCollectionName);
                if (await collectionService.AddCollectionAsync(cardCollection))
                {
                    return(Ok(cardCollection));
                }
                throw new AppException("Не получилось создать коллекцию");
            }
            catch (AppException ex)
            {
                return(BadRequest(new { message = ex.Message }));
            }
        }
        public async Task <ActionResult <CardsCollection> > CreateDefaultAsync(CancellationToken cancellationToken)
        {
            try
            {
                Guid.TryParse(HttpContext.User.Identity.Name, out var uId);
                if (await collectionService.IsNameExistAsync(defaultCollectionName, uId))
                {
                    return(BadRequest(new { message = "Default collection already exists" }));
                }

                var cardCollection = collectionService.CreateCollection(uId, defaultCollectionName);
                if (await collectionService.AddCollectionAsync(cardCollection))
                {
                    return(Ok(cardCollection));
                }
                throw new AppException("Couldn't create collection");
            }
            catch (AppException ex)
            {
                return(BadRequest(new { message = ex.Message }));
            }
        }
예제 #3
0
        public async Task <IActionResult> AddCollectionAsync(NewCollectionDto dto)
        {
            var result = await _collectionService.AddCollectionAsync(dto);

            return(ApiResult(result));
        }