Esempio n. 1
0
        /// <summary>
        /// 获取表名和字段
        /// </summary>
        /// <returns></returns>
        public async Task <Dictionary <string, List <TABLES_COLUMNS> > > GetTableNameAndFields()
        {
            var _TableNames = (await this.GetAllTable()).ToList();

            var dic       = new Dictionary <string, List <TABLES_COLUMNS> >();
            var _TableAll = DbTable.GetAll();

            for (int i = 0; i < _TableNames.Count; i++)
            {
                var item  = _TableNames[i];
                var _Cols = (await this.GetColsByTableName(item));
                List <FieldDescribe> _FieldDescribeList = new List <FieldDescribe>();
                if (_TableAll.ContainsKey(item))
                {
                    _FieldDescribeList = _TableAll[item];
                }

                foreach (var _Col in _Cols)
                {
                    var _FieldDescribe = _FieldDescribeList?.Find(w => w.Name == _Col.COLUMN_NAME);
                    if (_FieldDescribe != null)
                    {
                        _Col.Alias = _FieldDescribe.DisplayName;
                    }
                }
                dic[item] = _Cols;
            }

            return(dic);
        }
        protected override HttpResponseMessage DoGetAll()
        {
            var             listAll = tblData.GetAll(null);
            ApiDataResponse res     = new ApiDataResponse();

            res.data            = listAll;
            res.recordsaffected = listAll.Count();
            return(Request.CreateResponse <ApiDataResponse>(HttpStatusCode.OK, res));
        }
        /// <summary>
        /// Executa um GET ALL (SELECT da tabela inteira)
        /// </summary>
        /// <typeparam name="T">Modelo da Tabela</typeparam>
        /// <returns>HTTP Response com a tabela, paginada ou não</returns>
        public HttpResponseMessage GenericGetAll <T>() where T : class
        {
            HttpResponseMessage response = ResourceNotFound();

            DbTable <T> tblData = new DbTable <T>(DBContext, UserID);

            var QueryStringValidationResponse = ValidateQryString();

            if (QueryStringValidationResponse != null)
            {
                response = Controller.Request.CreateResponse <ApiStatusResponse>(HttpStatusCode.BadRequest, QueryStringValidationResponse);
            }
            else
            {
                try
                {
                    PagedResults <T> foundItens = null;

                    IEnumerable <T> listAll = null;

                    if (HasPagingCommand)
                    {
                        foundItens = tblData.GetPagedResults(PageSize, PageNumber, GetOrderByFieldsList(), BuildWhereParams <T>());
                    }
                    else
                    {
                        listAll = tblData.GetAll(BuildWhereParams <T>());
                    }


                    if (!listAll.IsNullOrEmpty() || (foundItens != null))
                    {
                        ApiDataResponse res = new ApiDataResponse();

                        // já temos os resultados, temos de ordenar?
                        if (!HasPagingCommand && (!MatchedOrderFields.IsNullOrEmpty() && (MatchedOrderFields.Count > 0)))
                        {
                            string order = GetOrderForQuery();

                            var listOrdered = listAll.AsQueryable().OrderBy(order);

                            listAll = listOrdered;
                        }

                        if (!HasPagingCommand)
                        {
                            res.data            = listAll;
                            res.recordsaffected = listAll.Count();
                        }
                        else
                        {
                            res = buildTypedResponse <T>(foundItens, HasPagingCommand);
                        }

                        tblData = null;

                        response = Controller.Request.CreateResponse <ApiDataResponse>(HttpStatusCode.OK, res);
                    }
                }
                catch (Exception ex)
                {
                    tblData  = null;
                    response = DefaultControllerException(Controller.Request, ex);
                }
            }

            return(response);
        }