RemoveSpecial() public method

public RemoveSpecial ( Id id ) : void
id Id
return void
Esempio n. 1
0
        // Check all descriptions other than the passed one, and remove any duplicate courses.
        public static void UpdateDescriptionCourses(EventDB eventDB, Id<Special> descriptionId)
        {
            // Which courses to remove?
            CourseDesignator[] coursesToRemove = QueryEvent.GetSpecialDisplayedCourses(eventDB, descriptionId);

            // Find all descriptions to change.
            List<Id<Special>> allDescriptionIds = new List<Id<Special>>();
            foreach (Id<Special> specialId in eventDB.AllSpecialIds) {
                if (eventDB.GetSpecial(specialId).kind == SpecialKind.Descriptions && specialId != descriptionId)
                    allDescriptionIds.Add(specialId);
            }

            foreach (Id<Special> descriptionToChange in allDescriptionIds) {
                // Remove any courses that overlap with the courses the given description has..
                bool changes = false;          // track if any changes made.
                List<CourseDesignator> courses = new List<CourseDesignator>(QueryEvent.GetSpecialDisplayedCourses(eventDB, descriptionToChange));
                for (int courseIndex = 0; courseIndex < courses.Count; ++courseIndex) {
                    foreach (CourseDesignator courseToRemove in coursesToRemove) {
                        if (courseIndex >= 0 && courseIndex < courses.Count) {
                            if (courseToRemove == courses[courseIndex]) {
                                changes = true;
                                courses.RemoveAt(courseIndex--);
                            }
                            else if (courseToRemove.CourseId == courses[courseIndex].CourseId) {
                                changes = true;
                                if (!courseToRemove.AllParts && courses[courseIndex].AllParts) {
                                    int removedPart = courseToRemove.Part;
                                    courses.RemoveAt(courseIndex--);
                                    for (int part = 0; part < QueryEvent.CountCourseParts(eventDB, courseToRemove.CourseId); ++part) {
                                        if (part != removedPart)
                                            courses.Add(new CourseDesignator(courseToRemove.CourseId, part));
                                    }
                                }
                                else if (courseToRemove.AllParts) {
                                    courses.RemoveAt(courseIndex--);
                                }
                            }
                        }
                    }
                }

                // Commit the removal to the event database.
                if (changes) {
                    if (courses.Count == 0) {
                        // Remove the given description entire, since it has no displayed courses.
                        eventDB.RemoveSpecial(descriptionToChange);
                    }
                    else {
                        Special newDescription = (Special) eventDB.GetSpecial(descriptionToChange).Clone();
                        newDescription.allCourses = false;
                        newDescription.courses = courses.ToArray();
                        eventDB.ReplaceSpecial(descriptionToChange, newDescription);
                    }
                }
            }
        }
Esempio n. 2
0
 // Delete a special
 public static void DeleteSpecial(EventDB eventDB, Id<Special> specialId)
 {
     eventDB.RemoveSpecial(specialId);
 }