Esempio n. 1
0
        public LinkDTO UpdateLink(LinkDTO link, string userName)
        {
            p1p.Data.Link mdlLink = (p1p.Data.Link)P1PObjectMapper.Convert(link, typeof(p1p.Data.Link));
            p1p.Data.Link match;
            mdlLink.LastModifiedBy   = userName;
            mdlLink.DateLastModified = DateTime.Now;

            using (p1p.Data.P1PContext ctx = new p1p.Data.P1PContext())
            {
                match = ctx.Links.Single(l => link.Id == l.Id);
                if (match.LinkStatusId != 10 && link.LinkStatus.Id == 10)
                {
                    throw new Exception("You cannot set a link active through the 'UpdateLink' method.");
                }

                if (match.LinkStatusId != 14 && link.LinkStatus.Id == 14)
                {
                    throw new Exception("You cannot set a link to 'Request Active' through the 'UpdateLink' method.");
                }

                if (link.Article != null && link.Article.Id > 0)
                {
                    p1p.Data.ProjectArticleXREF pax = ctx.ProjectArticleXREFs.Single(x => x.ArticleId == link.Article.Id && x.ProjectId == link.ProjectId);
                    mdlLink.ProjectArticleXREFId = pax.Id;
                }

                ctx.Entry(match).CurrentValues.SetValues(mdlLink);
                ctx.SaveChanges();
                return((LinkDTO)P1PObjectMapper.Convert(match, typeof(LinkDTO)));
            }
        }
Esempio n. 2
0
        public LinkDTO RequestActive(LinkDTO link, string userName)
        {
            p1p.Data.Link mdlLink = (p1p.Data.Link)P1PObjectMapper.Convert(link, typeof(p1p.Data.Link));
            p1p.Data.Link match;
            mdlLink.LastModifiedBy   = userName;
            mdlLink.DateLastModified = DateTime.Now;

            using (p1p.Data.P1PContext ctx = new p1p.Data.P1PContext())
            {
                match = ctx.Links.Single(l => link.Id == l.Id);

                if (link.Article != null && link.Article.Id > 0)
                {
                    p1p.Data.ProjectArticleXREF pax = ctx.ProjectArticleXREFs.Single(x => x.ArticleId == link.Article.Id && x.ProjectId == link.ProjectId);
                    mdlLink.ProjectArticleXREFId = pax.Id;
                }

                mdlLink.LinkStatusId  = 14;
                mdlLink.AcquiredBy    = userName;
                mdlLink.DatePublished = DateTime.Now;

                ctx.Entry(match).CurrentValues.SetValues(mdlLink);
                ctx.SaveChanges();
                return((LinkDTO)P1PObjectMapper.Convert(match, typeof(LinkDTO)));
            }
        }
Esempio n. 3
0
 public void ActivateLink(LinkDTO link)
 {
     p1p.Data.Link mdlLink = (p1p.Data.Link)P1PObjectMapper.Convert(link, typeof(p1p.Data.Link));
     p1p.Data.Link match;
     using (p1p.Data.P1PContext ctx = new p1p.Data.P1PContext())
     {
         if (link.Article.Id != 0)
         {
             p1p.Data.Article article        = ctx.Articles.Single(a => a.Id == link.Article.Id);
             p1p.Data.Article updatedArticle = article;
             updatedArticle.ArticleStatusId = 4;
             ctx.Entry(article).CurrentValues.SetValues(updatedArticle);
         }
         match = ctx.Links.Single(l => link.Id == l.Id);
         ctx.Entry(match).CurrentValues.SetValues(mdlLink);
         ctx.SaveChanges();
     }
 }
Esempio n. 4
0
 public LinkDTO AddLink(LinkDTO link, string userName)
 {
     p1p.Data.Link mdlLink = (p1p.Data.Link)P1PObjectMapper.Convert(link, typeof(p1p.Data.Link));
     mdlLink.LastModifiedBy   = userName;
     mdlLink.DateLastModified = DateTime.Now;
     mdlLink.InsertDate       = DateTime.Now;
     p1p.Data.Link newLink = new p1p.Data.Link();
     using (p1p.Data.P1PContext ctx = new p1p.Data.P1PContext())
     {
         if (mdlLink.LinkStatusId == 10 || mdlLink.LinkStatusId == 14)
         {
             throw new Exception("You must use the 'Request Active' button.");
         }
         //TODO Need to verify that Article isn't being incorrectly instantiated when the link has no article
         if (link.Article != null && link.Article.Id > 0)
         {
             ProjectArticleXREF xref = ctx.ProjectArticleXREFs.Single(x => x.ProjectId == link.ProjectId && x.ArticleId == link.Article.Id);
             mdlLink.ProjectArticleXREFId = xref.Id;
         }
         newLink = ctx.Links.Add(mdlLink);
         ctx.SaveChanges();
     }
     return(Get(newLink.Id));
 }