public ShowDTO map(ShowModel showmodel) { ShowDTO dto = new ShowDTO(); dto.setID(showmodel.getID()); dto.setGenre(showmodel.getGenre()); dto.setDistribution(showmodel.getDistribution()); dto.setDate(showmodel.getDate()); dto.setNumberOfTickets(showmodel.getNumberOfTickets()); dto.setTitle(showmodel.getTitle()); return(dto); }
private void getAllShows() { showsList = new List <ShowDTO>(); SqlCommand cmd = connectToDB(); cmd.CommandText = "select * from Shows"; SqlDataReader dataReader = cmd.ExecuteReader(); while (dataReader.Read()) { ShowDTO show = new ShowDTO(); show.setID((Int32)dataReader["ID"]); show.setTitle(dataReader["Title"].ToString()); show.setGenre(dataReader["Genre"].ToString()); show.setDistribution(dataReader["Distr"].ToString()); DateTime dt; DateTime.TryParse(dataReader["Date"].ToString(), out dt); show.setDate(dt); show.setNumberOfTickets((Int32)dataReader["NumberOfTickets"]); showsList.Add(show); } cmd.Connection.Close(); }
public List <ShowDTO> getShowsByTitle(string Title) { List <ShowDTO> showsByTitle = new List <ShowDTO>(); SqlCommand cmd = connectToDB(); cmd.Parameters.AddWithValue("Title", Title); cmd.CommandText = "select * from Shows where Title = @Title"; SqlDataReader dataReader = cmd.ExecuteReader(); while (dataReader.Read()) { ShowDTO show = new ShowDTO(); show.setID((Int32)dataReader["ID"]); show.setTitle(dataReader["Title"].ToString()); show.setGenre(dataReader["Genre"].ToString()); show.setDistribution(dataReader["Distr"].ToString()); show.setDate(DateTime.Parse(dataReader["Date"].ToString())); show.setNumberOfTickets((Int32)dataReader["NumberOfTickets"]); showsByTitle.Add(show); } cmd.Connection.Close(); return(showsByTitle); }