Ejemplo n.º 1
0
        public ActionResult <ProductDto> CreateProductForCategory(Guid categoryId, ProductForUpdateAndCreateDto product)
        {
            var category = _categoryRepository.GetCategory(categoryId);

            if (category == null)
            {
                return(NotFound());
            }

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

            _productRepository.CreateProduct(categoryId, ProductEntity);
            _productRepository.Save();

            var ProductToReturn = _mapper.Map <ProductDto>(ProductEntity);

            return(CreatedAtRoute("GetProductForCategory", new { categoryId = categoryId, ProductToReturn.ProductId }, ProductToReturn));
        }
Ejemplo n.º 2
0
        public ActionResult UpdateProductForCategory(Guid productId, Guid categoryId, ProductForUpdateAndCreateDto product)
        {
            var Category = _categoryRepository.GetCategory(categoryId);

            if (Category == null)
            {
                return(NotFound());
            }
            var ProductForCategoryFromRepo = _productRepository.GetProduct(categoryId, productId);

            if (ProductForCategoryFromRepo == null)
            {
                return(NotFound());
            }
            _mapper.Map(product, ProductForCategoryFromRepo);
            // AutoMapper Here Is Used For update  , This Function Has No Implementation
            //_productRepository.UpdateProducts(product);
            _productRepository.Save();
            return(NoContent());
        }