Ejemplo n.º 1
0
        public async Task <IActionResult> UpdatePrice([FromRoute] Guid businessId, [FromRoute] Guid productId, [FromBody] UpdateProductPrice request)
        {
            var response = await ProductService.UpdatePrice(businessId, productId, request);

            return(Ok(response));
        }
Ejemplo n.º 2
0
        public async Task <GlobalResponse> UpdatePrice(Guid businessId, Guid productId, UpdateProductPrice price)
        {
            var business = await DbContext.Businesses.Include(x => x.Products).SingleOrDefaultAsync(x => x.Id == businessId);

            if (business is null)
            {
                throw new KeyNotFoundException("Invalid Business Id");
            }

            var product = await DbContext.Products.SingleOrDefaultAsync(x => x.Id == productId && x.BusinessId == business.Id);

            product.Price = price.NewPrice;
            DbContext.Update(product);
            await DbContext.SaveChangesAsync();

            return(new GlobalResponse {
                Message = "successful", Status = true
            });
        }