/// <summary> /// Remove all positions of an variation. /// </summary> /// <param name="variation"> /// The airport variation. With this object, it will lookup for all positions. /// </param> /// <returns>True everything went well; False something went wrong.</returns> public bool RemoveAllPositions(AirportVariations variation) { using (var db = new YapbtDbEntities()) { Path path = new Path(); // Find a list of all positions, which belongs to this variation. var position = db.AirportPositions.Where(c => c.variationid == variation.variationid).ToList(); // If any position is available. if (position.Any()) { // For each position, remove all pushback path and remove the position. position.ForEach(delegate (AirportPositions pos) { path.RemoveAllPushbackPathOfPosition(pos); db.AirportPositions.Remove(pos); db.SaveChanges(); }); } return true; } }
// /// <summary> /// Adding a airport variations and all positions, paths and pusback points to the db. /// </summary> /// <param name="variationName">The airport variation name.</param> /// <param name="airport"> The airport object.</param> /// <param name="positionList"> A list of positions.</param> /// <param name="pathList"> A list of posible paths.</param> /// <param name="pointList"> A list of push back points.</param> /// <returns></returns> public bool AddNewVariationList(string variationName, Airport airport, List<AirportPositions> positionList, List<AirportPushBackPath> pathList, List<AirportPushPoints> pointList) { List<AirportPositions> errorPositionList = new List<AirportPositions>(); List<AirportPushBackPath> errorPathList = new List<AirportPushBackPath>(); List<AirportPushPoints> errorPointList = new List<AirportPushPoints>(); // Use the YapbtDbEntities to store the data. using (var db = new YapbtDbEntities()) { try { AddVariation(variationName, airport, db); // Adding the positions to the db. Position position = new Position(); Path path = new Path(); Point point = new Point(); // For each position it will add a path and it's points. errorPositionList = position.AddNewPosition(positionList); foreach (var errorPosition in errorPositionList) { positionList.Remove(errorPosition); var pathToRemoveList = pathList.Where(c => c.AirportPositions == errorPosition).ToList(); foreach (var pathToRemove in pathToRemoveList) { pathList.Remove(pathToRemove); pointList = this.RemovePoints(pointList, pathToRemove); } } //Add the path list data to the db errorPathList = path.AddPathByList(pathList); foreach (var pathToRemove in errorPathList) { pathList.Remove(pathToRemove); pointList = this.RemovePoints(pointList, pathToRemove); } // Add the point list to the data. errorPointList = point.AddPointsByList(pointList); return true; } catch (Exception) { return false; } } }