예제 #1
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();
                    }
                }
            }
        }
예제 #2
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");
                }
            }
        }