public async Task <NewEquipmentUIPaging> GetEquipment(int modelId, int parentId, int skip, int limit)
        {
            using (var conn = new SqlConnection(AppSettings.ConnectionString))
            {
                _logger.LogTrace(
                    $"start GetEquipmentWithCheckLists modelId = {modelId}, parentId = {parentId}, skip = {skip}, limit = {limit}");

                List <EquipmentModel> result;
                int count = 0;
                if (parentId == 0)
                {
                    var sql = Sql.SqlQueryCach["Equipment.GetEquipmentModelByModelAndParentNull"];
                    result = (await conn.QueryAsync <EquipmentModel>(
                                  sql,
                                  new { model_id = modelId, skip = skip, limit = limit, parent_id = parentId })).ToList();

                    var sqlc = Sql.SqlQueryCach["Equipment.CountEquipmentModelByModelAndParentNull"];
                    count = (await conn.QueryAsync <int>(sqlc, new { model_id = modelId })).FirstOrDefault();
                }
                else
                {
                    var sql = Sql.SqlQueryCach["Equipment.GetEquipmentModelByModelAndParent"];
                    result = (await conn.QueryAsync <EquipmentModel>(
                                  sql,

                                  new { model_id = modelId, skip = skip, limit = limit, parent_id = parentId })).ToList();
                    var sqlc = Sql.SqlQueryCach["Equipment.CountEquipmentModelByModelAndParent"];
                    count = (await conn.QueryAsync <int>(sqlc, new { model_id = modelId, parent_id = parentId }))
                            .FirstOrDefault();
                }

                var list = new List <EquipmentUI>();
                foreach (var eqm in result)
                {
                    var eqWithCheckLists = await GetEquipmentModelById(eqm.Id);

                    eqWithCheckLists.ParentId = eqm.ParentId;
                    eqWithCheckLists.Id       = eqm.Id;
                    eqWithCheckLists.ModelId  = eqm.ModelId;
                    eqWithCheckLists.IsMark   = eqm.IsMark;
                    list.Add(eqWithCheckLists);
                }

                var sqlrM = new ModelRepository(_logger);
                var model = await sqlrM.GetById(modelId);

                var ret = new NewEquipmentUIPaging
                {
                    Data  = list.ToArray(),
                    Model = model,
                    Total = count
                };
                return(ret);
            }
        }
        public async Task <JsonResult> GetEquipment(int model_id, int parent_id, int skip, int limit, string filter)
        {
            await CheckPermission();

            var er     = new EquipmentRepository(_logger);
            var result = new NewEquipmentUIPaging();

            if (filter != null)
            {
                result = await er.GetEquipment(model_id, parent_id, skip, limit, filter);
            }
            else
            {
                result = await er.GetEquipment(model_id, parent_id, skip, limit);
            }
            return(Json(result));
        }
        public async Task <NewEquipmentUIPaging> GetEquipment(int modelId, int parentId, int skip, int limit, string filter)
        {
            using (var conn = new SqlConnection(AppSettings.ConnectionString))
            {
                var all = await GetEquipment(modelId, parentId, 0, Int32.MaxValue);

                var filters = JsonConvert.DeserializeObject <Other.Other.FilterBody[]>(filter);
                var list    = new List <EquipmentUI>();
                foreach (var itemAll in all.Data)
                {
                    if (itemAll.Equipment.Name.ToLower().Contains(filters.FirstOrDefault().Value.ToLower()))
                    {
                        list.Add(itemAll);
                    }
                }

                var listSkiplimit = new List <EquipmentUI>();
                if (skip < list.Count)
                {
                    if (limit + skip > list.Count)
                    {
                        limit = list.Count - skip;
                    }
                    for (int i = skip; i < limit + skip; i++)
                    {
                        listSkiplimit.Add(list[i]);
                    }
                }

                var sqlrM = new ModelRepository(_logger);
                var model = await sqlrM.GetById(modelId);

                var result = new NewEquipmentUIPaging
                {
                    Data  = listSkiplimit.ToArray(),
                    Model = model,
                    Total = list.Count
                };
                return(result);
            }
        }