public async Task <EquipmentUIPaging> GetEquipmentWithCheckLists(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 <CheckListEquipmentUI>();
                foreach (var eqm in result)
                {
                    var eqWithCheckLists = await GetCheckListByEquipmentModelId(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 EquipmentUIPaging
                {
                    Data  = list.ToArray(),
                    Model = model,
                    Total = count
                };
                return(ret);
            }
        }
        public async Task <JsonResult> GetEquipmentWithCheckLists(int model_id, int parent_id, int skip, int limit, string filter, List <int> ids)
        {
            await CheckPermission();

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

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

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

                var listSkiplimit = new List <CheckListEquipmentUI>();
                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 EquipmentUIPaging
                {
                    Data  = listSkiplimit.ToArray(),
                    Model = model,
                    Total = list.Count
                };
                return(result);
            }
        }