Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public ActionResult Search(TE0004MerchantInfoViewModel model)
- {
- if (!ModelState.IsValid)
- {
- return View("Search", model);
- }
- if (string.IsNullOrWhiteSpace(model.MerchantID1))
- {
- if (!string.IsNullOrWhiteSpace(model.MerchantID2))
- {
- ModelState.AddModelError("MerchantID1", "加盟店ID2を指定した場合、加盟店ID1は必ず指定してください。");
- return View("Search", model);
- }
- if (!string.IsNullOrWhiteSpace(model.MerchantID3))
- {
- ModelState.AddModelError("MerchantID1", "加盟店ID3を指定した場合、加盟店ID1は必ず指定してください。");
- return View("Search", model);
- }
- }
- TempData["TE0004MerchantInfo.SearchData"] = model;
- var query = db.TE0004MerchantInfo.AsQueryable();
- if (!string.IsNullOrWhiteSpace(model.CustomerID))
- {
- query = query.Where(s => s.CustomerID == model.CustomerID);
- }
- if (!string.IsNullOrWhiteSpace(model.MerchantID1))
- {
- query = query.Where(s => s.MerchantID1 == model.MerchantID1);
- }
- if (!string.IsNullOrWhiteSpace(model.MerchantID2))
- {
- query = query.Where(s => s.MerchantID2 == model.MerchantID2);
- }
- if (!string.IsNullOrWhiteSpace(model.MerchantID3))
- {
- query = query.Where(s => s.MerchantID3 == model.MerchantID3);
- }
- if (model.Status.HasValue)
- {
- switch (model.Status.Value)
- {
- case -1: // エラーの場合
- query = query.Where(s => s.Status < 0);
- break;
- default:
- query = query.Where(s => s.Status == model.Status);
- break;
- }
- }
- if (model.RegistrationDateFrom.HasValue)
- {
- query = query.Where(s => s.RegistrationDate >= model.RegistrationDateFrom.Value);
- }
- if (model.RegistrationDateTo.HasValue)
- {
- query = query.Where(s => s.RegistrationDate < model.RegistrationDateTo.Value);
- }
- if (model.UpdateDateFrom.HasValue)
- {
- query = query.Where(s => s.UpdateDate >= model.UpdateDateFrom.Value);
- }
- if (model.UpdateDateTo.HasValue)
- {
- query = query.Where(s => s.UpdateDate < model.UpdateDateTo.Value);
- }
- model.SearchResult = query.Count();
- if (model.SearchResult == 0)
- {
- ModelState.AddModelError("", Resources.Messages.SearchNotFound);
- return View("Search", model);
- }
- if (model.SearchResult > 10000)
- {
- ModelState.AddModelError("", Resources.Messages.SearchTooManyNumber);
- return View("Search", model);
- }
- model.TE0004MerchantInfoList =
- query.OrderBy(s => s.EntryDate);
- return View("Search", model);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement