Exemple #1
0
 private PropertyListing GetPropertyListing(int PropID)
 {
     using (JazMaxDBProdContext db = new JazMaxDBProdContext())
     {
         var query = db.PropertyListings.Where(x => x.PropertyListingId == PropID)?.FirstOrDefault();
         return(query);
     }
 }
Exemple #2
0
 public IQueryable <CoreAdditionalNote> GetNotes()
 {
     using (JazMaxDBProdContext db = new JazMaxDBProdContext())
     {
         var query = db.CoreAdditionalNotes.ToList();
         return(query.AsQueryable());
     }
 }
Exemple #3
0
 private List <PropertyListingAgent> AgentsForListing(int PropID)
 {
     using (JazMaxDBProdContext db = new JazMaxDBProdContext())
     {
         var list = db.PropertyListingAgents.Where(x => x.PropertyListingId == PropID).ToList();
         return(list);
     }
 }
Exemple #4
0
        private List <LeadRawData> GetRawData()
        {
            using (JazMaxDBProdContext db = new JazMaxDBProdContext())
            {
                var query = (from t in db.LeadRawDatas
                             where t.ServiceCompleted == false
                             orderby t.DateCreated ascending
                             select t)?.ToList();

                return(query);
            }
        }
 private void Logging(int MessengerTriggerId, int NumberOfMails)
 {
     using (JazMaxDBProdContext db = new JazMaxDBProdContext())
     {
         MessengerTriggerLog log = new MessengerTriggerLog()
         {
             DateAdded          = DateTime.Now,
             MessengerTriggerId = MessengerTriggerId,
             SendToValue        = NumberOfMails.ToString()
         };
         db.MessengerTriggerLogs.Add(log);
         db.SaveChanges();
     }
 }
Exemple #6
0
        private int FindSource(string SourceName)
        {
            using (JazMaxDBProdContext db = new JazMaxDBProdContext())
            {
                var source = db.LeadSources.FirstOrDefault(x => x.SourceName.ToLower() == SourceName.ToLower())?.LeadSourceId;

                if (source == null)
                {
                    return(-999);
                }

                return((int)source);
            }
        }
        private void MarkAsProcessed(int MessengerTriggerId, int NumberContacts = 0)
        {
            using (JazMaxDBProdContext db = new JazMaxDBProdContext())
            {
                MessengerTrigger table = db.MessengerTriggers?.FirstOrDefault(x => x.MessengerTriggerId == MessengerTriggerId);

                if (table != null)
                {
                    table.HasBeenProcessed  = true;
                    table.ProcessedDateTime = DateTime.Now;
                    table.NumberOfContacts  = NumberContacts;
                }
                db.SaveChanges();
            }
        }
        public string GetMessageTemplateBody(int MessageTemplateId)
        {
            using (JazMaxDBProdContext db = new JazMaxDBProdContext())
            {
                var query = (from t in db.MessengerTemplates
                             where t.MessengerTemplateId == MessageTemplateId
                             select t.TemplateHtml)?.FirstOrDefault();

                if (query != null)
                {
                    return(query);
                }
                return(null);
            }
        }
        public List <MessengerTrigger> GetMessages()
        {
            DateTime Today = DateTime.Now.Date;

            using (JazMaxDBProdContext db = new JazMaxDBProdContext())
            {
                var q = (from t in db.MessengerTriggers
                         where t.IsCancelled == 0
                         //    && t.SendingDate.Date >= Today
                         && t.HasBeenProcessed == false
                         select t
                         ).ToList();

                return(q);
            }
        }
Exemple #10
0
        public string GetAgentName(int CoreUserID)
        {
            using (JazMax.DataAccess.JazMaxDBProdContext db = new JazMaxDBProdContext())
            {
                var query = (from t in db.CoreUsers
                             where t.CoreUserId == CoreUserID
                             select t.FirstName + " " + t.LastName)?.FirstOrDefault();


                if (query == null)
                {
                    return("Unknown");
                }
                return(query);
            }
        }
