Example #1
0
        // GET: RolesController
        public ActionResult Index()
        {
            IVoyagerModel model     = ObjectInstance.GetGenericInstanceOfDifferentAssembly <IVoyagerModel>("Role");
            var           tableName = model["TableName"].ToString();

            var query = db.Query(tableName);

            if (model.checkFunc("LocalScope"))
            {
                query = model.func("LocalScope", new object[] { query }) as Query;
            }

            var result = query.Get();


            // Bread Browse column list
            var identityColumn   = "Id";
            var browseColumnList = new string[] { "Name", "DisplayName" };

            browseColumnList = browseColumnList.Concat(new[] { identityColumn }).ToArray();


            List <string> listColumns = new List <string>();
            var           columns     = db.Instance().Select($"SELECT name FROM syscolumns WHERE id=OBJECT_ID('{tableName}')").ToArray();

            foreach (var column in columns)
            {
                listColumns.Add(column.name);
            }

            return(View());
        }
Example #2
0
        public IActionResult Index()
        {
            // Get Class Instance
            //https://jeremylindsayni.wordpress.com/2019/02/11/instantiating-a-c-object-from-a-string-using-activator-createinstance-in-net/

            var objectType = ObjectInstance.GetClassType <IVoyagerModel>("User");

            var instantiatedObject = Activator.CreateInstance(objectType) as User;
            // get a property value
            var tableName = instantiatedObject.TableName;



            IVoyagerModel model = (IVoyagerModel)ObjectInstance.GetObjectInstanceOfDifferentAssembly("User");

            var res      = model.func("testfunction");
            var addition = model.func("add", new object[] { 4, 6 });



            // Adding Query Scope Start

            var query = _db.Query("AspNetUsers");

            if (model.checkFunc("LocalScope"))
            {
                query = model.func("LocalScope", new object[] { query }) as Query;
            }

            var result = query.Get();

            // Adding Query Scope End


            // Query
            var users = _db.Query("AspNetUsers").Get();

            return(Ok(users));

            return(View());
        }
        //***************************************
        //               ____
        //              |  _ \
        //              | |_) |
        //              |  _ <
        //              | |_) |
        //              |____/
        //
        //      Browse our Data Type (B)READ
        //
        //****************************************
        public IActionResult Index()
        {
            IEnumerable <dynamic> dataTypeContent = null;

            // GET THE SLUG, ex. 'posts', 'pages', etc.
            //var slug = GetSlug($request);
            var slug = "roles";

            var tableName = "roles";
            var keyColumn = "id";

            // GET THE DataType based on the slug
            var dataType = db.Query("data_types").Where("slug", "=", slug).First();


            // Check permission
            //$this->authorize('browse', app($dataType->model_name));

            var getter = Convert.ToBoolean(dataType.server_side) ? "paginate" : "get";

            var search = new Dictionary <string, string>()
            {
                { "value", Request.Query["s"].ToString() },
                { "key", Request.Query["key"].ToString() },
                { "filter", Request.Query["filter"].ToString() },
            };


            var searchNames = new Dictionary <string, string>();

            if (Convert.ToBoolean(dataType.server_side))
            {
                var searchable = SchemaManager.DescribeTable(db, tableName);
                var dataRow    = db.Query("data_rows").Where("data_type_id", "=", dataType.id);
                foreach (var value in searchable)
                {
                    var field       = db.Query("data_rows").Where("field", value).First();
                    var displayName = value.Replace('_', ' ');//ucwords(str_replace('_', ' ', $value));
                    //if (field !== null) {
                    //    displayName = field->getTranslatedAttribute('display_name');
                    //}
                    searchNames.Add(value, displayName);
                }
            }

            var orderBy         = !string.IsNullOrEmpty(Request.Query["order_by"]) ? Request.Query["order_by"].ToString() : dataType.order_column;
            var sortOrder       = !string.IsNullOrEmpty(Request.Query["sort_order"]) ? Request.Query["sort_order"].ToString() : dataType.order_direction;
            var usesSoftDeletes = false;
            var showSoftDeleted = false;

            // Next Get or Paginate the actual content from the MODEL that corresponds to the slug DataType
            if (Convert.ToString(dataType.model_name).Length != 0)
            {
                IVoyagerModel model = ObjectInstance.GetGenericInstanceOfDifferentAssembly <IVoyagerModel>(dataType.model_name);
                var           table = model["TableName"].ToString();

                var query = db.Query(tableName);

                //if (model.checkFunc("LocalScope"))
                //{
                //    query = model.func("LocalScope", new object[] { query }) as Query;
                //}

                //                if ($dataType->scope && $dataType->scope != '' && method_exists($model, 'scope'.ucfirst($dataType->scope))) {
                //                $query = $model->{$dataType->scope} ();
                //                } else
                //                {
                query = query.Select($"{table}.*");
                //                }

                //                // Use withTrashed() if model uses SoftDeletes and if toggle is selected
                //                if ($model && in_array(SoftDeletes::class, class_uses_recursive($model)) && Auth::user()->can('delete', app($dataType->model_name))) {
                //                $usesSoftDeletes = true;

                //                if ($request->get('showSoftDeleted')) {
                //                    $showSoftDeleted = true;
                //                    $query = $query->withTrashed();
                //    }
                //}

                //            // If a column has a relationship associated with it, we do not want to show that field
                //            $this->removeRelationshipField($dataType, 'browse');
                string search_filter = string.Empty;
                string search_value  = string.Empty;

                if (!string.IsNullOrEmpty(search["value"]) && !string.IsNullOrEmpty(search["key"]) && !string.IsNullOrEmpty(search["filter"]))
                {
                    search_filter = (search["filter"] == "equals") ? "=" : "LIKE";
                    search_value  = (search["filter"] == "equals") ? search["value"] : $"%{search["value"]}%";
                    query         = query.Where(search["key"], search_filter, search_value);
                }

                if (!string.IsNullOrEmpty(orderBy))
                {
                    //if (string.IsNullOrEmpty(orderBy) && in_array($orderBy, $dataType->fields())) {
                    var querySortOrder = (!string.IsNullOrEmpty(sortOrder)) ? sortOrder : "desc";
                    dataTypeContent = query.OrderBy(orderBy, querySortOrder);
                    //$dataTypeContent = call_user_func([
                    //    $query->orderBy($orderBy, $querySortOrder),
                    //    $getter,
                    //]);
                }
                //elseif($model->timestamps) {
                //                $dataTypeContent = call_user_func([$query->latest($model::CREATED_AT), $getter]);
                //}
                else
                {
                    dataTypeContent = (IEnumerable <dynamic>)query.OrderByDesc(keyColumn).Get();
                    return(Ok(dataTypeContent));
                }

                //            // Replace relationships' keys for labels and create READ links if a slug is provided.
                //            $dataTypeContent = $this->resolveRelations($dataTypeContent, $dataType);
                //        } else
                //{
                //            // If Model doesn't exist, get data from table name
                //            $dataTypeContent = call_user_func([DB::table($dataType->name), $getter]);
                //            $model = false;
            }


            return(View());
        }