Exemple #1
0
        public void TestTableName()
        {
            AModel model     = new AModel();
            string tableName = RepositoryUtils <AModel> .GetTableNameFromModel(model);

            Assert.IsTrue(!string.IsNullOrEmpty(tableName), "Error the tableName is null");
            Assert.IsTrue(tableName?.Equals("model_exemple"), $"Expected value => model_exemple and received => {tableName}");
        }
Exemple #2
0
        public async Task DeleteAsync(T model)
        {
            if (!CanExecute)
            {
                return;
            }

            string tableName = RepositoryUtils <T> .GetTableNameFromModel(model);

            string sql = $"DELETE FROM {tableName} WHERE id = {model.ID}";
            await db.QueryAsync <T>(sql, model);
        }
Exemple #3
0
        public async Task InsertAsync(T model)
        {
            if (!CanExecute)
            {
                return;
            }

            string tableName = RepositoryUtils <T> .GetTableNameFromModel(model);

            string sql = $"INSERT INTO {tableName}";
            await db.QueryAsync <T>(sql, model);
        }
Exemple #4
0
        public void Delete(T model)
        {
            if (!CanExecute)
            {
                return;
            }

            string tableName = RepositoryUtils <T> .GetTableNameFromModel(model);

            string sql = $"DELETE FROM {tableName} WHERE id = {model.ID}";

            db.Query <T>(sql, model);
        }
Exemple #5
0
        public void Insert(T model)
        {
            if (!CanExecute)
            {
                return;
            }

            string tableName = RepositoryUtils <T> .GetTableNameFromModel(model);

            string sql = $"INSERT INTO {tableName}";

            db.Query <T>(sql, model);
        }
Exemple #6
0
        public async Task UpdateAsync(T model)
        {
            if (!CanExecute)
            {
                return;
            }

            string tableName = RepositoryUtils <T> .GetTableNameFromModel(model);

            string update = RepositoryUtils <T> .BuildUpdateRequest(model);

            string sql = $"UPDATE {tableName} {update} WHERE id = {model.ID}";
            await db.QueryAsync <T>(sql, model);
        }