public void UpdateTrain(KindTrain train) { KindTrain listTrain = _trains.Where(t => t.Id == train.Id).FirstOrDefault(); _trains.Remove(listTrain); _trains.Add(train); trainContext.KindTrains.AddOrUpdate(ToTrainEntity(train)); trainContext.SaveChanges(); }
public void DeleteTrain(KindTrain train) { _trains.Remove(train); trainContext.KindTrains.Remove(ToTrainEntity(train)); var stops = trainContext.Stops.Where(t => t.TrainEntityId == train.Id); trainContext.Stops.RemoveRange(stops); trainContext.SaveChanges(); }
private TrainEntity ToTrainEntity(KindTrain train) { return(new TrainEntity() { ArrivalTime = train.ArrivalTime, DepartureTime = train.DepartureTime, Distance = train.Distance, FirstStation = train.FirstStation, LastStation = train.LastStation, TrainKind = train.TrainKind, }); }
public void AddTrain(KindTrain train) { _trains.Add(train); TrainEntity trainEntity = ToTrainEntity(train); var enteredTrain = trainContext.KindTrains.Add(trainEntity); trainContext .Stops .AddRange(train .Stops .Select(t => ToStopEntity(t, enteredTrain))); trainContext.SaveChanges(); }
private void button1_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(textBox1.Text) && !string.IsNullOrEmpty(textBox2.Text)) { KindTrain train = _trainNet.GetFastestTrain(textBox1.Text, textBox2.Text); if (train == null) { MessageBox.Show("Няма намерен влак"); } else { DisplayData ddf = new DisplayData(new List <KindTrain>() { train }); ddf.ShowDialog(); } } else { MessageBox.Show("Моля въведете необходимите данни!"); } }