コード例 #1
0
ファイル: UsersController.cs プロジェクト: tomas0860/SchoolAs
        public ResponseList <UserDto> Get([FromUri] SearchRequest <UserCriteriaDto> request)
        {
            ResponseList <UserDto> response = new ResponseList <UserDto>();

            if (request == null)
            {
                // Configure the Error response.
                response.Code = OperationCode.ResponseCode.ERROR;
                response.ErrorList.Add(MessageResource.GetInstance().GetText("SawDAL_GetListNull", MESSAGE_RESOURCE));
            }
            else
            {
                int?count = null;
                if (request.CountTotal)
                {
                    count = 0;
                }
                AssetContext assetContext = new AssetContext();

                var Users = assetContext.GetUsers(request.Criteria, request.Page, request.Take, ref count);

                if (Users.Any())
                {
                    response.Items      = Users.ToList();
                    response.TotalItems = response.Items.Count;
                    response.Count      = request.CountTotal ? count.Value : 0;
                    response.Code       = OperationCode.ResponseCode.SUCCESS;
                    response.MessageList.Add(MessageResource.GetInstance().GetText("SawDAL_GetListSuccess", MESSAGE_RESOURCE));
                }
                else
                {
                    response.Code = OperationCode.ResponseCode.SUCCESS;
                    response.MessageList.Add(MessageResource.GetInstance().GetText("SawDAL_GetListEmpty", MESSAGE_RESOURCE));
                }
            }

            return(response);
        }