/// <summary> /// Deletes the entry from the database if no Test or requirement is associated with it, otherwise sets it as obsolete /// </summary> public void RemoveOrSetObsolete() { using (LabDbEntities entities = new LabDbEntities()) { MethodVariant attachedInstance = entities.MethodVariants.FirstOrDefault(mtdvar => mtdvar.ID == ID); if (attachedInstance == null) { return; } if (attachedInstance.Requirements.Count == 0 && attachedInstance.Tests.Count == 0) { entities.Entry(attachedInstance) .State = EntityState.Deleted; } else { attachedInstance.IsOld = true; IsOld = true; } entities.SaveChanges(); } }
/// <summary> /// Adds a new method to an ExternalReport entry /// </summary> /// <param name="methodEntity">The MethodVariant to Add</param> public void AddTestMethod(MethodVariant methodVariant) { using (LabDbEntities entities = new LabDbEntities()) { ExternalReport attachedExternalReport = entities.ExternalReports.First(ext => ext.ID == ID); MethodVariant attachedMethodVariant = entities.MethodVariants.First(mtd => mtd.ID == methodVariant.ID); attachedExternalReport.MethodVariants.Add(attachedMethodVariant); IEnumerable <TestRecord> recordList = attachedExternalReport.TestRecords.ToList(); methodVariant.LoadMethod(true); foreach (TestRecord tstr in attachedExternalReport.TestRecords) { tstr.Tests.Add(methodVariant.GenerateTest()); } entities.SaveChanges(); } }
/// <summary> /// Removes a given methodVariant from the method associations and from every test record /// in the report /// </summary> /// <param name="methodEntity">The methodVariant that will be removed</param> public void RemoveTestMethodVariant(MethodVariant methodVariantEntity) { using (LabDbEntities entities = new LabDbEntities()) { ExternalReport attachedExternalReport = entities.ExternalReports.First(ext => ext.ID == ID); MethodVariant attachedMethodVariant = entities.MethodVariants.First(mtdvar => mtdvar.ID == methodVariantEntity.ID); attachedExternalReport.MethodVariants.Remove(attachedMethodVariant); IEnumerable <TestRecord> recordList = attachedExternalReport.TestRecords.ToList(); IEnumerable <Test> testList = attachedExternalReport.TestRecords.SelectMany(tstr => tstr.Tests) .Where(tst => tst.MethodVariantID == methodVariantEntity.ID) .ToList(); foreach (Test tst in testList) { entities.Entry(tst).State = EntityState.Deleted; } entities.SaveChanges(); } }