public async Task <IActionResult> LinkCustomerSalesRep(long custId, long salesId) { var cust = await _context.CustomerList.FindAsync(custId); var sale = await _context.SalesList.FindAsync(salesId); if (cust == null || sale == null) { return(NotFound("Resource not found")); } if (cust.saleIdList.Length > 0) { cust.saleIdList = cust.saleIdList.ToString() + "," + salesId.ToString(); } else { cust.saleIdList = salesId.ToString(); } _context.CustomerList.Attach(cust); _context.Entry(cust).State = EntityState.Modified; if (sale.custIdList.Length > 0) { sale.custIdList = sale.custIdList.Length.ToString() + "," + custId.ToString(); } else { sale.custIdList = custId.ToString(); } _context.SalesList.Attach(sale); _context.Entry(sale).State = EntityState.Modified; await _context.SaveChangesAsync(); return(NoContent()); }
public bool UpdateProduct(int id, [FromBody] Product request) { var product = _context.ProductItems.Find(id); if (product == null) { return(false); } else { product.Name = request.Name; product.Description = request.Description; _context.ProductItems.Attach(product); _context.Entry(product).State = EntityState.Modified; _context.SaveChangesAsync(); return(true); } }