예제 #1
0
        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);
        }
예제 #2
0
        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"));
            }
        }
예제 #3
0
        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)));
        }