コード例 #1
0
        /// <summary>
        /// 查询报备信息接口
        /// </summary>
        /// <param name="id"></param>
        /// <param name="searchcondition"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public virtual async Task <PagingResponseMessage <BeltLookResponse> > Search(string id, BeltLookSearchRequest searchcondition, CancellationToken cancellationToken = default(CancellationToken))
        {
            var pagingResponse = new PagingResponseMessage <BeltLookResponse>();

            var response = _ibeltLookStore.BeltLookAll().Where(x => !x.IsDeleted);

            if (!string.IsNullOrEmpty(searchcondition.BeltHouse))
            {
                response = response.Where(x => x.BeltHouse.Contains(searchcondition.BeltHouse));
            }


            var result = await response.OrderByDescending(a => a.CreateTime).Skip(searchcondition.PageIndex * searchcondition.PageSize).Take(searchcondition.PageSize).ToListAsync(cancellationToken);

            pagingResponse.TotalCount = await response.CountAsync(cancellationToken);

            pagingResponse.PageIndex = searchcondition.PageIndex;
            pagingResponse.PageSize  = searchcondition.PageSize;

            pagingResponse.Extension = _mapper.Map <List <BeltLookResponse> >(result);

            return(pagingResponse);
        }
コード例 #2
0
        public async Task <PagingResponseMessage <BeltLookResponse> > Search(UserInfo user, [FromBody] BeltLookSearchRequest searchcondition)
        {
            Logger.Trace($"用户{user?.UserName ?? ""}({user?.Id ?? ""})发起请求查询带看信息(Search):\r\n请求参数为:\r\n" + (searchcondition != null ? JsonHelper.ToJson(searchcondition) : ""));

            var response = new PagingResponseMessage <BeltLookResponse>();

            response.Code    = ResponseCodeDefines.NotFound;
            response.Message = "未查询到信息";
            if (!ModelState.IsValid)
            {
                var error  = "";
                var errors = ModelState.Values.ToList();
                foreach (var item in errors)
                {
                    foreach (var e in item.Errors)
                    {
                        error += e.ErrorMessage + "  ";
                    }
                }
                response.Code    = ResponseCodeDefines.ModelStateInvalid;
                response.Message = error;
                Logger.Warn($"用户{user?.UserName ?? ""}({user?.Id ?? ""})查询带看信息(Search)模型验证失败:\r\n{response.Message ?? ""},\r\n请求参数为:\r\n" + (searchcondition != null ? JsonHelper.ToJson(searchcondition) : ""));
                return(response);
            }
            try
            {
                response = await _beltLookManager.Search(user.Id, searchcondition, HttpContext.RequestAborted);

                response.Code    = ResponseCodeDefines.SuccessCode;
                response.Message = "查询成功";
            }
            catch (Exception e)
            {
                response.Code    = ResponseCodeDefines.ServiceError;
                response.Message = "服务器错误:" + e.ToString();
                Logger.Error($"用户{user?.UserName ?? ""}({user?.Id ?? ""})查询带看信息(Search)请求失败:\r\n{response.Message ?? ""},\r\n请求参数为:\r\n" + (searchcondition != null ? JsonHelper.ToJson(searchcondition) : ""));
            }
            return(response);
        }