public ActionResult Index(int?companyId, int?page) { var model = from cbd in db.CompanyMeeting select cbd; //orderby cbd.Id descending if (companyId.HasValue) { ViewBag.CompanyId = companyId.Value; ViewBag.CompanyName = db.OtaCompany.FirstOrDefault(p => p.Id == companyId.Value).CompanyName; model = model.Where(p => p.CompanyId == companyId.Value); } else { if (!User.IsInRole("SalesDirector") && !User.IsInRole("Admin")) { if (User.IsInRole("AreaManager")) { //找出本区域的所有人,并把它作为条件加入查询结果中 ServeAreasController sac = new ServeAreasController(); List <string> myAreaUserNameList = sac.GetMyAreaUserNames(User.Identity.Name); model = model.Where(p => myAreaUserNameList.Contains(p.CreateUserName)); } else if (User.IsInRole("OtaSales")) { //销售只能看到本人的 model = model.Where(p => p.CreateUserName == User.Identity.Name); } } } model = model.OrderByDescending(p => p.Id); int pageSize = 10; int pageNumber = (page ?? 1); return(View(model.ToPagedList(pageNumber, pageSize))); }
// GET: OtaCompanies public ActionResult Index(string sortOrder, string searchString, string currentFilter, string businessStatus, int?page) { //根据user来确定公司结果 ViewBag.CurrentSort = sortOrder; ViewBag.SalesUserNameSortParm = string.IsNullOrEmpty(sortOrder) ? "salesUserName_desc" : "salesUserName"; ViewBag.CityNameSortParm = sortOrder == "cityName" ? "cityName_desc" : "cityName"; ViewBag.LastMeetingDateSortParm = sortOrder == "lastMeetingDate" ? "lastMeetingDate_desc" : "lastMeetingDate"; ViewBag.BusinessStatusSortParm = sortOrder == "businessStatus" ? "businessStatus_desc" : "businessStatus"; ViewData["BusinessStatusList"] = GetParamDictList("业务状态", businessStatus); if (businessStatus == null) { ViewBag.BusinessStatus = ""; } else { ViewBag.BusinessStatus = businessStatus; } if (searchString != null) { page = 1; } else { searchString = currentFilter; } ViewBag.CurrentFilter = searchString; //总监能看到所有人的,区域经理能看到本区域的,需要进行打勾,其他的销售只能看到自己的 var otaCompanys = from p in db.OtaCompany select p; if (!string.IsNullOrEmpty(businessStatus)) { otaCompanys = otaCompanys.Where(p => p.BusinessStatus == businessStatus); } if (!User.IsInRole("SalesDirector") && !User.IsInRole("Admin")) { if (User.IsInRole("AreaManager")) { //找出本区域的所有人,并把它作为条件加入查询结果中 ServeAreasController sac = new ServeAreasController(); List <string> myAreaUserNameList = sac.GetMyAreaUserNames(User.Identity.Name); AccountController ac = new AccountController(); List <string> realNameList = new List <string>(); realNameList.Add("未知"); foreach (string userName in myAreaUserNameList) { string realName = ac.GetRealName(userName); realNameList.Add(realName); } otaCompanys = otaCompanys.Where(p => realNameList.Contains(p.SalesUserName)); } else if (User.IsInRole("OtaSales")) { //销售只能看到本人的 AccountController ac = new AccountController(); string realName = ac.GetRealName(User.Identity.Name); otaCompanys = otaCompanys.Where(p => p.SalesUserName == realName || p.SalesUserName == "未知"); } } //搜索 if (!string.IsNullOrEmpty(searchString)) { otaCompanys = otaCompanys.Where(p => p.CompanyName.Contains(searchString) || p.SalesUserName == searchString || p.BossName.Contains(searchString) || p.LegalPerson.Contains(searchString) || p.CityName.Contains(searchString) || p.BusinessStatus.Contains(searchString) || p.BusinessRange.Contains(searchString)); } switch (sortOrder) { case "salesUserName_desc": otaCompanys = otaCompanys.OrderByDescending(o => o.SalesUserName); break; case "salesUserName": otaCompanys = otaCompanys.OrderBy(o => o.SalesUserName); break; case "businessStatus_desc": otaCompanys = otaCompanys.OrderByDescending(o => o.BusinessStatus); break; case "businessStatus": otaCompanys = otaCompanys.OrderBy(o => o.BusinessStatus); break; case "cityName_desc": otaCompanys = otaCompanys.OrderByDescending(o => o.CityName); break; case "cityName": otaCompanys = otaCompanys.OrderBy(o => o.CityName); break; case "lastMeetingDate": otaCompanys = otaCompanys.OrderBy(o => o.LastMeetingDate); break; case "lastMeetingDate_desc": otaCompanys = otaCompanys.OrderByDescending(o => o.LastMeetingDate); break; default: otaCompanys = otaCompanys.OrderBy(o => o.BusinessStatus); break; } int pageSize = 10; int pageNumber = (page ?? 1); return(View(otaCompanys.ToPagedList(pageNumber, pageSize))); }