public IEnumerable <Servis> FindAll() { List <Servis> list = new List <Servis>(); using (IDbConnection connection = database.CreateOpenConnection()) { IDbTransaction tran = connection.BeginTransaction(); using (IDbCommand command = database.CreateStoredProcCommand("SelectServis", connection)) { try { command.Connection = connection; command.Transaction = tran; using (IDataReader reader = command.ExecuteReader()) { IVoziloRepository vozrepo = new VoziloRepository(); IServisStavkaRepository ssrepo = new ServisStavkaRepository(); while (reader.Read()) { Vozilo vozilo = vozrepo.FindById(reader.GetInt32(1)); ServisStavka servisStavka = ssrepo.FindById(reader.GetInt32(2)); Servis temp = new Servis { IDServis = reader.GetInt32(0), ServisStavka = servisStavka, Vozilo = vozilo, Datum = reader.GetDateTime(3), Naziv = reader.GetString(4), Opis = reader.GetString(5), Cijena = reader.GetDouble(6) }; list.Add(temp); } } tran.Commit(); } catch (Exception ex) { try { tran.Rollback(); } catch (Exception ex2) { throw; } } } } return(list.AsEnumerable()); }
public Servis FindById(int id) { Servis temp = null; using (IDbConnection connection = database.CreateOpenConnection()) { IDbTransaction tran = connection.BeginTransaction(); using (IDbCommand command = database.CreateStoredProcCommand("FindServis", connection)) { try { command.Connection = connection; command.Transaction = tran; command.Parameters.Add(database.CreateParameter("pID", id)); using (IDataReader reader = command.ExecuteReader()) { IVoziloRepository vozrepo = new VoziloRepository(); IServisStavkaRepository ssrepo = new ServisStavkaRepository(); while (reader.Read()) { Vozilo vozilo = vozrepo.FindById(reader.GetInt32(1)); ServisStavka servisStavka = ssrepo.FindById(reader.GetInt32(2)); temp = new Servis { IDServis = reader.GetInt32(0), ServisStavka = servisStavka, Vozilo = vozilo, Datum = reader.GetDateTime(3), Naziv = reader.GetString(4), Opis = reader.GetString(5), Cijena = reader.GetDouble(6) }; } } tran.Commit(); } catch (Exception ex) { try { tran.Rollback(); } catch (Exception ex2) { throw; } } } } return(temp); }