示例#1
0
        public DateTime GetCycleStart(int projectId)
        {
            p1p.Data.Project p;

            using (p1p.Data.P1PContext ctx = new p1p.Data.P1PContext())
            {
                p = ctx.Projects.Single(proj => proj.Id == projectId);
            }
            DateTime cycleStart;

            if (p.BillingCycleId == 1)
            {
                cycleStart = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
            }
            else
            {
                if (DateTime.Now < new DateTime(DateTime.Now.Year, DateTime.Now.Month, 15))
                {
                    cycleStart = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 15).AddMonths(-1);
                }
                else
                {
                    cycleStart = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 15);
                }
            }

            return(cycleStart);
        }
 public ArticleDTO GetArticleById(int id)
 {
     using (p1p.Data.P1PContext ctx = new p1p.Data.P1PContext())
     {
         ArticleDTO article = (ArticleDTO)P1PObjectMapper.Convert(ctx.Articles.Single(a => a.Id == id), typeof(ArticleDTO));
         p1p.Data.ProjectArticleXREF xref = ctx.ProjectArticleXREFs.Single(x => x.ArticleId == id);
         article.Project = new ProjectDTO()
         {
             Id = xref.ProjectId
         };
         return(article);
     }
 }
        public void Add(ArticleDTO article)
        {
            p1p.Data.Article newArticle;
            p1p.Data.Article mdlArticle = (p1p.Data.Article)P1PObjectMapper.Convert(article, typeof(p1p.Data.Article));
            mdlArticle.CreatedDate = DateTime.Now;
            using (p1p.Data.P1PContext ctx = new p1p.Data.P1PContext())
            {
                newArticle = ctx.Articles.Add(mdlArticle);

                ctx.ProjectArticleXREFs.Add(new Data.ProjectArticleXREF()
                {
                    ProjectId = article.Project.Id, ArticleId = newArticle.Id
                });
                ctx.SaveChanges();
            }
        }
        public void Update(ArticleDTO article)
        {
            p1p.Data.Article            mdlArticle = (p1p.Data.Article)P1PObjectMapper.Convert(article, typeof(p1p.Data.Article));
            p1p.Data.Article            articleMatch;
            p1p.Data.ProjectArticleXREF xrefMatch;
            p1p.Data.ProjectArticleXREF mdlxref;
            using (p1p.Data.P1PContext ctx = new p1p.Data.P1PContext())
            {
                articleMatch = ctx.Articles.Single(a => article.Id == a.Id);
                ctx.Entry(articleMatch).CurrentValues.SetValues(mdlArticle);

                xrefMatch         = ctx.ProjectArticleXREFs.Single(x => x.ArticleId == article.Id);
                mdlxref           = xrefMatch;
                mdlxref.ProjectId = article.Project.Id;
                ctx.Entry(xrefMatch).CurrentValues.SetValues(mdlxref);
                ctx.SaveChanges();
            }
        }
 public void Delete(int articleId)
 {
     using (p1p.Data.P1PContext ctx = new p1p.Data.P1PContext())
     {
         try
         {
             ctx.ProjectArticleXREFs.Remove(ctx.ProjectArticleXREFs.Single(xr => xr.ArticleId == articleId));
             ctx.SaveChanges();
         }
         catch (System.Data.Entity.Infrastructure.DbUpdateException ex)
         {
             throw new Exception("You cannot delete an article that is used in a target or link.");
         }
         try
         {
             ctx.Articles.Remove(ctx.Articles.Single(a => a.Id == articleId));
             ctx.SaveChanges();
         }
         catch (System.Data.Entity.Infrastructure.DbUpdateException ex)
         {
             throw new Exception("You cannot delete this article.");
         }
     }
 }
