private static List <int> UpdateEmailTable(List <string> OverallEmailList)
        {
            using (QuarksoftDBEmailsEntities database = new QuarksoftDBEmailsEntities())
            {
                List <int> emailIDList = new List <int>();

                foreach (string emailItem in OverallEmailList)
                {
                    var foundEmail = database.Emails.FirstOrDefault(x => x.Email.Equals(emailItem));
                    if (foundEmail != null)
                    {
                        emailIDList.Add(foundEmail.EmailID);
                    }
                    else
                    {
                        //Add a New email
                        Emails newEmail = new Emails()
                        {
                            Email = emailItem, DateAdded = DateTime.Now
                        };
                        database.Emails.Add(newEmail);
                        database.SaveChanges();
                        //Add new EmailID
                        emailIDList.Add(newEmail.EmailID);
                    }
                }
                return(emailIDList);
            }
        }
        private static List <int> UpdateDomainTable(List <string> OverallDomainList)
        {
            using (QuarksoftDBEmailsEntities database = new QuarksoftDBEmailsEntities())
            {
                List <int> emailIDList = new List <int>();

                foreach (string domainItem in OverallDomainList)
                {
                    var foundDomain = database.Domains.FirstOrDefault(x => x.DomainName.Equals(domainItem));
                    if (foundDomain != null)
                    {
                        emailIDList.Add(foundDomain.DomainID);
                    }
                    else
                    {
                        //Add a New Domain
                        Domains newDomain = new Domains()
                        {
                            DomainName = domainItem, DateAdded = DateTime.Now
                        };
                        database.Domains.Add(newDomain);
                        database.SaveChanges();
                        //Add new DomainID
                        emailIDList.Add(newDomain.DomainID);
                    }
                }
                return(emailIDList);
            }
        }
 private static int?GetEmailID(string emailName)
 {
     using (QuarksoftDBEmailsEntities database = new QuarksoftDBEmailsEntities())
     {
         var Email = database.Emails.FirstOrDefault(x => x.Email.Equals(emailName));
         return((Email != null) ? Email.EmailID : -1);
     }
 }
        private static long SaveEmailHeader(EmailHeader emailHeader)
        {
            using (QuarksoftDBEmailsEntities database = new QuarksoftDBEmailsEntities())
            {
                emailHeader.SenderEmailID = GetEmailID(ExtractEmails(emailHeader.Sender).First());
                //adding the timestamp
                emailHeader.DateAdded = DateTime.Now;

                database.EmailHeader.Add(emailHeader);
                database.SaveChanges();
                return(emailHeader.EmailHeaderID);
            }
        }
 private static void SaveEmailDomains(long headerID, List <int> domainIDList)
 {
     using (QuarksoftDBEmailsEntities database = new QuarksoftDBEmailsEntities())
     {
         foreach (int domainID in domainIDList)
         {
             database.EmailDomains.Add(new EmailDomains()
             {
                 EmailHeaderID = headerID, DomainID = domainID, DateAdded = DateTime.Now
             });
         }
         database.SaveChanges();
     }
 }
 private static void SaveEmailRecipients(long headerID, List <int> emailIDList)
 {
     using (QuarksoftDBEmailsEntities database = new QuarksoftDBEmailsEntities())
     {
         foreach (int emailID in emailIDList)
         {
             database.EmailRecipients.Add(new EmailRecipients()
             {
                 EmailHeaderID = headerID, EmailID = emailID, DateAdded = DateTime.Now
             });
         }
         database.SaveChanges();
     }
 }