コード例 #1
0
        public ServicesDirectory GetItem(int serviceId)
        {
            SqlParameter serviceIdParam = new SqlParameter("@serviceId", serviceId);
            string       expression     = "SELECT * FROM ServicesDirectory  WHERE Id = @serviceid";
            SqlCommand   command        = new SqlCommand(expression, sqlConnection);

            command.Parameters.Add(serviceIdParam);
            ServicesDirectory service = new ServicesDirectory();

            using (sqlConnection = new SqlConnection(connectionString))
            {
                sqlConnection.Open();
                SqlDataReader reader = command.ExecuteReader();
                if (reader.Read())
                {
                    service = serviceMapper.MapFromReader(reader);
                }
            }

            return(service);
        }
コード例 #2
0
        public ServicesHistory GetItem(int serviceHistoryId)
        {
            SqlParameter serviceIdParam = new SqlParameter("@serviceHistoryId", serviceHistoryId);
            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
                                WHERE ServicesHistory.Id = @serviceHistoryId";

            SqlCommand command = new SqlCommand(expression, sqlConnection);

            command.Parameters.Add(serviceIdParam);
            ServicesHistory serviceHistory = new ServicesHistory();

            using (sqlConnection = new SqlConnection(connectionString))
            {
                sqlConnection.Open();
                SqlDataReader reader = command.ExecuteReader();
                if (reader.Read())
                {
                    serviceHistory = serviceHistoryMapper.MapFromReader(reader);
                    serviceHistory.ServicesDirectory = serviceMapper.MapFromReader(reader);
                    serviceHistory.Employee          = employeeMapper.MapFromReader(reader);
                    serviceHistory.Client            = clientMapper.MapFromReader(reader);
                }
            }

            return(serviceHistory);
        }