Example #1
0
        public async Task <IActionResult> PostProviderProduct([FromBody] ProviderProduct providerProduct)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.ProviderProduct.Add(providerProduct);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (ProviderProductExists(providerProduct.ProviderID))
                {
                    return(new StatusCodeResult(StatusCodes.Status409Conflict));
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetProviderProduct", new { id = providerProduct.ProviderID }, providerProduct));
        }
Example #2
0
        public async Task <IActionResult> PutProviderProduct([FromRoute] int id, [FromBody] ProviderProduct providerProduct)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != providerProduct.ProviderID)
            {
                return(BadRequest());
            }

            _context.Entry(providerProduct).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ProviderProductExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Example #3
0
        // изм количества товара на складе
        public decimal changeInStockAmount(int prodId, int providerId, int amount)
        {
            ProviderProduct element = context.ProviderProducts.FirstOrDefault(rec => rec.ProviderId == providerId && rec.ProductId == prodId);

            element.InStockAmount = element.InStockAmount - amount;
            context.SaveChanges();
            decimal totalPrice = element.Price * amount;

            return(totalPrice);
        }