IEnumerable <EntityModelBase> IDbRepository <EntityModelBase, object> .SelectAll()
        {
            IList <UserReview> results = null;

            // this will depend on existence of the UserReviewsFilterParams

            if (_userReviewFilterParams.FilterType == SelectAllFilterType.ByUserId)
            {
                User user = (User)Convert.ChangeType(_userReviewFilterParams.Criteria, typeof(User));

                using (SqlLiteDbConnection connection = new SqlLiteDbConnection())
                {
                    ISqlLiteCommandBuilder <SQLiteCommand> selectAllReviewsForUserIdCommandBuilder =
                        new UserReviews_SelectAllForUserId(connection, user.Id);

                    SQLiteCommand command = selectAllReviewsForUserIdCommandBuilder.Build();

                    SQLiteDataReader reader = command.ExecuteReader();

                    IEntityModelBuilder <IList <UserReview>, SQLiteDataReader> userReviewsDataEntitiesBuilder = new UserReviewsDataEntitiesBuilder();

                    results = userReviewsDataEntitiesBuilder.Build(reader);
                }
            }
            else if (_userReviewFilterParams.FilterType == SelectAllFilterType.ByRestaurantId)
            {
                Restaurant restaurant = (Restaurant)Convert.ChangeType(_userReviewFilterParams.Criteria, typeof(Restaurant));

                using (SqlLiteDbConnection connection = new SqlLiteDbConnection())
                {
                    ISqlLiteCommandBuilder <SQLiteCommand> selectAllReviewsForRestaurantIdCommandBuilder =
                        new UserReviews_SelectAllForRestaurantId(connection, restaurant.Id);

                    SQLiteCommand command = selectAllReviewsForRestaurantIdCommandBuilder.Build();

                    SQLiteDataReader reader = command.ExecuteReader();

                    IEntityModelBuilder <IList <UserReview>, SQLiteDataReader> userReviewsDataEntitiesBuilder = new UserReviewsDataEntitiesBuilder();

                    results = userReviewsDataEntitiesBuilder.Build(reader);
                }
            }

            return(results);
        }
Exemplo n.º 2
0
        IEnumerable <EntityModelBase> IDbRepository <EntityModelBase, object> .SelectAll()
        {
            IList <User> results = null;

            using (SqlLiteDbConnection connection = new SqlLiteDbConnection())
            {
                ISqlLiteCommandBuilder <SQLiteCommand> selectAllUsersCommandBuilder = new Users_SelectAllCommand(connection);

                SQLiteCommand command = selectAllUsersCommandBuilder.Build();

                SQLiteDataReader reader = command.ExecuteReader();

                IEntityModelBuilder <IList <User>, SQLiteDataReader> usersDataEntitiesBuilder = new UsersDataEntitiesBuilder();

                results = usersDataEntitiesBuilder.Build(reader);
            }

            return(results);
        }
        object IDbRepository <EntityModelBase, object> .Insert(EntityModelBase entity)
        {
            int commandResult             = 0;
            SQLiteTransaction transaction = null;

            try
            {
                using (SqlLiteDbConnection connection = new SqlLiteDbConnection())
                {
                    ISqlLiteCommandBuilder <SQLiteCommand> restaurantAddCommandBuilder = new Restaurant_AddCommand(connection, entity as Restaurant);

                    SQLiteCommand command = restaurantAddCommandBuilder.Build();

                    using (transaction = connection.Connection.BeginTransaction(IsolationLevel.Serializable))
                    {
                        commandResult = command.ExecuteNonQuery();
                        transaction.Commit();
                    }
                }
            }
            catch (SQLiteException e)
            {
                throw new Exception(string.Format("SQLite Exception {0} {1}", e.ErrorCode, e.Message));
            }
            catch (Exception e)
            {
                transaction.Rollback();
                throw e;
            }
            finally
            {
                if (transaction != null)
                {
                    transaction.Dispose();
                }
            }

            return((object)commandResult);
        }
 public Restaurant_AddCommand(SqlLiteDbConnection dbConnection, Restaurant restaurant) : base(dbConnection)
 {
     _restaurant = restaurant;
 }
 public SqlLiteCommandBuilderBase(SqlLiteDbConnection dbConnection)
 {
     DbConnection = dbConnection;
 }
 public UserReview_AddCommand(SqlLiteDbConnection dbConnection, UserReview userReview) : base(dbConnection)
 {
     _userReview = userReview;
 }
Exemplo n.º 7
0
 public Restaurants_SelectAllCommand(SqlLiteDbConnection dbConnection) : base(dbConnection)
 {
     // do nothing
 }
Exemplo n.º 8
0
 public Users_SelectAllCommand(SqlLiteDbConnection dbConnection) : base(dbConnection)
 {
     // do nothing
 }
 public UserReviews_SelectAllForUserId(SqlLiteDbConnection dbConnection, int userId) : base(dbConnection)
 {
     _userId = userId;
 }
Exemplo n.º 10
0
 public UserReviews_SelectAllForRestaurantId(SqlLiteDbConnection dbConnection, int restaurantId) : base(dbConnection)
 {
     _restaurantId = restaurantId;
 }