示例#1
0
 public void AddOutreach(OutreachDTO entry, string user)
 {
     p1p.Data.Link link;
     p1p.Data.Link linkMatch;
     entry.AddedBy    = user;
     entry.InsertDate = DateTime.Now;
     p1p.Data.Outreach mdlOutreach = (p1p.Data.Outreach)P1PObjectMapper.Convert(entry, typeof(p1p.Data.Outreach));
     using (p1p.Data.P1PContext ctx = new p1p.Data.P1PContext())
     {
         if (entry.OutreachAction != null && ctx.OutreachActions.FirstOrDefault(oa => oa.Id == entry.OutreachAction.Id) != null)
         {
             linkMatch             = ctx.Links.Single(l => entry.LinkId == l.Id);
             link                  = linkMatch;
             link.LastModifiedBy   = user;
             link.DateLastModified = DateTime.Now;
             ctx.Outreaches.Add(mdlOutreach);
             ctx.Entry(linkMatch).CurrentValues.SetValues(link);
             ctx.SaveChanges();
         }
         else
         {
             throw new Exception("You must select an outreach action to save this outreach.");
         }
     }
 }
示例#2
0
 public OutreachDTO UpdateOutreach(OutreachDTO entry)
 {
     p1p.Data.Outreach mdlOutreach = (p1p.Data.Outreach)P1PObjectMapper.Convert(entry, typeof(p1p.Data.Outreach));
     p1p.Data.Outreach match;
     using (p1p.Data.P1PContext ctx = new p1p.Data.P1PContext())
     {
         match = ctx.Outreaches.Single(e => entry.Id == e.Id);
         ctx.Entry(match).CurrentValues.SetValues(mdlOutreach);
         ctx.SaveChanges();
         return((OutreachDTO)P1PObjectMapper.Convert(match, typeof(OutreachDTO)));
     }
 }
        public void Add(OutreachDTO entry)
        {
            string user = Membership.GetUser().UserName;

            if (entry.OutreachType.Id == 1)
            {
                if (!string.IsNullOrEmpty(entry.EmailRecipient) || !string.IsNullOrEmpty(entry.EmailBody) || entry.PersonaId > 0)
                {
                    if (string.IsNullOrEmpty(entry.EmailRecipient) || string.IsNullOrEmpty(entry.EmailBody) || entry.PersonaId < 1)
                    {
                        throw new Exception("Recipient, Sender, and Email Content must all be populated before sending an email.");
                    }
                    else
                    {
                        string attachmentPath = null;

                        if (entry.ArticleId > 0)
                        {
                            ArticleRepository articleRepo = new ArticleRepository();
                            ArticleDTO        article     = articleRepo.GetArticleById(entry.ArticleId);
                            DocumentUtility   docUtil     = new DocumentUtility();
                            attachmentPath = docUtil.ConvertHtmlToDocPath(new DocumentDTO()
                            {
                                Title = article.Title, Content = article.Content
                            });
                        }

                        PersonaDTO persona = new PersonaRepository().GetById(entry.PersonaId);

                        string smtpServer   = persona.SMTPServer;
                        int    smtpPort     = persona.SMTPPort;
                        string smtpUsername = persona.SMTPUsername;
                        string smtpPassword = persona.SMTPPassword;

                        if (persona.Email.ToLower().Contains("@gmail.com"))
                        {
                            smtpServer   = "smtp.gmail.com";
                            smtpPort     = 587;
                            smtpUsername = persona.GmailUsername;
                            smtpPassword = persona.GmailPassword;
                        }

                        MessagingHelper.SendEmail(persona.Email, entry.EmailRecipient, entry.EmailSubject, entry.EmailBody, attachmentPath, smtpServer, smtpPort, smtpUsername, smtpPassword);
                    }
                }
            }

            repo.AddOutreach(entry, user);
        }
示例#4
0
        public List <OutreachDTO> Search(int linkId, int projectId, int typeId, int actionId, Nullable <DateTime> startDate, Nullable <DateTime> endDate, bool onlyMine, int teamId, string userName)
        {
            ObjectResult <p1p.Data.Outreach> resultOutreaches;
            List <OutreachDTO> dtoOutreaches = new List <OutreachDTO>();

            using (P1PContext ctx = new P1PContext())
            {
                resultOutreaches = ctx.SearchOutreaches(linkId, projectId, typeId, actionId, startDate, endDate, onlyMine, teamId, userName);
                foreach (Outreach o in resultOutreaches)
                {
                    OutreachDTO outreach = new OutreachDTO()
                    {
                        Id             = o.Id,
                        LinkId         = o.LinkId,
                        OutreachAction = new KeyValueDTO()
                        {
                            Id   = o.OutreachAction.Id,
                            Name = o.OutreachAction.Name
                        },
                        OutreachType = new KeyValueDTO()
                        {
                            Id   = o.OutreachType.Id,
                            Name = o.OutreachType.Name
                        },
                        OutreachNotes  = o.OutreachNotes,
                        AddedBy        = o.AddedBy,
                        DateOutreached = o.DateOutreached,
                        InsertDate     = o.InsertDate,
                        Link           = new LinkDTO()
                        {
                            Id        = o.Link.Id,
                            TargetUrl = o.Link.TargetUrl
                        }
                    };

                    dtoOutreaches.Add(outreach);
                }
            }

            return(dtoOutreaches);
        }
 public OutreachDTO Update(OutreachDTO entry)
 {
     entry.AddedBy = this.User.Identity.Name;
     return(repo.UpdateOutreach(entry));
 }