public IActionResult CreateProductionArea([FromBody] ProductionAreaCRUD newProductionArea)
        {
            if (newProductionArea == null || EqualityComparer <ProductionAreaCRUD> .Default.Equals(newProductionArea, default(ProductionAreaCRUD)))
            {
                return(BadRequest());
            }


            var _productionArea = _mapper.Map <ProductionArea>(newProductionArea);


            var resultProductionAreaCreated = _productionAreaRepository.CreateProductionArea(_productionArea);

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


            _productionAreaRepository.Save();

            var productionAreaTO = _mapper.Map <ProductionAreaTO>(_productionArea);

            return(CreatedAtRoute("GetProductionArea"
                                  , new { productionAreaId = productionAreaTO.Id }
                                  , productionAreaTO
                                  ));
        }
示例#2
0
        public IActionResult AddProductionArea([FromBody] ProductionAreaToUpsert productionAreaToAdd)
        {
            if (productionAreaToAdd == null)
            {
                return(BadRequest());
            }

            var productionArea = _mapper.Map <ProductionArea>(productionAreaToAdd);

            if (productionArea.StoreId == Guid.Empty)
            {
                return(new UnprocessableEntityResult(ModelState));
            }

            _productionAreaRepository.Add(productionArea);
            _productionAreaRepository.Save();

            var productionAreaToGet = _mapper.Map <ProductionAreaToGet>(productionArea);

            return(CreatedAtRoute("GetProductionArea",
                                  new { id = productionAreaToGet.ProductionAreaId },
                                  productionAreaToGet));
        }