/// <summary> /// When adding a line station we would like to check /// if there is data on distance and time from adjacent stations. /// If there is, we will update the next and previous station of this new station. /// If not, we will update the user. /// In addition we will keep flags of what information is missing, /// in order to request it from the user /// </summary> /// <param name="lineStation">the new line station</param> /// <param name="prevMiss">flag if prev is missing</param> /// <param name="nextMiss">flag if next is missing</param> public void AddDistEndTimeToNewLineStation(BO.LineStation lineStation, out bool prevMiss, out bool nextMiss) { // Flags to know if there infromation of distance and time in the database prevMiss = nextMiss = false; BO.AdjacentStations nextStationAdst, prevStationAdst; try { nextStationAdst = GetAdjacentStations(lineStation.Station, lineStation.NextStation); lineStation.DistanceFromNext = nextStationAdst.Distance; lineStation.TimeFromNext = nextStationAdst.Time; // updade the next station with the new next station var prevStation = GetLineStation(lineStation.PrevStation, lineStation.LineId); prevStation.NextStation = lineStation.Station; UpdateLineStation(prevStation); } catch (BO.BadAdjacentStationsException) { nextMiss = true; } try { prevStationAdst = GetAdjacentStations(lineStation.PrevStation, lineStation.Station); lineStation.DistanceFromPrev = prevStationAdst.Distance; lineStation.TimeFromPrev = prevStationAdst.Time; //updade the prev station with the new prev station var nextStation = GetLineStation(lineStation.PrevStation, lineStation.LineId); nextStation.PrevStation = lineStation.Station; UpdateLineStation(nextStation); } catch (BO.BadAdjacentStationsException) { prevMiss = true; } catch (BO.BadLineStationException ex) { throw ex; } if (prevMiss && nextMiss) { throw new BO.BadLineStationException(lineStation.Station, lineStation.LineId, $"Missing distance and time\n" + $"information from the stations:\n" + $"{lineStation.PrevStation} and {lineStation.NextStation}"); } else if (prevMiss) { throw new BO.BadLineStationException(lineStation.Station, lineStation.LineId, $"Missing distance and time information from station {lineStation.PrevStation}"); } else if (nextMiss) { throw new BO.BadLineStationException(lineStation.Station, lineStation.LineId, $"Missing distance and time information from station {lineStation.NextStation}"); } }
/// <summary> /// Upadte a line station /// </summary> /// <param name="lineStation"></param> public void UpdateLineStation(BO.LineStation lineStation) { try { var lineStationDo = lineStation.CopyPropertiesToNew(typeof(DO.LineStation)) as DO.LineStation; dl.UpdateLineStation(lineStationDo); } catch (DO.BadLineStationException ex) { throw new BO.BadLineStationException(lineStation.Station, lineStation.LineId, ex.Message); } }
/// <summary> /// Remove line station /// </summary> /// <param name="station"></param> public void RemoveLineStation(BO.LineStation station) { try { /* A line must remain with at least two stations * and therefore it is not possible to delete a station * from a line that has only 2 left */ if (GetLine(station.LineId).LineStations.Count() <= 2) { throw new BO.BadLineStationException(station.Station, station.LineId, "A line must remain with at least two stations"); } var lineStationDo = station.CopyPropertiesToNew(typeof(DO.LineStation)) as DO.LineStation; dl.RemoveLineStation(lineStationDo); } catch (DO.BadLineStationException ex) { throw new BO.BadLineStationException(station.Station, station.LineId, ex.Message); } }
public void DeleteLineStation(BO.LineStation lineStation) { dl.DeleteLineStation(LineStationBoDoAdapter(lineStation)); }
public void UpdateLineStation(BO.LineStation lineStation) { dl.UpdateLineStation(LineStationBoDoAdapter(lineStation)); }
public void AddLineStation(BO.LineStation lineStation) { dl.AddLineStation(LineStationBoDoAdapter(lineStation)); }
DO.LineStation LineStationBoDoAdapter(BO.LineStation lineStationBo) { DO.LineStation lineStationDo = new DO.LineStation(); lineStationBo.CopyPropertiesTo(lineStationDo); return(lineStationDo); }
BO.LineStation LineStationDoBoAdapter(DO.LineStation lineStationDo) { BO.LineStation lineStationBo = new BO.LineStation(); lineStationDo.CopyPropertiesTo(lineStationBo); return(lineStationBo); }