public async Task <IActionResult> PutContractorProductPrice(int id, ContractorProductPrice contractorProductPrice) { if (id != contractorProductPrice.ID) { return(BadRequest()); } contractorProductPrice.Product = await _context.Products.FirstOrDefaultAsync(x => x.ID == contractorProductPrice.Product.ID); contractorProductPrice.Contractor = await _context.Contractors.FirstOrDefaultAsync(x => x.ID == contractorProductPrice.Contractor.ID); _context.Entry(contractorProductPrice).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ContractorProductPriceExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <ContractorProductPrice> > PostContractorProductPrice(ContractorProductPrice contractorProductPrice) { contractorProductPrice.Product = await _context.Products.FirstOrDefaultAsync(x => x.ID == contractorProductPrice.Product.ID); contractorProductPrice.Contractor = await _context.Contractors.FirstOrDefaultAsync(x => x.ID == contractorProductPrice.Contractor.ID); _context.ContractorProductPrices.Add(contractorProductPrice); await _context.SaveChangesAsync(); return(CreatedAtAction("GetContractorProductPrice", new { id = contractorProductPrice.ID }, contractorProductPrice)); }