FlowerController.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using Microsoft.AspNetCore.Mvc;
  2. using Microsoft.AspNetCore.Mvc.Filters;
  3. using Microsoft.AspNetCore.WebUtilities;
  4. using economy.Helpers;
  5. using economy.Models;
  6. using economy.Models.Price.Domestic;
  7. using economy.Models.Price.Domestic.Flower;
  8. namespace economy.Controllers.Price.Domestic
  9. {
  10. public class FlowerController : Controller
  11. {
  12. private readonly FlowerAtOrKR _flowerAtOrKR;
  13. private Dictionary<string, string> _queryString;
  14. public FlowerController(FlowerAtOrKR flowerAtOrKR)
  15. {
  16. _flowerAtOrKR = flowerAtOrKR;
  17. _queryString = [];
  18. }
  19. public override void OnActionExecuting(ActionExecutingContext context)
  20. {
  21. _queryString = QueryHelpers.ParseQuery(HttpContext.Request.QueryString.Value).ToDictionary(k => k.Key, v => string.Join(",", v.Value));
  22. ViewBag.QueryString = _queryString;
  23. base.OnActionExecuting(context);
  24. }
  25. [HttpGet("Price/Domestic/Flower")]
  26. public async Task<IActionResult> Index(Request request)
  27. {
  28. if (!ModelState.IsValid)
  29. {
  30. return BadRequest(ModelState);
  31. }
  32. DomesticModel domesticModel = new DomesticModel(null, _flowerAtOrKR);
  33. Response itemList = await domesticModel.GetFlowerPriceInfo(request);
  34. if (itemList is not null)
  35. {
  36. int listNum = Common.CalcListNumber(itemList.NumberOfRows, request.PageNo, request.NumOfRows);
  37. itemList.Items = itemList.Items.Select((row, index) =>
  38. {
  39. row.Num = listNum - index;
  40. row.MaxAmt = Common.NumberFormat(row.MaxAmt);
  41. row.MinAmt = Common.NumberFormat(row.MinAmt);
  42. row.AvgAmt = Common.NumberFormat(row.AvgAmt);
  43. row.TotAmt = Common.NumberFormat(row.TotAmt);
  44. row.TotQty = Common.NumberFormat(row.TotQty);
  45. return row;
  46. }).ToList();
  47. }
  48. var viewModel = new View<Request, Response>();
  49. viewModel.SelectedListPerPage = request.NumOfRows;
  50. viewModel.Request = request;
  51. viewModel.Response = itemList;
  52. var queryString = new
  53. {
  54. date = request.BaseDate
  55. };
  56. var pagination = new Pagination(itemList?.NumberOfRows, request.PageNo, request.NumOfRows, queryString);
  57. viewModel.Pagination = pagination;
  58. return View("/Views/Price/Domestic/Flower.cshtml", viewModel);
  59. }
  60. }
  61. }