コード例 #1
0
 public HttpResponseMessage GetAll(HttpRequestMessage request)
 {
     return(CreateHttpResponse(request, () =>
     {
         var lstMenuGroup = menuGroupService.GetAll();
         HttpResponseMessage response = request.CreateResponse(HttpStatusCode.OK, lstMenuGroup);
         return response;
     }));
 }
コード例 #2
0
        public async Task <HttpResponseMessage> GetAll(HttpRequestMessage request)
        {
            var model = await _menuGroupService.GetAll();

            var responseData = Mapper.Map <IEnumerable <MenuGroup>, IEnumerable <MenuGroupViewModel> >(model);

            return(await CreateHttpResponse(request, () =>
            {
                var response = request.CreateResponse(HttpStatusCode.OK, responseData);
                return response;
            }));
        }
コード例 #3
0
        public async Task <HttpResponseMessage> Get(HttpRequestMessage request)
        {
            //return Ok(await _menuGroupService.GetAll()); //cach 2 dung IActionResult
            var listMenuGroup = await _menuGroupService.GetAll();

            var listMenuGroupVm = Mapper.Map <List <MenuGroupViewModel> >(listMenuGroup);

            return(await CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = request.CreateResponse(HttpStatusCode.OK, listMenuGroupVm); //Map
                return response;
            }));
        }
コード例 #4
0
        public JsonResult GetAll(string searchstr, int page, int pageSize = 5)
        {
            var model    = _menuGroupService.GetAll(searchstr);
            var menuList = Mapper.Map <IEnumerable <MenuGroup>, IEnumerable <MenuGroupViewModel> >(model);
            var data     = menuList.
                           Skip((page - 1) * pageSize).
                           Take(pageSize);
            int totalRow = menuList.Count();

            return(Json(new
            {
                data = data,
                total = totalRow,
                status = true
            }, JsonRequestBehavior.AllowGet));
        }
コード例 #5
0
        public HttpResponseMessage GetAll(HttpRequestMessage request, string keyword, int page, int pageSize = 20)
        {
            return(CreateHttpResponse(request, () =>
            {
                int totalRow = 0;
                var model = _menuGroupService.GetAll(keyword);
                totalRow = model.Count();
                var query = model.OrderByDescending(x => x.Name).Skip(page * pageSize).Take(pageSize);

                var responseData = Mapper.Map <IEnumerable <MenuGroup>, IEnumerable <MenuGroupViewModel> >(query);

                var paginationSet = new PaginationSet <MenuGroupViewModel>()
                {
                    Items = responseData,
                    Page = page,
                    TotalCount = totalRow,
                    TotalPages = (int)Math.Ceiling((decimal)totalRow / pageSize)
                };
                var response = request.CreateResponse(HttpStatusCode.OK, paginationSet);
                return response;
            }));
        }