コード例 #1
0
ファイル: CatalogController.cs プロジェクト: mnbuhl/UpgradR
        public async Task <ActionResult <ProductResponseDto> > Create([FromBody] ProductCommandDto productRequest)
        {
            if (!ModelState.IsValid)
            {
                _logger.LogError("Attempted to create product with bad ModelState");
                return(BadRequest(ModelState));
            }

            var product = _mapper.Map <Product>(productRequest);
            await _productRepository.CreateProduct(product);

            var productResponse = _mapper.Map <ProductResponseDto>(product);

            return(CreatedAtRoute("GetById", new { id = product.Id }, productResponse));
        }
コード例 #2
0
ファイル: CatalogController.cs プロジェクト: mnbuhl/UpgradR
        public async Task <ActionResult> Update([FromBody] ProductCommandDto productRequest)
        {
            if (!ModelState.IsValid)
            {
                _logger.LogError("Attempted to update product with bad ModelState");
                return(BadRequest(ModelState));
            }

            var product = _mapper.Map <Product>(productRequest);

            bool updated = await _productRepository.UpdateProduct(product);

            if (!updated)
            {
                return(NotFound());
            }

            return(NoContent());
        }