private void UpdateStation(Station station, SqlConnection connection) { using (var command = connection.CreateCommand()) { command.CommandText = "UPDATE Stations SET Name = @name WHERE Id = @id"; command.Parameters.AddWithValue("@id", station.Id); command.Parameters.AddWithValue("@name", station.Name); command.ExecuteNonQuery(); } }
private Station ReadStation(SqlDataReader reader) { var station = new Station(); station.Id = reader.GetInt32(0); station.Name = reader.GetString(1); return station; }
private void SeedDefaultData() { using (var connection = OpenDbConnection()) { if (GetStationsCount(connection) == 0) { var stations = new Station[] { new Station { Name = "Москва Ленинградская" }, new Station { Name = "Москва Казанская" }, new Station { Name = "Москва Павелецкая" }, new Station { Name = "Санкт-Петербург Ладож." }, new Station { Name = "Казань" }, new Station { Name = "Воронеж" }, new Station { Name = "Нижний Новгород" }, new Station { Name = "Адлер" }, }; foreach (var s in stations) { InsertStation(s); } var trips = new TrainTrip[] { new TrainTrip { DepartureStation = stations[3], ArrivalStation = stations[0], DepartureTime = new DateTime(2015, 12, 10, 0, 11, 0), ArrivalTime = new DateTime(2015, 12, 10, 0, 11, 0) }, new TrainTrip { DepartureStation = stations[4], ArrivalStation = stations[1], DepartureTime = new DateTime(2015, 12, 14, 19, 45, 0), ArrivalTime = new DateTime(2015, 12, 15, 7, 10, 0) } }; foreach (var t in trips) { InsertTrip(t); InsertTickets(t.Id, wagonsCount: 16, seatsCountPerWagon: 37, cost: 4554); } } } }
internal void UpdateStation(Station station) { using (var connection = OpenDbConnection()) { UpdateStation(station, connection); } }
public void InsertStation(Station station, SqlConnection connection) { using (var command = connection.CreateCommand()) { command.CommandText = "INSERT INTO Stations(Name) OUTPUT INSERTED.Id VALUES(@name)"; command.Parameters.AddWithValue("@name", station.Name); station.Id = (int)command.ExecuteScalar(); } }
public void InsertStation(Station station) { using (var connection = OpenDbConnection()) { InsertStation(station, connection); } }
public ActionResult Edit(Station station) { var db = new RzdTicketsDb(); db.UpdateStation(station); return RedirectToAction("Index"); }
public ActionResult Create(Station station) { var db = new RzdTicketsDb(); db.InsertStation(station); return RedirectToAction("Index"); }