示例#1
0
        public IActionResult GetProductsByBrandId(Guid brandId, [FromQuery] ProductSearchParams productSearchParams)
        {
            Brand brand = _repository.GetBrandById(brandId);

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

            if (productSearchParams == null)
            {
                return(Ok(_mapper.Map <IEnumerable <ProductReadDto> >(_repository.GetProductsOfBrand(brandId))));
            }

            var productsOfBrandQuery = _repository.GetProductsOfBrandWithParams(brandId, productSearchParams);

            if (productSearchParams.Fields == null)
            {
                return(Ok(_mapper.Map <IEnumerable <ProductReadDto> >(productsOfBrandQuery)));
            }

            List <ExpandoObject> list = new List <ExpandoObject>();

            foreach (Product product in productsOfBrandQuery)
            {
                ProductReadDto pr = _mapper.Map <ProductReadDto>(product);
                list.Add(pr.ShapeData(productSearchParams.Fields));
            }

            return(Ok(list));
        }
示例#2
0
        public ActionResult UpdateProduct(Guid brandId, Guid productId, ProductUpdateDto productUpdateDto)
        {
            Brand brand = _repository.GetBrandById(brandId);

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

            Product productOfBrand = _repository.GetProductById(productId);

            //put upserting
            if (productOfBrand == null)
            {
                Product product = _mapper.Map <Product>(productUpdateDto);
                product.Id = productId;
                _repository.AddProduct(brandId, product);
                _repository.SaveChanges();

                ProductReadDto productRead = _mapper.Map <ProductReadDto>(product);

                return(CreatedAtRoute("GetProduct", new { brandId, productId = productRead.Id }, productRead));
            }

            _mapper.Map(productUpdateDto, productOfBrand);
            _repository.UpdateProduct(productOfBrand);
            _repository.SaveChanges();
            return(NoContent());
        }
示例#3
0
        public ActionResult <ProductReadDto> CreateProduct(Guid brandId, ProductCreateDto productCreateDto)
        {
            Brand brand = _repository.GetBrandById(brandId);

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

            Product createdProduct = _mapper.Map <Product>(productCreateDto);

            _repository.AddProduct(brandId, createdProduct);
            _repository.SaveChanges();
            ProductReadDto productReadDto = _mapper.Map <ProductReadDto>(createdProduct);

            return(CreatedAtRoute("GetProduct", new { brandId, productId = productReadDto.Id }, productReadDto));
        }
示例#4
0
 public Task SendBidUpdate(ProductReadDto Product)
 {
     return(Clients.All.SendAsync("ReceiveProduct", Product));
 }