Ejemplo n.º 1
0
        public IActionResult GetListByCondition(string condition, string keyword)
        {
            var resultCountModel = new RespResultCountViewModel();

            try
            {
                LogEventInfo log = new LogEventInfo(LogLevel.Info, User.GetCurrentUserName(), "测试日志Info");
                nlog.Log(log);

                var data = _organizeService.GetAll();
                if (data != null && !string.IsNullOrEmpty(condition) && !string.IsNullOrEmpty(keyword))
                {
                    #region 多条件查询
                    switch (condition)
                    {
                    case "OrgName":        //机构名称
                        data = data.Where(t => t.OrgName != null && t.OrgName.Contains(keyword)).ToList();
                        break;

                    case "OrgCode":       //机构代码
                        data = data.Where(t => t.OrgCode != null && t.OrgCode.Contains(keyword)).ToList();
                        break;

                    case "Manager":        //机构管理人
                        data = data.Where(t => t.Manager != null && t.Manager.Contains(keyword)).ToList();
                        break;

                    default:
                        break;
                    }
                    #endregion
                }

                if (data != null)
                {
                    resultCountModel.code  = 0;
                    resultCountModel.msg   = "成功";
                    resultCountModel.data  = data;
                    resultCountModel.count = data.Count();
                }
                else
                {
                    resultCountModel.code = -1;
                    resultCountModel.msg  = "没有检索到数据";
                }

                return(Ok(resultCountModel));
            }
            catch (Exception ex)
            {
                resultCountModel.code = -1;
                resultCountModel.msg  = "操作失败:" + ex.ToString();
                return(Ok(resultCountModel));
            }
        }