public IEnumerable <ServicesHistory> GetAll()
        {
            List <ServicesHistory> serviceHistories = new List <ServicesHistory>();
            string expression = @"SELECT ServicesHistory.Id AS ServicesHistoryId ,
                                ServicesHistory.Date AS ServicesHistoryDate, ServicesHistory.ServiceId AS ServicesHistoryServiceId, 
                                ServicesHistory.EmployeeId  AS ServicesHistoryEmployeeId, ServicesHistory.ClientId  AS ServicesHistoryClientId,
                                ServicesDirectory.Id AS 'ServicesDirectoryId', ServicesDirectory.Name AS 'ServicesDirectoryName',
                                Employee.Id AS EmployeeId, Employee.FirstName AS EmployeeFirstName, Employee.SecondName AS EmployeeSecondName,
                                Employee.MiddleName AS EmployeeMiddleName, Employee.BirthDay AS EmployeeBirthDay, Employee.BranchId AS EmployeeBranchId,
                                Employee.PositionId AS EmployeePositionId,
                                Client.Id AS ClientId, Client.FirstName AS ClientFirstName, Client.SecondName AS ClientSecondName,
                                Client.MiddleName AS ClientMiddleName, Client.BirthDay AS ClientBirthDay, Client.Address AS ClientAddress,
                                Client.PassportSeriesAndNumber AS ClientPassportSeriesAndNumber, Client.CardNumber AS ClientCardNumber
                                FROM ServicesHistory
                                JOIN ServicesDirectory ON ServicesDirectory.Id = ServicesHistory.ServiceId
                                JOIN Employee ON Employee.Id = ServicesHistory.EmployeeId
                                JOIN Client ON Client.Id = ServicesHistory.ClientId";

            SqlCommand sqlCommand = new SqlCommand(expression, sqlConnection);
            DataTable  dataTable  = GetDataTable(sqlCommand);

            foreach (DataRow row in dataTable.Rows)
            {
                ServicesHistory serviceHistory = serviceHistoryMapper.MapFromRow(row);

                serviceHistory.ServicesDirectory = serviceMapper.MapFromRow(row);
                serviceHistory.Employee          = employeeMapper.MapFromRow(row);
                serviceHistory.Client            = clientMapper.MapFromRow(row);
                serviceHistories.Add(serviceHistory);
            }
            return(serviceHistories);
        }
Exemple #2
0
        public List <ServicesDirectory> GetAll()
        {
            List <ServicesDirectory> services = new List <ServicesDirectory>();
            string     expression             = "SELECT * FROM ServicesDirectory";
            SqlCommand sqlCommand             = new SqlCommand(expression, sqlConnection);
            DataTable  dataTable = GetDataTable(sqlCommand);

            foreach (DataRow row in dataTable.Rows)
            {
                ServicesDirectory service = serviceMapper.MapFromRow(row);
                services.Add(service);
            }
            return(services);
        }