示例#6
0
        public List <LinkDTO> Search(int projectId, int status, int linkStrategy, bool onlyMine, string userName, int categoryId, Nullable <DateTime> startDate, Nullable <DateTime> endDate, bool includeNotInUse, int teamId, bool isActive)
        {
            ObjectResult <p1p.Data.Link> resultLinks;
            List <LinkDTO> dtoLinks = new List <LinkDTO>();

            using (P1PContext ctx = new p1p.Data.P1PContext()) {
                resultLinks = ctx.SearchLinks(projectId, status, linkStrategy, onlyMine, userName, categoryId, startDate, endDate, includeNotInUse, teamId, isActive);
                foreach (Link l in resultLinks)
                {
                    LinkDTO link = new LinkDTO()
                    {
                        Id        = l.Id,
                        ProjectId = l.ProjectId,
                        Project   = (new ProjectDTO()
                        {
                            Id = l.Project.Id,
                            Name = l.Project.Name,
                            Description = l.Project.Description,
                            CustomerId = l.Project.CustomerId,
                            IsActive = l.Project.IsActive,
                            DateCreated = l.Project.DateCreated,
                        }),
                        TargetUrl    = l.TargetUrl,
                        RootUrl      = l.RootUrl,
                        RootMethod   = l.RootMethod,
                        LinkStrategy = (new KeyValueDTO()
                        {
                            Id = l.LinkStrategy.Id,
                            Name = l.LinkStrategy.Name
                        }),
                        AnchorText      = l.AnchorText,
                        DomainAuthority = l.DomainAuthority,
                        PageRelevance   = l.PageRelevance,
                        SiteRelevance   = l.SiteRelevance,
                        LinkLocation    = (new KeyValueDTO()
                        {
                            Id = l.LinkLocation.Id,
                            Name = l.LinkLocation.Name
                        }),
                        PublishedUrl = l.PublishedUrl,
                        LandingPage  = l.LandingPage,
                        LinkStatus   = (new KeyValueDTO()
                        {
                            Id = l.LinkStatus.Id,
                            Name = l.LinkStatus.Name
                        }),
                        DateFound        = l.DateFound,
                        DatePublished    = l.DatePublished,
                        FoundBy          = l.FoundBy,
                        LastModifiedBy   = l.LastModifiedBy,
                        DateLastModified = l.DateLastModified,
                        AcquiredBy       = l.AcquiredBy,
                        LinkBuildingMode = (new KeyValueDTO()
                        {
                            Id = l.LinkBuildingMode.Id,
                            Name = l.LinkBuildingMode.Name
                        }),
                        ContactEmail = l.ContactEmail,
                        ContactPhone = l.ContactPhone,
                        ContactUrl   = l.ContactUrl,
                        Notes        = l.Notes,
                        LinkType     = (new KeyValueDTO()
                        {
                            Id = l.LinkType.Id,
                            Name = l.LinkType.Name
                        }),
                        InsertDate           = l.InsertDate,
                        Article              = new ArticleDTO(),
                        ProjectArticleXREFId = l.ProjectArticleXREFId,
                        IsWinner             = l.IsWinner
                    };

                    if (link.ProjectArticleXREFId != null && link.ProjectArticleXREFId != 0)
                    {
                        link.Article.Id              = l.ProjectArticleXREF.Article.Id;
                        link.Article.Title           = l.ProjectArticleXREF.Article.Title;
                        link.Article.CreatedBy       = l.ProjectArticleXREF.Article.CreatedBy;
                        link.Article.ArticleStatusId = l.ProjectArticleXREF.Article.ArticleStatusId;
                        link.Article.CreatedDate     = l.ProjectArticleXREF.Article.CreatedDate;
                    }

                    dtoLinks.Add(link);
                }
            }
            return(dtoLinks);
        }
