/// <summary> /// Add a list of paths to the db. /// </summary> /// <param name="position">The position we are using for this paths.</param> /// <param name="pathList">A list of paths.</param> /// <returns>A list of all paths that made trouble.</returns> public List<AirportPushBackPath> AddPathByList(List<AirportPushBackPath> pathList) { // The return list with error path objects. Hope it will always be null. List<AirportPushBackPath> errorPath = new List<AirportPushBackPath>(); using (var db = new YapbtDbEntities()) { foreach (var path in pathList) { try { // Add the new path. AirportPushBackPath newPath = new AirportPushBackPath(); newPath = path; db.AirportPushBackPath.Add(newPath); // TODO bulk inserts? db.SaveChanges(); } catch (System.Exception) { // unable to store it into the db. Add it to the list for an error message. errorPath.Add(path); } } } return errorPath; }
/// <summary> /// Remove all points belonging to a single pushback path. /// </summary> /// <param name="pushBackPath">The pushback path we are looking for.</param> /// <returns>True allright; False something went wrong.</returns> public bool RemovePushbackPoint(AirportPushBackPath pushBackPath) { try { using (var db = new YapbtDbEntities()) { // Find a list of all points, which belongs to this path. var points = db.AirportPushPoints.Where(c => c.AirportPushBackPath == pushBackPath).ToList(); // If any point was found, remove it. if (points.Any()) { points.ForEach(delegate (AirportPushPoints point) { db.AirportPushPoints.Remove(point); db.SaveChanges(); }); } return true; } } catch (Exception) { return false; throw; } }
List<AirportPushPoints> RemovePoints(List<AirportPushPoints> pointList, AirportPushBackPath pathToRemove) { var pointsToRemoveList = pointList.Where(c => c.AirportPushBackPath == pathToRemove).ToList(); foreach (var pointToRemove in pointsToRemoveList) { pointList.Remove(pointToRemove); } return pointList; }