public ActionResult Search(string ProspectName, string LeadTypeId, string LeadStatusId, string BranchId, string AngentId) { JazMaxIdentityHelper.UserName = User.Identity.Name; LeadHelper o = new LeadHelper(); LeadIndexSearch model = new LeadIndexSearch() { ProspectName = ProspectName, AngentId = Convert.ToInt32(AngentId), BranchId = Convert.ToInt32(BranchId), LeadStatusId = Convert.ToInt32(LeadStatusId), LeadTypeId = Convert.ToInt32(LeadTypeId) }; if (JazMaxIdentityHelper.IsUserInRole(JazMax.Common.Enum.UserType.Agent.ToString())) { model.AngentId = JazMaxIdentityHelper.GetAgentId(); return(View(o.GetLeadIndexNew(model))); } if (JazMaxIdentityHelper.IsUserInRole(JazMax.Common.Enum.UserType.TeamLeader.ToString())) { model.BranchId = JazMaxIdentityHelper.GetTeamLeadersInfoNew().CoreBranchId; return(View(o.GetLeadIndexNew(model))); } if (JazMaxIdentityHelper.IsUserInRole(JazMax.Common.Enum.UserType.PA.ToString())) { model.BranchIdList = JazMaxIdentityHelper.GetPAProvinceIdList(); return(View(o.GetLeadIndexNew(model))); } if (JazMaxIdentityHelper.IsUserInRole(JazMax.Common.Enum.UserType.CEO.ToString())) { return(View(o.GetLeadIndexNew(model))); } return(View(o.GetLeadIndexNew(model))); }
public LeadIndexSearch GetLeadIndexNew(LeadIndexSearch index) { using (JazMax.DataAccess.JazMaxDBProdContext db = new DataAccess.JazMaxDBProdContext()) { IQueryable <LeadIndex> query = (from a in db.Leads join b in db.LeadTypes on a.LeadTypeId equals b.LeadTypeId join c in db.LeadSources on a.LeadSourceId equals c.LeadSourceId join d in db.LeadStatus on a.LeadStatusId equals d.LeadStatusId join e in db.PropertyListings on a.PropertyListingId equals e.PropertyListingId join f in db.CoreBranches on a.CoreBranchId equals f.BranchId join g in db.LeadProspects on a.LeadId equals g.LeadId where a.LeadSourceId != -999 select new LeadIndex { DateCreated = a.DateCreated, LeadId = a.LeadId, LeadSource = c.SourceName, LeadStatus = d.StatusName, LeadType = b.TypeName, PropertyListingFriendlyName = e.FriendlyName, BranchName = f.BranchName, ProspectName = g.FullName, BranchId = f.BranchId, LeadStatusId = a.LeadStatusId, LeadTypeId = a.LeadTypeId }).Union(from a in db.Leads join b in db.LeadTypes on a.LeadTypeId equals b.LeadTypeId join d in db.LeadStatus on a.LeadStatusId equals d.LeadStatusId join e in db.PropertyListings on a.PropertyListingId equals e.PropertyListingId join f in db.CoreBranches on a.CoreBranchId equals f.BranchId join g in db.LeadProspects on a.LeadId equals g.LeadId where a.LeadSourceId == -999 select new LeadIndex { DateCreated = a.DateCreated, LeadId = a.LeadId, LeadSource = "Unknown", LeadStatus = d.StatusName, LeadType = b.TypeName, PropertyListingFriendlyName = e.FriendlyName, BranchName = f.BranchName, ProspectName = g.FullName, BranchId = f.BranchId, LeadStatusId = a.LeadStatusId, LeadTypeId = a.LeadTypeId }).ToList().AsQueryable(); foreach (var ash in query) { JazMax.Core.Leads.Activity.ActivityLogic o = new Activity.ActivityLogic(ash.LeadId); ash.LastActivity = JazMax.Core.Leads.Activity.ActivityLogic.GetLastLeadActivity()?.ActivityTypeName; } foreach (var bob in query) { LeadId = bob.LeadId; bob.LeadAgents = GetAgentsForLead(); } var mine = query.AsQueryable(); if (index.BranchId > 0) { mine = mine.Where(x => x.BranchId == index.BranchId); } if (index.LeadStatusId > 0) { mine = mine.Where(x => x.LeadStatusId == index.LeadStatusId); } if (index.LeadTypeId > 0) { mine = mine.Where(x => x.LeadTypeId == index.LeadTypeId); } if (index.AngentId > 0) { mine = mine.Where(x => x.LeadAgents.Where(y => y.AgentId == index.AngentId).Any()); } if (!string.IsNullOrEmpty(index.ProspectName)) { mine = mine.Where(x => x.ProspectName == index.ProspectName); } if (index.BranchIdList != null) { mine = mine.Where(x => index.BranchIdList.Contains(x.BranchId)); } index.LeadIndex = mine.AsQueryable(); index.ShowResult = true; return(index); } }