public IEnumerable <Client> GetClients() { var result = new List <Client>(); using (SqlConnection connection = new SqlConnection(connectionstring)) { SqlCommand cmd = new SqlCommand("GetAllClients", connection); cmd.CommandType = System.Data.CommandType.StoredProcedure; connection.Open(); SqlDataReader read = cmd.ExecuteReader(); while (read.Read()) //пока читаем { int idClinet = (int)read["IDClient"]; string firstName = (string)read["FirstName"]; string lastName = (string)read["LastName"]; string telephoneNumber = (string)read["TelephoneNumber"]; int? idCoach = read["IDFavoriteCoach"] as int?; if (idCoach.HasValue) { var client = new Client { IDClient = idClinet, FirstName = firstName, LastName = lastName, TelephoneNumber = telephoneNumber, FirstNameOfFavoriteCoach = coachDao.GetFirstNameNeedCoach((int)idCoach), LastNameOfFavoriteCoach = coachDao.GetLastNameNeedCoach((int)idCoach) }; result.Add(client); } else { var client = new Client { IDClient = idClinet, FirstName = firstName, LastName = lastName, TelephoneNumber = telephoneNumber, FirstNameOfFavoriteCoach = "NULL", LastNameOfFavoriteCoach = "NULL", }; result.Add(client); } } } return(result); }
public string GetLastNameNeedCoach(int idCoach) { return(_coachDao.GetLastNameNeedCoach(idCoach)); }