Ejemplo n.º 1
0
        public void RemoveProject(int projectId)
        {
            p1p.Data.Project proj;
            using (p1p.Data.P1PContext ctx = new p1p.Data.P1PContext())
            {
                proj = ctx.Projects.Single(p => p.Id == projectId);
                try
                {
                    List <OrderTeamXREF> matchingxref = ctx.OrderTeamXREFs.Where(x => x.OrderId == projectId).ToList <OrderTeamXREF>();
                    if (matchingxref.Count > 0)
                    {
                        OrderTeamXREF xref = matchingxref[0];
                        ctx.OrderTeamXREFs.Remove(xref);
                        ctx.SaveChanges();
                    }

                    ctx.Projects.Remove(proj);
                    ctx.SaveChanges();
                }
                catch (System.Data.Entity.Infrastructure.DbUpdateException ex)
                {
                    if ("The DELETE statement conflicted with the REFERENCE constraint \"FK_dbo.LandingPages_dbo.Projects_ProjectId\". The conflict occurred in database \"p1pLinkTracker\", table \"dbo.LandingPages\", column 'ProjectId'.\r\nThe statement has been terminated.".Equals(ex.InnerException.InnerException.Message))
                    {
                        throw new Exception("You can't delete a project that has targets assigned to it.");
                    }
                    else
                    {
                        throw new Exception("Could not delete Project.");
                    }
                }
            }
        }
Ejemplo n.º 2
0
        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();
                    }
                }
            }
        }
Ejemplo n.º 3
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)));
            }
        }
Ejemplo n.º 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.");
         }
     }
 }
Ejemplo n.º 5
0
 public bool AddRecentTimeEntry(KronosTimeEntry kEntry)
 {
     using (p1p.Data.P1PContext ctx = new p1p.Data.P1PContext())
     {
         try
         {
             p1p.Data.TimeEntry thisEntry = ConvertToTimeEntry(kEntry);
             if (thisEntry.StartTime < DateTime.Now.AddMonths(-1))
             {
                 return(true);
             }
             List <p1p.Data.TimeEntry> dupCheck = ctx.TimeEntries.Where(t => t.StartTime == thisEntry.StartTime && t.EndTime == thisEntry.EndTime && t.UserId.Equals(thisEntry.UserId)).ToList <p1p.Data.TimeEntry>();
             if (dupCheck.Count > 0)
             {
                 return(true);
             }
             else
             {
                 thisEntry.InsertDate = DateTime.Now;
                 ctx.TimeEntries.Add(thisEntry);
                 ctx.SaveChanges();
                 return(true);
             }
         }
         catch (Exception ex)
         {
             log.Error("Failed to add Time Entry: " + ex.Message + ex.Message + kEntry.toJSON());
             return(false);
         }
     }
 }
Ejemplo n.º 6
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)));
            }
        }
Ejemplo n.º 7
0
 public void DeleteLink(int linkId)
 {
     using (p1p.Data.P1PContext ctx = new p1p.Data.P1PContext())
     {
         List <p1p.Data.Link> toDel = ctx.Links.Where(wl => wl.Id == linkId).ToList <p1p.Data.Link>();
         for (int i = 0; i < toDel.Count; i++)
         {
             try
             {
                 ctx.Links.Remove(toDel[i]);
                 ctx.SaveChanges();
             }
             catch (System.Data.Entity.Infrastructure.DbUpdateException ex)
             {
                 if ("The DELETE statement conflicted with the REFERENCE constraint \"FK_dbo.Outreaches_dbo.Links_LinkId\". The conflict occurred in database \"p1pLinkTracker\", table \"dbo.Outreaches\", column 'LinkId'.\r\nThe statement has been terminated.".Equals(ex.InnerException.InnerException.Message))
                 {
                     throw new Exception("You can't delete this link because it has outreaches assigned to it.");
                 }
                 else
                 {
                     throw new Exception("Could not delete Link.");
                 }
             }
         }
     }
 }
Ejemplo n.º 8
0
 public void Delete(int id)
 {
     p1p.Data.Team team;
     using (p1p.Data.P1PContext ctx = new p1p.Data.P1PContext())
     {
         team = ctx.Teams.Single(t => t.Id == id);
         ctx.Teams.Remove(team);
         ctx.SaveChanges();
     }
 }
Ejemplo n.º 9
0
 public void Delete(int Id)
 {
     p1p.Data.TimeEntry te;
     using (p1p.Data.P1PContext ctx = new p1p.Data.P1PContext())
     {
         te = ctx.TimeEntries.Single(t => t.Id == Id);
         ctx.TimeEntries.Remove(te);
         ctx.SaveChanges();
     }
 }
Ejemplo n.º 10
0
 public void Add(CustomerDTO item)
 {
     p1p.Data.Customer mdlCustomer = (p1p.Data.Customer)P1PObjectMapper.Convert(item, typeof(p1p.Data.Customer));
     mdlCustomer.InsertDate = DateTime.Now;
     using (p1p.Data.P1PContext ctx = new p1p.Data.P1PContext())
     {
         ctx.Customers.Add(mdlCustomer);
         ctx.SaveChanges();
     }
 }
 public void Add(LandingPageDTO landingPage)
 {
     p1p.Data.LandingPage mdlLandingPage = (p1p.Data.LandingPage)P1PObjectMapper.Convert(landingPage, typeof(p1p.Data.LandingPage));
     mdlLandingPage.InsertDate = DateTime.Now;
     using (p1p.Data.P1PContext ctx = new p1p.Data.P1PContext())
     {
         ctx.LandingPages.Add(mdlLandingPage);
         ctx.SaveChanges();
     }
 }
