Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.38 KB | None | 0 0
  1. public ActionResult Search(TE0004MerchantInfoViewModel model)
  2. {
  3. if (!ModelState.IsValid)
  4. {
  5. return View("Search", model);
  6. }
  7.  
  8. if (string.IsNullOrWhiteSpace(model.MerchantID1))
  9. {
  10. if (!string.IsNullOrWhiteSpace(model.MerchantID2))
  11. {
  12. ModelState.AddModelError("MerchantID1", "加盟店ID2を指定した場合、加盟店ID1は必ず指定してください。");
  13. return View("Search", model);
  14. }
  15.  
  16. if (!string.IsNullOrWhiteSpace(model.MerchantID3))
  17. {
  18. ModelState.AddModelError("MerchantID1", "加盟店ID3を指定した場合、加盟店ID1は必ず指定してください。");
  19. return View("Search", model);
  20. }
  21. }
  22.  
  23. TempData["TE0004MerchantInfo.SearchData"] = model;
  24. var query = db.TE0004MerchantInfo.AsQueryable();
  25.  
  26. if (!string.IsNullOrWhiteSpace(model.CustomerID))
  27. {
  28. query = query.Where(s => s.CustomerID == model.CustomerID);
  29. }
  30. if (!string.IsNullOrWhiteSpace(model.MerchantID1))
  31. {
  32. query = query.Where(s => s.MerchantID1 == model.MerchantID1);
  33. }
  34. if (!string.IsNullOrWhiteSpace(model.MerchantID2))
  35. {
  36. query = query.Where(s => s.MerchantID2 == model.MerchantID2);
  37. }
  38. if (!string.IsNullOrWhiteSpace(model.MerchantID3))
  39. {
  40. query = query.Where(s => s.MerchantID3 == model.MerchantID3);
  41. }
  42. if (model.Status.HasValue)
  43. {
  44. switch (model.Status.Value)
  45. {
  46. case -1: // エラーの場合
  47. query = query.Where(s => s.Status < 0);
  48. break;
  49. default:
  50. query = query.Where(s => s.Status == model.Status);
  51. break;
  52. }
  53. }
  54. if (model.RegistrationDateFrom.HasValue)
  55. {
  56. query = query.Where(s => s.RegistrationDate >= model.RegistrationDateFrom.Value);
  57. }
  58. if (model.RegistrationDateTo.HasValue)
  59. {
  60. query = query.Where(s => s.RegistrationDate < model.RegistrationDateTo.Value);
  61. }
  62. if (model.UpdateDateFrom.HasValue)
  63. {
  64. query = query.Where(s => s.UpdateDate >= model.UpdateDateFrom.Value);
  65. }
  66. if (model.UpdateDateTo.HasValue)
  67. {
  68. query = query.Where(s => s.UpdateDate < model.UpdateDateTo.Value);
  69. }
  70.  
  71. model.SearchResult = query.Count();
  72. if (model.SearchResult == 0)
  73. {
  74. ModelState.AddModelError("", Resources.Messages.SearchNotFound);
  75. return View("Search", model);
  76. }
  77.  
  78. if (model.SearchResult > 10000)
  79. {
  80. ModelState.AddModelError("", Resources.Messages.SearchTooManyNumber);
  81. return View("Search", model);
  82. }
  83.  
  84. model.TE0004MerchantInfoList =
  85. query.OrderBy(s => s.EntryDate);
  86.  
  87. return View("Search", model);
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement