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 })); } }
public async Task <IActionResult> AddCollectionAsync(NewCollectionDto dto) { var result = await _collectionService.AddCollectionAsync(dto); return(ApiResult(result)); }