Exemple #11
0
        private int GetCoreUserIdFromAgentId(int AgentId)
        {
            using (JazMax.DataAccess.JazMaxDBProdContext db = new JazMaxDBProdContext())
            {
                var query = (from t in db.CoreAgents
                             where t.CoreAgentId == AgentId
                             select t.CoreUserId)?.FirstOrDefault();


                if (query == 0)
                {
                    return(-999);
                }
                return((int)query);
            }
        }
        private IQueryable <LeadProspects> GetLeadProspects(LeadProspectsSearchFilter filter)
        {
            using (JazMaxDBProdContext db = new JazMaxDBProdContext())
            {
                var query = (from t in db.Leads
                             join b in db.LeadProspects
                             on t.LeadId equals b.LeadId

                             join c in db.CoreBranches
                             on t.CoreBranchId equals c.BranchId

                             join e in db.PropertyListings
                             on t.PropertyListingId equals e.PropertyListingId

                             select new LeadProspects
                {
                    BranchId = t.LeadId,
                    EmailAddress = b.Email,
                    FullName = b.FullName,
                    LeadId = b.LeadId,
                    ProvinceId = (int)c.ProvinceId,
                    BranchName = c.BranchName,
                    LeadPropertyItem = e.FriendlyName,
                    PropertyPrice = e.Price.ToString()
                }) /*.GroupBy(b => b.EmailAddress).Select(g => g.FirstOrDefault())*/.ToList().AsQueryable();

                var mine = query;

                if (filter.BranchId > 0)
                {
                    mine = mine.Where(x => x.BranchId == filter.BranchId);
                }

                if (filter.ProvinceId > 0)
                {
                    mine = mine.Where(x => x.ProvinceId == filter.ProvinceId);
                }

                return(mine);
            }
        }
Exemple #13
0
 public int AddNote(AdditionalNotesView Note)
 {
     using (JazMaxDBProdContext db = new JazMaxDBProdContext())
     {
         DataAccess.CoreAdditionalNote AdditionalNotes = new DataAccess.CoreAdditionalNote()
         {
             AdditionalNoteId = Note.AdditionalNoteId,
             FileUploadId     = Note.FileUploadId,
             CoreUserId       = 1,
             DateCreated      = DateTime.Now,
             DeletedBy        = "None",
             DeletedDate      = DateTime.Now,
             IsActive         = true,
             IsSent           = true,
             NotesArea        = Note.NotesArea
         };
         db.CoreAdditionalNotes.Add(AdditionalNotes);
         db.SaveChanges();
         return(AdditionalNotes.AdditionalNoteId);
     }
 }
