Program.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. using api_asp.net.models;
  2. using Dapper;
  3. using MySqlConnector;
  4. var builder = WebApplication.CreateBuilder(args);
  5. var app = builder.Build();
  6. var dbDataProvider = new DBDataProvider();
  7. app.MapGet("/product", (int? pageNum) =>
  8. {
  9. return dbDataProvider.getProduct(pageNum ?? 1);
  10. });
  11. app.MapPost("/product", (Product newProduct) =>
  12. {
  13. dbDataProvider.saveProduct(newProduct);
  14. });
  15. app.MapDelete(
  16. "/product/{id:int}",
  17. (int id) =>
  18. {
  19. dbDataProvider.removeProduct(id);
  20. });
  21. app.MapPut("/product", (Product editProduct) =>
  22. {
  23. dbDataProvider.saveProduct(editProduct);
  24. });
  25. app.MapGet("/productCount", () =>
  26. {
  27. return dbDataProvider.getProductCount();
  28. });
  29. app.MapPut("/minCostForAgent/{minCost:decimal}", (decimal minCost, int[] ids) =>
  30. {
  31. dbDataProvider.setMinCostForAgent(minCost, ids);
  32. });
  33. app.MapGet("/saleCount/{ID:int}", (int ID) =>
  34. {
  35. return dbDataProvider.saleCount(ID);
  36. });
  37. app.MapDelete("/productMaterial/{ID:int}", (int ID) =>
  38. {
  39. dbDataProvider.removeProductMaterial(ID);
  40. });
  41. app.MapDelete("/PriceHistory/{ID:int}", (int ID) =>
  42. {
  43. dbDataProvider.removePriceHistory(ID);
  44. });
  45. app.MapGet("/productMaterial/{ID:int}", (int ID) =>
  46. {
  47. return dbDataProvider.getProductMaterials(ID);
  48. });
  49. app.MapGet("/AvailableMaterials", () =>
  50. {
  51. return dbDataProvider.getAvailableMaterials();
  52. });
  53. app.MapGet("/ProductTypes", () =>
  54. {
  55. return dbDataProvider.getProductTypes();
  56. });
  57. app.MapPost("/productMaterial", (ProductMaterial material) =>
  58. {
  59. dbDataProvider.addProductMaterial(material);
  60. });
  61. app.MapPut("/setOrder", (string condition) =>
  62. {
  63. dbDataProvider.setOrder(condition);
  64. });
  65. app.MapPut("/addFilter", (string name, object value) =>
  66. {
  67. dbDataProvider.addFilter(name, value);
  68. });
  69. app.MapPut("/clearFilter", () =>
  70. {
  71. dbDataProvider.clearFilter();
  72. });
  73. app.Run();