public async Task <IActionResult> DeleteProductsById(int productid) { ProductWebApiContext productWebApiContext = new ProductWebApiContext(conn.DefaultConnection); var product = await(from p in productWebApiContext.Product where p.Id == productid select p).ToListAsync(); if (product == null) { return(NotFound()); } productWebApiContext.Remove(product.FirstOrDefault()); if (await productWebApiContext.SaveChangesAsync() <= 0) { return(StatusCode(500, $"删除产品{product.First().Id}失败")); } return(NoContent()); }
public IActionResult DeleteMaterialById(int productid, int materialid) { ProductWebApiContext productWebApiContext = new ProductWebApiContext(conn.DefaultConnection); var product = (from p in productWebApiContext.Product where p.Id == productid select p).FirstOrDefault(); if (product == null) { return(NotFound()); } var material = (from m in productWebApiContext.Material where m.Id == materialid select m).FirstOrDefault(); if (material == null) { return(NotFound()); } productWebApiContext.Remove(material); productWebApiContext.SaveChanges(); return(Ok()); }