/// <summary> /// Add new line to the database /// </summary> /// <param name="newLine"></param> /// <returns>the id of this line that came from the run number in the database</returns> public int AddLine(BO.Line newLine) { #region Check if there is needed data on the database if (!dl.GetAllStations().Any(s => s.Code == newLine.FirstStation)) { throw new BO.BadLineException(newLine.Id, $"Station '{newLine.FirstStation}' does not exist"); } if (!dl.GetAllStations().Any(s => s.Code == newLine.LastStation)) { throw new BO.BadLineException(newLine.Id, $"Station '{newLine.LastStation}' does not exist"); } if (!dl.GetAllAdjacentStations().Any(s => s.Station1 == newLine.FirstStation && s.Station2 == newLine.LastStation)) { throw new BO.BadLineException(newLine.Id, $"Missing distance and time information between {newLine.FirstStation}" + $" and {newLine.LastStation}"); } #endregion var lineDo = newLine.CopyPropertiesToNew(typeof(DO.Line)) as DO.Line; return(dl.AddLine(lineDo)); }
/// <summary> /// Remove line /// </summary> /// <param name="line"></param> public void RemoveLine(BO.Line line) { var lineDo = line.CopyPropertiesToNew(typeof(DO.Line)) as DO.Line; try { dl.RemoveLine(lineDo); } catch (DO.BadLineException ex) { throw new BO.BadLineException(line.Id, ex.Message); } }