Exemple #14
0
 public LinkedLeads GetLeadsWithSameProspect(string FullName, string ContactNumber, string Email, int BranchID)
 {
     using (JazMaxDBProdContext db = new JazMaxDBProdContext())
     {
         var leads = (from t in db.Leads
                      join b in db.LeadProspects
                      on t.LeadId equals b.LeadId
                      join c in db.PropertyListings
                      on t.PropertyListingId equals c.PropertyListingId
                      where
                      b.FullName.ToLower() == FullName.ToLower() ||
                      b.ContactNumber == ContactNumber ||
                      b.Email == Email
                      &&
                      c.BranchId == BranchID
                      select new LinkedLeads
         {
             BranchID = c.BranchId,
             LeadID = t.LeadId
         })?.FirstOrDefault();
         return(leads);
     }
 }
        private IQueryable <CoreUserEmailData> GetUsersForSelection(CoreUserSearchFilter filter)
        {
            using (JazMaxDBProdContext db = new JazMaxDBProdContext())
            {
                var user = (from t in db.CoreUsers
                            join b in db.CoreAgents
                            on t.CoreUserId equals b.CoreUserId
                            join c in db.CoreBranches
                            on b.CoreBranchId equals c.BranchId
                            where t.IsActive == true
                            select new CoreUserEmailData
                {
                    BranchId = (int)b.CoreBranchId,
                    CoreUserId = t.CoreUserId,
                    CoreUserTypeId = 4,
                    ProvinceId = (int)c.ProvinceId,
                    Email = t.EmailAddress,
                    Name = t.FirstName + " " + t.LastName
                }).Union(from t in db.CoreUsers
                         join b in db.CoreTeamLeaders
                         on t.CoreUserId equals b.CoreUserId
                         join c in db.CoreBranches
                         on b.CoreTeamLeaderId equals c.CoreTeamLeaderId
                         where t.IsActive == true
                         select new CoreUserEmailData
                {
                    BranchId       = (int)c.BranchId,
                    CoreUserId     = t.CoreUserId,
                    CoreUserTypeId = 3,
                    ProvinceId     = (int)c.ProvinceId,
                    Email          = t.EmailAddress,
                    Name           = t.FirstName + " " + t.LastName
                }).Union(from t in db.CoreUsers
                         join b in db.CorePas
                         on t.CoreUserId equals b.CoreUserId
                         where t.IsActive == true
                         select new CoreUserEmailData
                {
                    BranchId       = 0,
                    CoreUserId     = t.CoreUserId,
                    CoreUserTypeId = 5,
                    ProvinceId     = (int)b.ProvinceId,
                    Email          = t.EmailAddress,
                    Name           = t.FirstName + " " + t.LastName
                }).ToList().AsQueryable();

                var mine = user;

                if (filter.BranchId > 0)
                {
                    mine = mine.Where(x => x.BranchId == filter.BranchId);
                }
                if (filter.CoreUserTypeId > 0)
                {
                    mine = mine.Where(x => x.CoreUserTypeId == filter.CoreUserTypeId);
                }
                if (filter.ProvinceId > 0)
                {
                    mine = mine.Where(x => x.ProvinceId == filter.ProvinceId);
                }
                return(mine);
            }
        }
        public static CoreUserEmailData User()
        {
            using (JazMaxDBProdContext db = new JazMaxDBProdContext())
            {
                var user = (from t in db.CoreUsers
                            join b in db.CoreAgents
                            on t.CoreUserId equals b.CoreUserId
                            join c in db.CoreBranches
                            on b.CoreBranchId equals c.BranchId
                            where t.IsActive == true
                            select new CoreUserEmailData
                {
                    BranchId = (int)b.CoreBranchId,
                    CoreUserId = t.CoreUserId,
                    CoreUserTypeId = 4,
                    ProvinceId = (int)c.ProvinceId,
                    Email = t.EmailAddress,
                    Name = t.FirstName + " " + t.LastName
                }).Union(from t in db.CoreUsers
                         join b in db.CoreTeamLeaders
                         on t.CoreUserId equals b.CoreUserId
                         join c in db.CoreBranches
                         on b.CoreTeamLeaderId equals c.CoreTeamLeaderId
                         where t.IsActive == true
                         select new CoreUserEmailData
                {
                    BranchId       = (int)c.BranchId,
                    CoreUserId     = t.CoreUserId,
                    CoreUserTypeId = 3,
                    ProvinceId     = (int)c.ProvinceId,
                    Email          = t.EmailAddress,
                    Name           = t.FirstName + " " + t.LastName
                }).Union(from t in db.CoreUsers
                         join b in db.CorePas
                         on t.CoreUserId equals b.CoreUserId
                         where t.IsActive == true
                         select new CoreUserEmailData
                {
                    BranchId       = 0,
                    CoreUserId     = t.CoreUserId,
                    CoreUserTypeId = 5,
                    ProvinceId     = (int)b.ProvinceId,
                    Email          = t.EmailAddress,
                    Name           = t.FirstName + " " + t.LastName
                }).Where(x => x.Email == UserName)?.FirstOrDefault();

                if (user == null)
                {
                    return(new CoreUserEmailData
                    {
                        BranchId = 0,
                        CoreUserId = 0,
                        CoreUserTypeId = 0,
                        Email = null,
                        Name = null,
                        ProvinceId = 0
                    });
                }


                return(user);
            }
        }
