public void UpdateProject(ProjectDTO item)
        {
            p1p.Data.Project mdlProject = (p1p.Data.Project)P1PObjectMapper.Convert(item, typeof(p1p.Data.Project));
            p1p.Data.Project match;
            using (p1p.Data.P1PContext ctx = new p1p.Data.P1PContext())
            {
                match = ctx.Projects.Single(p => item.Id == p.Id);
                if (match.IsActive && !mdlProject.IsActive)
                {
                    List <Link> killLinks = ctx.Links.Where(l => l.ProjectId == item.Id &&
                                                            l.LinkStatusId != 5 &&
                                                            l.LinkStatusId != 8 &&
                                                            l.LinkStatusId != 9 &&
                                                            l.LinkStatusId != 10 &&
                                                            l.LinkStatusId != 11 &&
                                                            l.LinkStatusId != 12).ToList <Link>();
                    foreach (Link link in killLinks)
                    {
                        Link deadLink = link;
                        deadLink.LinkStatusId = 8;
                        ctx.Entry(link).CurrentValues.SetValues(deadLink);
                    }
                    ctx.SaveChanges();
                }

                ctx.Entry(match).CurrentValues.SetValues(mdlProject);
                ctx.SaveChanges();

                List <OrderTeamXREF> matchingxref = ctx.OrderTeamXREFs.Where(x => x.OrderId == item.Id).ToList <OrderTeamXREF>();
                if (matchingxref.Count > 0)
                {
                    DateTime      InsertDate = DateTime.Now;
                    OrderTeamXREF xref       = matchingxref[0];
                    ctx.OrderTeamXREFs.Remove(xref);
                    OrderTeamXREF newxref = new OrderTeamXREF()
                    {
                        TeamId = item.Team.Id, OrderId = item.Id, InsertDate = InsertDate
                    };
                    ctx.OrderTeamXREFs.Add(newxref);
                    ctx.SaveChanges();
                }
                else
                {
                    if (item.Team.Id > 0)
                    {
                        DateTime      InsertDate = DateTime.Now;
                        OrderTeamXREF newxref    = new OrderTeamXREF()
                        {
                            TeamId = item.Team.Id, OrderId = item.Id, InsertDate = InsertDate
                        };
                        ctx.OrderTeamXREFs.Add(newxref);
                        ctx.SaveChanges();
                    }
                }
            }
        }
        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)));
            }
        }
Beispiel #4
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.");
         }
     }
 }
 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();
     }
 }
Beispiel #6
0
 public void Update(CustomerDTO item)
 {
     p1p.Data.Customer mdlCustomer = (p1p.Data.Customer)P1PObjectMapper.Convert(item, typeof(p1p.Data.Customer));
     p1p.Data.Customer match;
     using (p1p.Data.P1PContext ctx = new p1p.Data.P1PContext())
     {
         match = ctx.Customers.Single(c => c.Id == item.Id);
         ctx.Entry(match).CurrentValues.SetValues(item);
         ctx.SaveChanges();
     }
 }
 public void Update(LandingPageDTO landingPage)
 {
     p1p.Data.LandingPage mdlLandingPage = (p1p.Data.LandingPage)P1PObjectMapper.Convert(landingPage, typeof(p1p.Data.LandingPage));
     p1p.Data.LandingPage match;
     using (p1p.Data.P1PContext ctx = new p1p.Data.P1PContext())
     {
         match = ctx.LandingPages.Single(l => landingPage.Id == l.Id);
         ctx.Entry(match).CurrentValues.SetValues(mdlLandingPage);
         ctx.SaveChanges();
     }
 }
Beispiel #8
0
 public void UpdateTeam(TeamDTO team)
 {
     p1p.Data.Team mdlTeam = (p1p.Data.Team)P1PObjectMapper.Convert(team, typeof(p1p.Data.Team));
     p1p.Data.Team match;
     using (p1p.Data.P1PContext ctx = new p1p.Data.P1PContext())
     {
         match = ctx.Teams.Single(t => t.Id == team.Id);
         ctx.Entry(match).CurrentValues.SetValues(mdlTeam);
         ctx.SaveChanges();
     }
 }
Beispiel #9
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)));
     }
 }
Beispiel #10
0
 public void Update(EmployeeDetailDTO item)
 {
     p1p.Data.Employee mdlEmployee = (p1p.Data.Employee)P1PObjectMapper.Convert(item, typeof(p1p.Data.Employee));
     p1p.Data.Employee match;
     using (p1p.Data.P1PContext ctx = new p1p.Data.P1PContext())
     {
         if (item.Team != null && item.Team.Id != 0)
         {
             EmployeeTeamXREF xref = ctx.EmployeeTeamXREFs.FirstOrDefault(x => x.EmployeeId == item.Id);
             if (xref != null)
             {
                 if (xref.TeamId != item.Team.Id)
                 {
                     ctx.EmployeeTeamXREFs.Remove(xref);
                     ctx.EmployeeTeamXREFs.Add(new EmployeeTeamXREF()
                     {
                         EmployeeId = item.Id,
                         TeamId     = item.Team.Id,
                         InsertDate = DateTime.Now
                     });
                     ctx.SaveChanges();
                 }
             }
             else
             {
                 ctx.EmployeeTeamXREFs.Add(new EmployeeTeamXREF()
                 {
                     EmployeeId = item.Id,
                     TeamId     = item.Team.Id,
                     InsertDate = DateTime.Now
                 });
                 ctx.SaveChanges();
             }
         }
         match = ctx.Employees.Single(c => item.Id == c.Id);
         ctx.Entry(match).CurrentValues.SetValues(mdlEmployee);
         ctx.SaveChanges();
     }
 }