Ejemplo n.º 12
0
        public void AddProject(ProjectDTO item)
        {
            p1p.Data.Project mdlProject = (p1p.Data.Project)P1PObjectMapper.Convert(item, typeof(p1p.Data.Project));
            using (p1p.Data.P1PContext ctx = new p1p.Data.P1PContext())
            {
                if (!IsDuplicate(mdlProject.Name))
                {
                    mdlProject.DateCreated = DateTime.Now;
                    mdlProject.InsertDate  = DateTime.Now;
                    Project newproject = ctx.Projects.Add(mdlProject);
                    ctx.SaveChanges();
                    DateTime insertDate = DateTime.Now;
                    if (item.Team != null && item.Team.Id != 0)
                    {
                        OrderTeamXREF xref = new OrderTeamXREF()
                        {
                            TeamId     = item.Team.Id,
                            OrderId    = newproject.Id,
                            InsertDate = insertDate
                        };

                        ctx.OrderTeamXREFs.Add(xref);
                    }
                    if (item.Categories != null && item.Categories.Count > 0)
                    {
                        foreach (KeyValueDTO c in item.Categories)
                        {
                            ctx.OrderCategoryXREFs.Add(new OrderCategoryXREF()
                            {
                                ProjectId  = newproject.Id,
                                CategoryId = c.Id
                            });
                        }
                    }
                    ctx.SaveChanges();
                }
                else
                {
                    throw new Exception("A project already exists with this name");
                }
            }
        }
Ejemplo n.º 13
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();
     }
 }
Ejemplo n.º 14
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();
     }
 }
Ejemplo n.º 16
0
        public void Add(Types.DTO.TeamDTO team)
        {
            Team mdlTeam = (Team)P1PObjectMapper.Convert(team, typeof(Team));

            mdlTeam.InsertDate = DateTime.Now;

            using (p1p.Data.P1PContext ctx = new p1p.Data.P1PContext())
            {
                ctx.Teams.Add(mdlTeam);
                ctx.SaveChanges();
            }
        }
Ejemplo n.º 17
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)));
     }
 }
Ejemplo n.º 18
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();
     }
 }
Ejemplo n.º 19
0
        public void DeleteOutreach(int entryId)
        {
            using (p1p.Data.P1PContext ctx = new p1p.Data.P1PContext())
            {
                p1p.Data.Outreach entry = ctx.Outreaches.Single(w => entryId == w.Id);

                if (entry != null)
                {
                    ctx.Outreaches.Remove(entry);
                    ctx.SaveChanges();
                }
            }
        }
Ejemplo n.º 20
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();
     }
 }
Ejemplo n.º 21
0
 public void Add(EmployeeDetailDTO item)
 {
     p1p.Data.Employee mdlEmployee = (p1p.Data.Employee)P1PObjectMapper.Convert(item, typeof(p1p.Data.Employee));
     mdlEmployee.InsertDate = DateTime.Now;
     using (p1p.Data.P1PContext ctx = new p1p.Data.P1PContext())
     {
         if (item.Team.Id != 0)
         {
             ctx.EmployeeTeamXREFs.Add(new EmployeeTeamXREF()
             {
                 EmployeeId = item.Id,
                 TeamId     = item.Team.Id,
                 InsertDate = DateTime.Now
             });
         }
         ctx.Employees.Add(mdlEmployee);
         ctx.SaveChanges();
     }
 }
Ejemplo n.º 22
0
        public void DeleteEmployee(EmployeeDetailDTO employee)
        {
            using (p1p.Data.P1PContext ctx = new p1p.Data.P1PContext())
            {
                var employeeToRm = ctx.Employees.Single(a => a.Id == employee.Id);
                ctx.Employees.Remove(employeeToRm);

                var teamXrfs = ctx.EmployeeTeamXREFs.Where(x => x.EmployeeId == employee.Id);
                foreach (var x in teamXrfs)
                {
                    ctx.EmployeeTeamXREFs.Remove(x);
                }

                var projXrfs = ctx.OrderEmployeeXREFs.Where(x => x.EmployeeId == employee.Id);
                foreach (var x in projXrfs)
                {
                    ctx.OrderEmployeeXREFs.Remove(x);
                }

                ctx.SaveChanges();
            }
        }
Ejemplo n.º 23
0
 public void Delete(int id)
 {
     using (p1p.Data.P1PContext ctx = new p1p.Data.P1PContext())
     {
         var toRm = ctx.Customers.Single(a => a.Id == id);
         try
         {
             ctx.Customers.Remove(toRm);
             ctx.SaveChanges();
         }
         catch (System.Data.Entity.Infrastructure.DbUpdateException ex)
         {
             if ("The DELETE statement conflicted with the REFERENCE constraint \"FK_dbo.Projects_dbo.Customers_CustomerId\". The conflict occurred in database \"p1pLinkTracker\", table \"dbo.Projects\", column 'CustomerId'.\r\nThe statement has been terminated.".Equals(ex.InnerException.InnerException.Message))
             {
                 throw new Exception("You can't delete an account that has projects assigned to it.");
             }
             else
             {
                 throw new Exception("The account cannot be deleted.");
             }
         }
     }
 }
Ejemplo n.º 24
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));
 }