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))); } }
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))); } }