示例#7
0
        public ClientReportDTO GetClientReport(int projectId, Nullable <DateTime> startDate, Nullable <DateTime> endDate)
        {
            int             totalDomainAuthority = 0;
            int             totalArticles        = 0;
            ClientReportDTO rpt = new ClientReportDTO();

            rpt.PeriodLinks    = getPeriodActiveLinks(projectId, startDate, endDate);
            rpt.PeriodOutreach = getPeriodOutreach(projectId, startDate, endDate);
            rpt.PeriodHours    = getPeriodHours(projectId, startDate, endDate);
            rpt.TotalHours     = 0;

            double totalOutreachHours = 0;
            double totalArticleHours  = 0;

            foreach (TimeEntryDTO entry in rpt.PeriodHours)
            {
                rpt.TotalHours += entry.Elapsed.TotalHours;

                switch (entry.Activity)
                {
                case "Article Directory Writing":
                case "Guest Post Article Writing":
                    totalArticleHours += entry.Elapsed.TotalHours;
                    break;

                case "Article Directory Submitting":
                case "Guest Post Outreach":
                case "Research Outreach":
                    totalOutreachHours += entry.Elapsed.TotalHours;
                    break;
                }
            }

            rpt.TotalLinkCount = rpt.PeriodLinks.Where(lnk => "Link Acquired".Equals(lnk.LinkStatus.Name)).Count();

            if (rpt.TotalLinkCount > 0)
            {
                rpt.HoursPerLink = rpt.TotalHours / rpt.TotalLinkCount;
            }

            rpt.LinksInCommunicationCount = 0;
            rpt.LinksPendingCount         = 0;
            rpt.TotalLinkCount            = 0;
            rpt.UniqueDomainCount         = 0;

            List <LinkDTO> duplicateCheck = new List <LinkDTO>();

            List <LinkDTO> allLinks = getPeriodLinks(projectId, startDate, endDate);

            //TODO quick fix I don't like, will make it better later
            List <p1p.Data.Link> foreverLinks = new List <p1p.Data.Link>();

            using (p1p.Data.P1PContext ctx = new p1p.Data.P1PContext())
            {
                foreverLinks = ctx.Links.Include("LinkStatus").Where(l => l.ProjectId == projectId).ToList <p1p.Data.Link>();
                List <p1p.Data.Article> unwritten = (from a in ctx.Articles
                                                     join x in ctx.ProjectArticleXREFs on a.Id equals x.ArticleId
                                                     where x.ProjectId == projectId && !a.ArticleStatus.Name.ToLower().Equals("unwritten")
                                                     select a).ToList <p1p.Data.Article>();
                totalArticles = unwritten.Count();
            }

            foreach (p1p.Data.Link link in foreverLinks)
            {
                if ("Outreach".Equals(link.LinkStatus.Name))
                {
                    rpt.SitesTargetedCount++;
                }
                if ("In Communication".Equals(link.LinkStatus.Name))
                {
                    rpt.LinksInCommunicationCount++;
                }
                if ("Scheduled".Equals(link.LinkStatus.Name))
                {
                    rpt.ScheduledCount++;
                }
            }

            foreach (LinkDTO link in rpt.PeriodLinks)
            {
                rpt.TotalLinkCount++;
                totalDomainAuthority += link.DomainAuthority;
                if (!duplicateCheck.Any(l => l.RootUrl.Equals(link.RootUrl)))
                {
                    rpt.UniqueDomainCount++;
                    duplicateCheck.Add(link);
                }
            }
            rpt.TotalOutreachCount = rpt.PeriodOutreach.Count;
            if (rpt.TotalLinkCount > 0)
            {
                rpt.AverageDomainAuthority = totalDomainAuthority / rpt.TotalLinkCount;
            }

            List <LinkDTO> activeLinks = new List <LinkDTO>();

            activeLinks = rpt.PeriodLinks.Where(l => "Link Acquired".Equals(l.LinkStatus.Name)).ToList <LinkDTO>();

            rpt.AggregateHoursByActivity = GetAggregateHours(rpt.PeriodHours);
            rpt.AggregateOutreach        = GetAggregatedOutreach(rpt.PeriodOutreach);
            rpt.AggregateLinksByType     = GetAggregateLinksByType(activeLinks);
            rpt.AggregateAnchorText      = GetAggregateAnchorText(activeLinks);
            return(rpt);
        }