Example #1
0
        public async Task <IActionResult> PutProduct(int id, ProductDTO product)
        {
            if (id != product.ID)
            {
                return(BadRequest());
            }

            try
            {
                ProductDTO oldProduct = await _productRepository.GetByID(id);

                if (product.Price != oldProduct.Price)
                {
                    await _priceHistoryRepository.Create(_mapper.Map(oldProduct, new PriceHistoryDTO()));
                }

                product = await CreateAndSetCategory(product);

                product = await CreateAndSetBrand(product);

                await _productRepository.Update(id, product);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!await _productRepository.EntityExists(id))
                {
                    return(NotFound());
                }

                throw;
            }

            return(NoContent());
        }
Example #2
0
        public async Task <ActionResult <PriceHistoryDTO> > PostPriceHistory(PriceHistoryDTO priceHistory)
        {
            await _priceHistoryRepository.Create(priceHistory);

            return(CreatedAtAction("GetPriceHistory", new { id = priceHistory.ID }, priceHistory));
        }