Ejemplo n.º 1
0
        public Publisher Update(Publisher publisher)
        {
            Publisher result = new Publisher();

            using (MailPusherDBContext context = new MailPusherDBContext())
            {
                Publisher dbPublisher = context.Publishers.FirstOrDefault(x => x.ID == publisher.ID);
                if (dbPublisher != null)
                {
                    dbPublisher.Domain = publisher.Domain;
                    if (publisher.Status != dbPublisher.Status)
                    {
                        dbPublisher.StatusChanged = DateTime.UtcNow;
                    }
                    dbPublisher.Status   = publisher.Status;
                    dbPublisher.Language = publisher.Language;
                    dbPublisher.NACEID   = publisher.NACEID;
                    dbPublisher.Name     = publisher.Name;

                    dbPublisher.Updater = publisher.Updater;
                }

                context.Entry(dbPublisher).State = EntityState.Modified;
                context.SaveChanges();

                result = context.Publishers.Include(x => x.NACE).FirstOrDefault(x => x.ID == publisher.ID);;
            }
            return(result);
        }
Ejemplo n.º 2
0
        public Email AddEmail(Common.Models.Email newEmail)
        {
            Email result = new Email();
            Email email  = new Email()
            {
                PublisherID   = newEmail.PublisherID,
                ReceivedGMT   = newEmail.ReceivedGMT,
                SenderAddress = newEmail.SenderAddress,
                SenderName    = newEmail.SenderName,
                SubjectLine   = newEmail.SubjectLine,
                Copy          = newEmail.Copy
            };

            using (var context = new MailPusherDBContext())
            {
                result = context.Emails.Add(email);
                context.SaveChanges();

                context.EmailsRawData.Add(new EmailRawData()
                {
                    HTML     = newEmail.HTML,
                    HTMLText = newEmail.HTMLText,
                    Text     = newEmail.Text,
                    EmailID  = result.ID
                });

                foreach (var header in newEmail.EmailHeaders)
                {
                    context.EmailRawHeaders.Add(new EmailRawHeader()
                    {
                        HeaderName  = header.HeaderName,
                        HeaderValue = header.HeaderValue,
                        EmailID     = result.ID
                    });
                }
                context.SaveChanges();
            }
            return(result);
        }
Ejemplo n.º 3
0
        public Publisher Create(Publisher publisher)
        {
            publisher.Created = DateTime.UtcNow;
            publisher.Updated = DateTime.UtcNow;
            Publisher result = new Publisher();

            using (MailPusherDBContext context = new MailPusherDBContext())
            {
                result = context.Publishers.Add(publisher);
                context.SaveChanges();
            }
            return(result);
        }
Ejemplo n.º 4
0
        public Publisher UpdateLastReceivedEmailDate(int publisherID)
        {
            Publisher result = new Publisher();

            using (MailPusherDBContext context = new MailPusherDBContext())
            {
                result = context.Publishers.FirstOrDefault(x => x.ID == publisherID);
                result.LastReceivedEmail    = DateTime.UtcNow;
                context.Entry(result).State = EntityState.Modified;
                context.SaveChanges();
            }
            return(result);
        }
Ejemplo n.º 5
0
 public bool Delete(int publisherID)
 {
     using (MailPusherDBContext context = new MailPusherDBContext())
     {
         Publisher dbPublisher = new Publisher()
         {
             ID = publisherID
         };
         context.Publishers.Attach(dbPublisher);
         context.Publishers.Remove(dbPublisher);
         context.SaveChanges();
     }
     return(true);
 }
Ejemplo n.º 6
0
        public UserSettings Create(string userId, string language)
        {
            UserSettings result = new UserSettings()
            {
                Language = language,
                UserId   = userId
            };

            using (var context = new MailPusherDBContext())
            {
                result = context.UserSettings.Add(result);
                context.SaveChanges();
            }
            return(result);
        }
Ejemplo n.º 7
0
        public UserSettings Update(string userId, string language)
        {
            UserSettings result = new UserSettings();

            using (var context = new MailPusherDBContext())
            {
                result = context.UserSettings.FirstOrDefault(x => x.UserId == userId);
                if (result.Language != language)
                {
                    result.Language             = language;
                    context.Entry(result).State = EntityState.Modified;
                    context.SaveChanges();
                }
            }
            return(result);
        }
Ejemplo n.º 8
0
 public bool ChangePublisherStatus(PublisherStatus status, int id, string userId)
 {
     using (MailPusherDBContext context = new MailPusherDBContext())
     {
         Publisher result = context.Publishers.FirstOrDefault(x => x.ID == id);
         if (status != result.Status)
         {
             result.StatusChanged = DateTime.UtcNow;
         }
         result.Status               = status;
         result.UpdaterId            = userId;
         result.Updated              = DateTime.UtcNow;
         context.Entry(result).State = EntityState.Modified;
         context.SaveChanges();
     }
     return(true);
 }