Beispiel #1
0
        public async Task <DbStatus> Execute()
        {
            MySqlConnection connection = connector.CreateConnection();

            try
            {
                await connector.OpenConnection(connection);
                await CreateProcedure(connection);

                MySqlCommand callCommand = new MySqlCommand
                {
                    Connection  = connection,
                    CommandType = System.Data.CommandType.StoredProcedure,
                    CommandText = GetProcedureName()
                };
                await callCommand.ExecuteNonQueryAsync();

                return(DbStatus.SUCCESS);
            }
            catch (MySqlException ex)
            {
                return(errorHandler.HandleException(ex));
            }
            catch (Exception)
            {
                return(DbStatus.DATABASE_ERROR);
            }
            finally
            {
                await connector.CloseConnection(connection);
            }
        }
        public async static Task <object> ExecuteScalarCommand(DbCommand <T> command)
        {
            IConnector     connector    = ConnectorFactory.CreateConnector();
            IErrorHandling errorHandler = ErrorHandlerFactory.CreateErrorHandler();

            object          scalarResult = null;
            MySqlConnection connection   = connector.CreateConnection();

            try
            {
                await connector.OpenConnection(connection);

                scalarResult = await CommandExecutor <T> .TryExecutingScalarRead(connection, command);

                return(scalarResult);
            }

            catch (MySqlException exception)
            {
                errorHandler.HandleException(exception);
                return(scalarResult);
            }
            finally
            {
                await connector.CloseConnection(connection);
            }
        }
        public async static Task <List <T> > ExecuteSelectCommand(DbCommand <T> command, T entity = default(T))
        {
            IConnector     connector    = ConnectorFactory.CreateConnector();
            IErrorHandling errorHandler = ErrorHandlerFactory.CreateErrorHandler();

            List <T> clinics = new List <T>();

            MySqlConnection connection = connector.CreateConnection();

            try
            {
                await connector.OpenConnection(connection);

                var reader = await CommandExecutor <T> .TryExecutingSelectQueryDataReader(connection, command, entity);

                while (await reader.ReadAsync())
                {
                    clinics.Add(ReadOneObject(reader));
                }
                return(clinics);
            }

            catch (MySqlException exception)
            {
                errorHandler.HandleException(exception);
                return(clinics);
            }
            finally
            {
                await connector.CloseConnection(connection);
            }
        }
Beispiel #4
0
        public async Task <object> ExecuteCommand()
        {
            MySqlCommand    command    = new MySqlCommand();
            MySqlConnection connection = connector.CreateConnection();

            try
            {
                await connector.OpenConnection(connection);

                command.Connection  = connection;
                command.CommandType = System.Data.CommandType.StoredProcedure;
                command.Parameters.AddRange(SetParameters());
                command.CommandText = GetStoredProcedureName();
                return(await Execute(command));
            }
            catch (MySqlException ex)
            {
                errorHandler.HandleException(ex);
                return(null);
            }
            catch (Exception)
            {
                return(null);
            }
            finally
            {
                await connector.CloseConnection(connection);
            }
        }
        public async static Task <DbStatus> ExecuteCRUDCommand(DbCommand <T> command, T entity)
        {
            IConnector     connector    = ConnectorFactory.CreateConnector();
            IErrorHandling errorHandler = ErrorHandlerFactory.CreateErrorHandler();

            MySqlConnection connection = connector.CreateConnection();

            try
            {
                await connector.OpenConnection(connection);

                return(await CommandExecutor <T> .TryExecutingCRUDQuery(connection, command, entity));
            }
            catch (MySqlException exception)
            {
                return(errorHandler.HandleException(exception));
            }
            finally
            {
                await connector.CloseConnection(connection);
            }
        }