Program.cs 642 B

1234567891011121314151617181920212223242526272829303132333435
  1. using WebApplication1.models;
  2. var builder = WebApplication.CreateBuilder(args);
  3. var app = builder.Build();
  4. // ñþäà áóäåì äîáàâëÿòü ñâîè êîíå÷íûå òî÷êè
  5. var dbDataProvider = new DBDataProvider();
  6. app.MapGet("/product", (int? pageNum) =>
  7. {
  8. return dbDataProvider.getProduct(pageNum ?? 1);
  9. });
  10. app.MapPost("/product", (Product newProduct) =>
  11. {
  12. dbDataProvider.saveProduct(newProduct);
  13. });
  14. app.MapPut("/product",
  15. (Product editProduct) =>
  16. {
  17. dbDataProvider.saveProduct(editProduct);
  18. });
  19. app.MapDelete(
  20. "/product/{id:int}",
  21. (int id) =>
  22. {
  23. dbDataProvider.removeProduct(id);
  24. });
  25. app.Run();