/// <summary> /// Получить id станции по коду станции /// </summary> /// <param name="code_cs"></param> /// <returns></returns> public int DefinitionIDStation(int code_cs) { ReferenceStation station = g_ref.GetReferenceStationOfCode(code_cs); if (station != null) { return(station.IDStation); } Code_Station code_station = rw_ref.GetStationsOfCodeCS(code_cs); if (code_station == null) { return(0); } Code_InternalRailroad code_ir = rw_ref.GetInternalRailroads(code_station.IDInternalRailroad != null? (int)code_station.IDInternalRailroad:0); Code_State code_st = rw_ref.GetState(code_ir != null ? code_ir.IDState: 0); int res = g_ref.SaveReferenceStation(new ReferenceStation() { IDStation = 0, Name = code_station.Station + (code_ir != null ? " " + code_ir.Abbr + " ж/д" : "") + (code_st != null ? " " + code_st.ABB_RUS : ""), Station = code_station.Station, InternalRailroad = code_ir != null ? code_ir.InternalRailroad : "-", IR_Abbr = code_ir != null ? code_ir.Abbr : "-", NameNetwork = code_st != null ? code_st.NameNetwork : "-", NN_Abbr = code_st != null ? code_st.ABB_RUS : "-", CodeCS = code_cs }); if (res > 0) { return(res); } return(0); }
public void Read_Code_Station() { // Arrange - create the mock repository Mock <IReferenceRailwayRepository> mock_rr = new Mock <IReferenceRailwayRepository>(); mock_rr.Setup(m => m.Code_Station).Returns(new Code_Station[] { new Code_Station { IDStation = 1, Station = "Station1", Code = 40000, CodeCS = 400000, IDInternalRailroad = 1 }, new Code_Station { IDStation = 2, Station = "Station2", Code = 50000, CodeCS = 500000, IDInternalRailroad = 1 }, new Code_Station { IDStation = 3, Station = "Station3", Code = 50001, CodeCS = 500010, IDInternalRailroad = 2 } }.AsQueryable()); // Arrange - create the controller ReferenceRailway target = new ReferenceRailway(mock_rr.Object); // Act Code_Station cs1 = target.GetStations(1); Code_Station cs3 = target.GetStations(3); Code_Station cs4 = target.GetStations(4); List <Code_Station> list = target.GetStations().ToList(); // Assert Assert.AreEqual(1, cs1.IDStation); Assert.AreEqual(3, cs3.IDStation); Assert.AreEqual(3, list.Count()); Assert.AreEqual(null, cs4); }
/// <summary> /// Добавить или править Code_Station /// </summary> /// <param name="station"></param> public bool SaveStation(Code_Station station) { if (station.IDStation == 0) { context_edit.Code_Station.Add(station); } else { Code_Station dbEntry = context_edit.Code_Station.Find(station.IDStation); if (dbEntry != null) { dbEntry.Code = station.Code; dbEntry.CodeCS = station.CodeCS; dbEntry.Station = station.Station; dbEntry.IDInternalRailroad = station.IDInternalRailroad; } } try { context_edit.SaveChanges(); } catch (Exception e) { return(false); } return(true); }
public int?GetCodeCSStations(int code) { Code_Station cs = RRRrepository.Code_Station.Where(s => s.Code == code).FirstOrDefault(); if (cs != null) { return(cs.CodeCS); } return(null); }
public void SaveStation(Code_Station cs) { RRRrepository.SaveStation(cs); }