Пример #1
0
        public HttpResponseMessage GetAll(HttpRequestMessage request, string keyword, int page, int pageSize = 20)
        {
            return(CreateHttpResponse(request, () =>
            {
                int totalRow = 0;
                var user = HttpContext.Current.GetOwinContext().Authentication.User.Identity.Name;
                var lvCode = userManager.FindByNameAsync(user).Result.LevelCode;
                var model = this.dichVuService.GetAll();

                if (keyword != null)
                {
                    model = model.Where(x => (x.IDDichVu.Contains(keyword)) ||
                                        (x.TenDichVu != null && x.TenDichVu.ToLower().Contains(keyword.ToLower())) ||
                                        (x.TenHienThiDichVu != null && x.TenHienThiDichVu.ToLower().Contains(keyword.ToLower())));
                }

                totalRow = model.Count();
                var query = model.OrderByDescending(x => x.IDDichVu).Skip(page * pageSize).Take(pageSize);
                var nhom = nhomService.GetAll();

                var responseData = Mapper.Map <IEnumerable <DanhMucDichVu>, IEnumerable <DanhMucDichVuViewModel> >(query).Select(x => { x.TenNhom = nhom.First(n => n.RowIDNhom == x.MaNhom).TenNhom; return x; }).ToList();
                //var a = responseData.Select(x => { x.TenNhom = ""; return x; }).ToList();

                var paginationSet = new PaginationSet <DanhMucDichVu>()
                {
                    Items = model,
                    Page = page,
                    TotalCount = totalRow,
                    TotalPages = (int)Math.Ceiling((decimal)totalRow / pageSize)
                };
                var response = request.CreateResponse(HttpStatusCode.OK, paginationSet);
                return response;
            }));
        }
Пример #2
0
//        [Authorize(Roles = "DichVuList")]
        public HttpResponseMessage GetAll(HttpRequestMessage request, string keyword, int page, int pageSize = 20)
        {
            return(CreateHttpResponse(request, () =>
            {
                int totalRow = 0;
                var model = this.dichVuService.GetAll();

                totalRow = model.Count();
                var query = model.OrderByDescending(x => x.IDDichVu).Skip(page * pageSize).Take(pageSize);
                var nhom = nhomService.GetAll();

                var responseData = Mapper.Map <IEnumerable <DanhMucDichVu>, IEnumerable <DanhMucDichVuViewModel> >(query).Select(x => { x.TenNhom = nhom.First(n => n.RowIDNhom == x.MaNhom).TenNhom; return x; }).ToList();
                //var a = responseData.Select(x => { x.TenNhom = ""; return x; }).ToList();

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