public async Task CreateCatalogAsyncCallsMethodOfRepository_And_SavesChanges() { await _service.CreateCatalogAsync(new CatalogDto()); _catalogRepositoryMock.Verify(r => r.Add(It.IsAny <Catalog>()), Times.Once); _dbContextMock.Verify(r => r.SaveChangesAsync(CancellationToken.None), Times.Once); }
public async Task <IActionResult> CreateCatalogAsync(CatalogsEntity catalog) { if (!_catalogService.CheckIfCatalogExit(catalog)) { var model = await _catalogService.CreateCatalogAsync(catalog); var location = _linkGanarator.GetPathByAction("GetCatalogByIdAsync", "Catalogs", new { id = model.CatalogId }); return(Created(location, model)); } else { return(BadRequest("catalog has already been created")); } }
public async Task <IActionResult> CreateCatalog([FromBody, Bind("Title", "ParentCatalogId")] CatalogViewModel model) { if (!ModelState.IsValid) { return(BadRequest()); } var catalog = _mapper.Map <Catalog>(model); if (!string.IsNullOrWhiteSpace(model.ParentCatalogId)) { var parentCatalog = _catalogService.FindCatalogId(model.ParentCatalogId); catalog.ParentCatalog = parentCatalog; } await _catalogService.CreateCatalogAsync(catalog); return(Created("", _mapper.Map <CatalogViewModel>(catalog))); }