Exemple #17
0
        private void ProcessLeadData(LeadRawData data)
        {
            using (JazMaxDBProdContext db = new JazMaxDBProdContext())
            {
                #region Linked Lead Check
                int BranchId       = GetPropertyListing(data.PropertyListingId).BranchId;
                var LinkedLeadData = GetLeadsWithSameProspect(data.FullName, data.ContactNumber, data.Email, BranchId);
                #endregion

                #region Create New Lead
                int  LeadID = 0;
                Lead lead   = new Lead()
                {
                    IsCompleted       = false,
                    DateCreated       = DateTime.Now,
                    LeadStatusId      = 1,
                    LeadSourceId      = FindSource(data.SourceName),
                    PropertyListingId = data.PropertyListingId,
                    LeadTypeId        = data.IsManualCapture ? (int)LeadType.NewManualLead : (int)LeadType.NewLead,
                    HasLinkedLead     = LinkedLeadData != null ? true : false,
                    ServiceCompleted  = false,
                    CoreBranchId      = BranchId,
                };
                db.Leads.Add(lead);
                db.SaveChanges();
                LeadID = lead.LeadId;

                JazMax.Core.Leads.Activity.ActivityCreation.CaptureLeadActivity(new Core.Leads.Activity.LeadActivity
                {
                    CoreUserId     = -999,
                    LeadActivityId = 1,
                    LeadId         = LeadID,
                    IsSystem       = true,
                    Description    = "New Lead Has Been Created on " + DateTime.Now.ToLongDateString()
                });

                Console.WriteLine("Lead has been inserted. LeadID - " + LeadID.ToString());
                #endregion

                #region Prospect
                LeadProspect prop = new LeadProspect()
                {
                    FullName      = data.FullName,
                    LeadId        = LeadID,
                    ContactNumber = data.ContactNumber,
                    Comments      = data.Comments,
                    Email         = data.Email
                };
                db.LeadProspects.Add(prop);
                db.SaveChanges();
                Console.WriteLine("Lead Prospect Has Been Inserted " + prop.LeadProspectId);
                #endregion

                #region Assign Agents To Lead
                if (data.IsManualCapture)
                {
                    int?GetAgentId = GetAgentIdFromCoreUserId((int)data.CoreUserId);

                    //FOUND AN AGENT
                    if (GetAgentId != null)
                    {
                        LeadAgent agent = new LeadAgent()
                        {
                            LeadId   = LeadID,
                            IsActive = true,
                            AgentId  = (int)GetAgentId
                        };
                        db.LeadAgents.Add(agent);
                        db.SaveChanges();
                        Console.WriteLine("Manual Agent Added " + agent.LeadAgentsId);

                        //Add Lead Activity For Manual Lead
                        JazMax.Core.Leads.Activity.ActivityCreation.CaptureLeadActivity(new Core.Leads.Activity.LeadActivity
                        {
                            CoreUserId     = (int)data.CoreUserId,
                            LeadActivityId = 2,
                            LeadId         = LeadID,
                            IsSystem       = true,
                            Description    = "Manual Lead Has Been Assigned To Agent : " + GetAgentName((int)data.CoreUserId),
                        });
                    }
                    else
                    {
                        foreach (var PropAgent in AgentsForListing(data.PropertyListingId))
                        {
                            LeadAgent agent = new LeadAgent()
                            {
                                LeadId   = LeadID,
                                AgentId  = PropAgent.AgentId,
                                IsActive = true
                            };
                            db.LeadAgents.Add(agent);
                            db.SaveChanges();

                            int cuid = GetCoreUserIdFromAgentId(PropAgent.AgentId);
                            //Add Lead Activity For Lead
                            JazMax.Core.Leads.Activity.ActivityCreation.CaptureLeadActivity(new Core.Leads.Activity.LeadActivity
                            {
                                CoreUserId     = cuid,
                                LeadActivityId = 2,
                                LeadId         = LeadID,
                                IsSystem       = true,
                                Description    = "Lead Has Been Assigned To Agent : " + GetAgentName(cuid),
                            });

                            Console.WriteLine("Agents have been added to the lead " + agent.LeadAgentsId);
                        }
                    }
                }
                else
                {
                    foreach (var PropAgent in AgentsForListing(data.PropertyListingId))
                    {
                        LeadAgent agent = new LeadAgent()
                        {
                            LeadId   = LeadID,
                            AgentId  = PropAgent.AgentId,
                            IsActive = true
                        };
                        db.LeadAgents.Add(agent);
                        db.SaveChanges();

                        int cuid = GetCoreUserIdFromAgentId(PropAgent.AgentId);
                        //Add Lead Activity For Lead
                        JazMax.Core.Leads.Activity.ActivityCreation.CaptureLeadActivity(new Core.Leads.Activity.LeadActivity
                        {
                            CoreUserId     = cuid,
                            LeadActivityId = 2,
                            LeadId         = LeadID,
                            IsSystem       = true,
                            Description    = "Lead Has Been Assigned To Agent : " + GetAgentName(cuid),
                        });

                        Console.WriteLine("Agents have been added to the lead " + agent.LeadAgentsId);
                    }
                }
                #endregion

                #region Perform Linked Leads Magic
                if (LinkedLeadData != null)
                {
                    var check = db.LeadWithSameProspects.FirstOrDefault(x => x.LeadId == LinkedLeadData.LeadID);

                    if (check != null)
                    {
                        LeadWithSameProspectLink link = new LeadWithSameProspectLink()
                        {
                            LeadWithSameProspectId = check.LeadWithSameProspectId,
                            LinkedLeadId           = LeadID
                        };
                        db.LeadWithSameProspectLinks.Add(link);
                        db.SaveChanges();

                        JazMax.Core.Leads.Activity.ActivityCreation.CaptureLeadActivity(new Core.Leads.Activity.LeadActivity
                        {
                            CoreUserId     = -999,
                            LeadActivityId = 3,
                            LeadId         = LeadID,
                            IsSystem       = true,
                            Description    = "Lead Has Been Linked To " + LeadID,
                        });
                    }
                    else
                    {
                        LeadWithSameProspect same = new LeadWithSameProspect()
                        {
                            LeadId = LinkedLeadData.LeadID
                        };
                        db.LeadWithSameProspects.Add(same);
                        db.SaveChanges();

                        LeadWithSameProspectLink link = new LeadWithSameProspectLink()
                        {
                            LeadWithSameProspectId = same.LeadWithSameProspectId,
                            LinkedLeadId           = LeadID
                        };
                        db.LeadWithSameProspectLinks.Add(link);
                        db.SaveChanges();

                        JazMax.Core.Leads.Activity.ActivityCreation.CaptureLeadActivity(new Core.Leads.Activity.LeadActivity
                        {
                            CoreUserId     = -999,
                            LeadActivityId = 3,
                            LeadId         = LeadID,
                            IsSystem       = true,
                            Description    = "Lead Has Been Linked To " + LinkedLeadData.LeadID,
                        });
                    }
                }
                #endregion

                #region Mark Raw Data As Processed And Log New Lead
                var record = db.LeadRawDatas.FirstOrDefault(x => x.LeadRawDataId == data.LeadRawDataId);
                record.ServiceCompleted     = true;
                record.ServiceCompletedDate = DateTime.Now;
                db.SaveChanges();

                LeadRawDataLog log = new LeadRawDataLog()
                {
                    LeadId        = LeadID,
                    LeadRawDataId = data.LeadRawDataId,
                    DateCreated   = DateTime.Now,
                    Message       = "New Lead Created"
                };
                db.LeadRawDataLogs.Add(log);
                db.SaveChanges();
                #endregion
            }
        }