public List <OfferDal> GetOffers(int skip, int take) { List <OfferDal> proposedReturnValue = new List <OfferDal>(); try { EnsureConnected(); using (SqlCommand command = new SqlCommand("GetOffers", _connection)) { command.CommandType = System.Data.CommandType.StoredProcedure; command.Parameters.AddWithValue("@Skip", skip); command.Parameters.AddWithValue("@Take", take); using (SqlDataReader reader = command.ExecuteReader()) { OfferMapper m = new OfferMapper(reader); while (reader.Read()) { OfferDal r = m.OfferFromReader(reader); proposedReturnValue.Add(r); } } } } catch (Exception ex) when(Log(ex)) { } return(proposedReturnValue); }
//Offer public OfferDal FindOfferByID(int OfferID) { OfferDal ProposedReturnValue = null; try { EnsureConnected(); using (SqlCommand command = new SqlCommand("FindOfferByID", _connection)) { command.CommandType = System.Data.CommandType.StoredProcedure; command.Parameters.AddWithValue("@OfferID", OfferID); using (SqlDataReader reader = command.ExecuteReader()) { OfferMapper m = new OfferMapper(reader); int count = 0; while (reader.Read()) { ProposedReturnValue = m.OfferFromReader(reader); count++; } if (count > 1) { throw new Exception($"Found more than 1 Offer with key{OfferID}"); } } } } catch (Exception ex) when(Log(ex)) { } return(ProposedReturnValue); }