Ejemplo n.º 1
0
        public void Delete()
        {
            using (LabDbEntities entities = new LabDbEntities())
            {
                ControlPlan tempEntry = entities.ControlPlans.FirstOrDefault(cp => cp.ID == ID);
                if (tempEntry != null)
                {
                    entities.Entry(tempEntry)
                    .State = System.Data.Entity.EntityState.Deleted;
                    entities.SaveChanges();
                }

                ID = 0;
            }
        }
Ejemplo n.º 2
0
        public ControlPlan AddControlPlan(bool asDefault = false)
        {
            // Generates a new control plan for this specification

            using (LabDbEntities entities = new LabDbEntities())
            {
                ControlPlan newEntry = new ControlPlan()
                {
                    IsDefault       = asDefault,
                    Name            = (asDefault) ? "Completo" : "Nuovo Piano di Controllo",
                    SpecificationID = ID
                };

                SpecificationVersion mainVersion = entities.SpecificationVersions
                                                   .FirstOrDefault(spv => spv
                                                                   .SpecificationID == ID &&
                                                                   spv.IsMain);

                if (mainVersion == null)
                {
                    throw new InvalidOperationException();
                }

                foreach (Requirement req in mainVersion.Requirements)
                {
                    newEntry.control_plan_items_b.Add(new ControlPlanItem()
                    {
                        IsSelected    = asDefault,
                        RequirementID = req.ID
                    });
                }

                entities.ControlPlans.Add(newEntry);

                entities.SaveChanges();

                return(newEntry);
            }
        }