コード例 #1
0
ファイル: ClientRepository.cs プロジェクト: AntonukOM/Hotel
        public List<Client> GetClients()
        {
            using (var connection = new SqlConnection(this._connectionString))
            {
                connection.Open();
                using (var command = new SqlCommand())
                {
                    command.Connection = connection;
                    command.CommandText = SELECT_CLIENTS;

                    using (var reader = command.ExecuteReader())
                    {
                        List<Client> sections = new List<Client>();
                        while (reader.Read())
                        {
                            Client client = new Client();
                            client.Id = (int)reader["Id"];
                            client.FirstName = (string)reader["FirstName"];
                            client.LastName = (string)reader["LastName"];
                            client.Email = (string)reader["Email"];
                            client.Phone = Convert.ToString(reader["Phone"]);
                            sections.Add(client);
                        }
                        return sections;
                    }
                }
            }
        }
コード例 #2
0
ファイル: ClientRepository.cs プロジェクト: AntonukOM/Hotel
 public void Insert(Client client)
 {
     using (var connection = new SqlConnection(this._connectionString))
     {
         connection.Open();
         string commandText =
                "INSERT INTO Client(FirstName, LastName, Email, Phone) VALUES ('"
                + client.FirstName + "', '" + client.LastName + "', '"
                + client.Email + "', '" + client.Phone + "');";
         using (var command = new SqlCommand(commandText, connection))
         {
             command.ExecuteNonQuery();
         }
     }
 }
コード例 #3
0
ファイル: HotelService.svc.cs プロジェクト: AntonukOM/Hotel
 public void InsertClient(ClientDTO clientDTO)
 {
     var client = new Client
     {
         FirstName = clientDTO.FirstName,
         LastName = clientDTO.LastName,
         Email = clientDTO.Email,
         Phone = clientDTO.Phone
     };
     string connectionString = ConfigurationManager.ConnectionStrings["HotelServiceDB"].ConnectionString;
     IClientRepository repository = new ClientRepository(connectionString);
     repository.Insert(client);
 }