public async Task <IActionResult> Get([FromQuery] FloorQueryFilter filter,
                                              [FromQuery] FloorQuerySort sort,
                                              [FromQuery] FloorQueryProjection projection,
                                              [FromQuery] FloorQueryPaging paging,
                                              [FromQuery] FloorQueryOptions options)
        {
            var validationResult = _service.ValidateGetFloors(
                User, filter, sort, projection, paging, options);

            if (!validationResult.Valid)
            {
                return(BadRequest(validationResult.Result));
            }
            var result = await _service.QueryFloorDynamic(
                projection, options, filter, sort, paging);

            if (options.single_only)
            {
                if (result == null)
                {
                    return(NotFound(new AppResultBuilder().NotFound()));
                }
                return(Ok(new AppResultBuilder().Success(result.SingleResult)));
            }
            return(Ok(new AppResultBuilder().Success(result)));
        }
Exemplo n.º 2
0
 public ValidationResult ValidateGetFloors(
     ClaimsPrincipal principal,
     FloorQueryFilter filter,
     FloorQuerySort sort,
     FloorQueryProjection projection,
     FloorQueryPaging paging,
     FloorQueryOptions options)
 {
     return(ValidationResult.Pass());
 }
Exemplo n.º 3
0
        public IDictionary <string, object> GetFloorDynamic(
            FloorQueryRow row, FloorQueryProjection projection,
            FloorQueryOptions options)
        {
            var obj = new Dictionary <string, object>();

            foreach (var f in projection.GetFieldsArr())
            {
                switch (f)
                {
                case FloorQueryProjection.INFO:
                {
                    var entity = row.Floor;
                    obj["id"]          = entity.Id;
                    obj["code"]        = entity.Code;
                    obj["name"]        = entity.Name;
                    obj["location_id"] = entity.LocationId;
                    obj["description"] = entity.Description;
                    obj["buidling_id"] = entity.BuildingId;
                }
                break;

                case FloorQueryProjection.FLOOR_PLAN:
                {
                    var entity = row.Floor;
                    obj["floor_plan_svg"] = entity.FloorPlanSvg;
                }
                break;

                case FloorQueryProjection.SELECT:
                {
                    var entity = row.Floor;
                    obj["id"]   = entity.Id;
                    obj["code"] = entity.Code;
                    obj["name"] = entity.Name;
                }
                break;

                case FloorQueryProjection.BUILDING:
                {
                    var entity = row.Building;
                    obj["building"] = new
                    {
                        id   = entity.Id,
                        name = entity.Name,
                        code = entity.Code
                    };
                }
                break;
                }
            }
            return(obj);
        }
Exemplo n.º 4
0
        public QueryResult <IDictionary <string, object> > GetFloorDynamic(
            IEnumerable <FloorQueryRow> rows, FloorQueryProjection projection,
            FloorQueryOptions options, int?totalCount = null)
        {
            var list = new List <IDictionary <string, object> >();

            foreach (var o in rows)
            {
                var obj = GetFloorDynamic(o, projection, options);
                list.Add(obj);
            }
            var resp = new QueryResult <IDictionary <string, object> >();

            resp.Results = list;
            if (options.count_total)
            {
                resp.TotalCount = totalCount;
            }
            return(resp);
        }
Exemplo n.º 5
0
        public async Task <QueryResult <FloorQueryRow> > QueryFloor(
            FloorQueryFilter filter         = null,
            FloorQuerySort sort             = null,
            FloorQueryProjection projection = null,
            FloorQueryPaging paging         = null,
            FloorQueryOptions options       = null)
        {
            var conn     = context.Database.GetDbConnection();
            var openConn = conn.OpenAsync();
            var query    = FloorQuery.CreateDynamicSql();

            #region General
            if (filter != null)
            {
                query = query.SqlFilter(filter);
            }
            if (projection != null)
            {
                query = query.SqlJoin(projection);
            }
            DynamicSql countQuery = null; int?totalCount = null; Task <int> countTask = null;
            if (options != null && options.count_total)
            {
                countQuery = query.SqlCount("*");
            }
            if (projection != null)
            {
                query = query.SqlProjectFields(projection);
            }
            #endregion
            await openConn;
            if (options != null && !options.single_only)
            {
                #region List query
                if (sort != null)
                {
                    query = query.SqlSort(sort);
                }
                if (paging != null && (!options.load_all || !FloorQueryOptions.IsLoadAllAllowed))
                {
                    query = query.SqlSelectPage(paging.page, paging.limit);
                }
                #endregion
                #region Count query
                if (options.count_total)
                {
                    countTask = conn.ExecuteScalarAsync <int>(
                        sql: countQuery.PreparedForm,
                        param: countQuery.DynamicParameters);
                }
                #endregion
            }
            var queryResult = await conn.QueryAsync(
                sql : query.PreparedForm,
                types : query.GetTypesArr(),
                map : (objs) => ProcessMultiResults(query, objs),
                splitOn : string.Join(',', query.GetSplitOns()),
                param : query.DynamicParameters);

            if (options != null && options.single_only)
            {
                var single = queryResult.FirstOrDefault();
                return(new QueryResult <FloorQueryRow>
                {
                    SingleResult = single
                });
            }
            if (options != null && options.count_total)
            {
                totalCount = await countTask;
            }
            return(new QueryResult <FloorQueryRow>
            {
                Results = queryResult,
                TotalCount = totalCount
            });
        }