Example #1
0
        public IQueryable <LeadIndex> GetLeadIndex(int BranchId = 0, int AgentId = 0)
        {
            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
                                                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
                }).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 (BranchId > 0)
                {
                    mine = mine.Where(x => x.BranchId == BranchId);
                }

                if (AgentId > 0)
                {
                    mine = mine.Where(x => x.LeadAgents.Where(y => y.AgentId == AgentId).Any());
                }

                //List<LeadIndex> lol = new List<LeadIndex>();
                //lol = mine.ToList();
                //return lol;
                return(mine);
            }
        }
Example #2
0
        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);
            }
        }