public OrderEntity Add(OrderEntity order) { OrderEntity newOrder = new OrderEntity { ServiceId = order.ServiceId, CustomerId = order.CustomerId, DateOfProcedure = order.DateOfProcedure, StatusId = order.StatusId }; string sqlExpression = $"INSERT INTO Orders (ServiceId, CustomerId, DateOfProcedure, StatusId) " + $"VALUES ('{newOrder.ServiceId}', " + $"'{newOrder.CustomerId}', " + $"'{newOrder.DateOfProcedure}', " + $"N'7')"; SqlConnection sql = _connection.CreateSqlConnection(); sql.Open(); SqlCommand command = new SqlCommand(sqlExpression, sql); command.ExecuteNonQuery(); sql.Close(); return(newOrder); }
public CustomerEntity Add(CustomerEntity customer) { CustomerEntity newCustomer = new CustomerEntity { FirstName = customer.FirstName, LastName = customer.LastName, PhoneNumber = customer.PhoneNumber, Email = customer.Email }; string sqlExpression = $"INSERT INTO Customers (FirstName, LastName, PhoneNumber, Email) " + $"VALUES (N'{customer.FirstName}', " + $"N'{customer.LastName}', " + $"'{customer.PhoneNumber}', " + $"N'{customer.Email}')"; SqlConnection sql = _connection.CreateSqlConnection(); sql.Open(); SqlCommand command = new SqlCommand(sqlExpression, sql); command.ExecuteNonQuery(); sql.Close(); return(newCustomer); }
public ListDatabasesResponse HandleRequest(ISqlConnectionFactory connectionFactory, ConnectionInfo connectionInfo) { ConnectionDetails connectionDetails = connectionInfo.ConnectionDetails.Clone(); // Connect to master connectionDetails.DatabaseName = "master"; using (var connection = connectionFactory.CreateSqlConnection(ConnectionService.BuildConnectionString(connectionDetails), connectionDetails.AzureAccountToken)) { connection.Open(); ListDatabasesResponse response = new ListDatabasesResponse(); using (DbCommand command = connection.CreateCommand()) { command.CommandText = this.QueryText; command.CommandTimeout = 15; command.CommandType = CommandType.Text; using (var reader = command.ExecuteReader()) { List <T> results = new List <T>(); while (reader.Read()) { results.Add(this.CreateItem(reader)); } // Put system databases at the top of the list results = results.Where(s => SystemDatabases.Any(x => this.NameMatches(x, s))).Concat( results.Where(s => SystemDatabases.All(x => !this.NameMatches(x, s)))).ToList(); SetResponse(response, results.ToArray()); } } connection.Close(); return(response); } }
public static ConnectionInfo CreateTestConnectionInfo(TestResultSet[] data, bool throwOnExecute, bool throwOnRead) { // Create a connection info and add the default connection to it ISqlConnectionFactory factory = CreateMockFactory(data, throwOnExecute, throwOnRead); ConnectionInfo ci = new ConnectionInfo(factory, Constants.OwnerUri, StandardConnectionDetails); ci.ConnectionTypeToConnectionMap[ConnectionType.Default] = factory.CreateSqlConnection(null, null); return(ci); }
public StateEntity Add(StateEntity state) { StateEntity newState = new StateEntity { OrderStatus = state.OrderStatus }; string sqlExpression = $"INSERT INTO States (OrderStatus) VALUES (N'{newState.OrderStatus})'"; SqlConnection sql = _connection.CreateSqlConnection(); sql.Open(); SqlCommand command = new SqlCommand(sqlExpression, sql); command.ExecuteNonQuery(); sql.Close(); return(newState); }
public ServiceEntity Add(ServiceEntity service) { ServiceEntity newService = new ServiceEntity { NameOfService = service.NameOfService, Price = service.Price, }; string sqlExpression = $"INSERT INTO Services (NameOfService, Price) " + $"VALUES (N'{newService.NameOfService}', " + $"{newService.Price})"; SqlConnection sql = _connection.CreateSqlConnection(); sql.Open(); SqlCommand command = new SqlCommand(sqlExpression, sql); command.ExecuteNonQuery(); sql.Close(); return(newService); }