Program.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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.MapPut("/product", (Product editProduct) =>
  26. {
  27. dbDataProvider.saveProduct(editProduct);
  28. });
  29. app.MapGet("/productCount", () =>
  30. {
  31. return dbDataProvider.getProductCount();
  32. });
  33. app.MapPut("/minCostForAgent/{minCost:decimal}", (decimal minCost, int[] ids) =>
  34. {
  35. dbDataProvider.setMinCostForAgent(minCost, ids);
  36. });
  37. app.MapGet("/saleCount/{ID:int}", (int ID) =>
  38. {
  39. return dbDataProvider.saleCount(ID);
  40. });
  41. app.MapDelete("/productMaterial/{ID:int}", (int ID) =>
  42. {
  43. dbDataProvider.removeProductMaterial(ID);
  44. });
  45. app.MapDelete("/PriceHistory/{ID:int}", (int ID) =>
  46. {
  47. dbDataProvider.removePriceHistory(ID);
  48. });
  49. app.MapGet("/productMaterial/{ID:int}", (int ID) =>
  50. {
  51. return dbDataProvider.getProductMaterials(ID);
  52. });
  53. app.MapGet("/AvailableMaterials", () =>
  54. {
  55. return dbDataProvider.getAvailableMaterials();
  56. });
  57. app.MapGet("/ProductTypes", () =>
  58. {
  59. return dbDataProvider.getProductTypes();
  60. });
  61. app.MapPost("/productMaterial", (ProductMaterial material) =>
  62. {
  63. dbDataProvider.addProductMaterial(material);
  64. });
  65. app.MapPut("/setOrder", (string condition) =>
  66. {
  67. dbDataProvider.setOrder(condition);
  68. });
  69. app.MapPut("/addFilter", (string name, object value) =>
  70. {
  71. dbDataProvider.addFilter(name, value);
  72. });
  73. app.MapPut("/clearFilter", () =>
  74. {
  75. dbDataProvider.clearFilter();
  76. });
  77. app.Run();