public HttpResponseMessage GetActiveServices(HttpRequestMessage request, int? page, int? pageSize, string filter = null) { int currentPage = page.Value; int currentPageSize = pageSize.Value; int totalServices = new int(); return CreateHttpResponse(request, () => { HttpResponseMessage response = null; List<service> efps = null; if (string.IsNullOrEmpty(filter)) { efps = _efpRepository.FindBy(p => p.active) .Include(i => i.scope_exceeding) .OrderBy(p => p.name) .Skip(currentPage * currentPageSize) .Take(currentPageSize) .ToList(); totalServices = _efpRepository.FindBy(p => p.active).Count(); } else { efps = _efpRepository.FindBy(p => p.active && p.name.Contains(filter)) .Include(i => i.scope_exceeding) .OrderBy(p => p.name) .Skip(currentPage * currentPageSize) .Take(currentPageSize) .ToList(); totalServices = _efpRepository.FindBy(p => p.active && p.name.Contains(filter)).Count(); } var servicesVM = Mapper.Map<IEnumerable<service>, IEnumerable<servicesViewModel>>(efps); PaginationSet<servicesViewModel> pagedSet = new PaginationSet<servicesViewModel>() { Page = currentPage, TotalCount = totalServices, TotalPages = (int)Math.Ceiling((decimal)totalServices / currentPageSize), Items = servicesVM }; response = request.CreateResponse(HttpStatusCode.OK, pagedSet); return response; }); }
public async Task<IActionResult> Get(int? page, int? pageSize) { PaginationSet<AlbumViewModel> pagedSet = new PaginationSet<AlbumViewModel>(); try { if (await _authorizationService.AuthorizeAsync(User, "AdminOnly")) { int currentPage = page.Value; int currentPageSize = pageSize.Value; List<Album> _albums = null; int _totalAlbums = new int(); _albums = _albumRepository .AllIncluding(a => a.Photos) .OrderBy(a => a.Id) .Skip(currentPage * currentPageSize) .Take(currentPageSize) .ToList(); _totalAlbums = _albumRepository.GetAll().Count(); IEnumerable<AlbumViewModel> _albumsVM = Mapper.Map<IEnumerable<Album>, IEnumerable<AlbumViewModel>>(_albums); pagedSet = new PaginationSet<AlbumViewModel>() { Page = currentPage, TotalCount = _totalAlbums, TotalPages = (int)Math.Ceiling((decimal)_totalAlbums / currentPageSize), Items = _albumsVM }; } else { StatusCodeResult _codeResult = new StatusCodeResult(401); return new ObjectResult(_codeResult); } } catch (Exception ex) { _loggingRepository.Add(new Error() { Message = ex.Message, StackTrace = ex.StackTrace, DateCreated = DateTime.Now }); _loggingRepository.Commit(); } return new ObjectResult(pagedSet); }
public HttpResponseMessage Search(HttpRequestMessage request, int? page, int? pageSize, string filter = null) { var currentPage = page.Value; var currentPageSize = pageSize.Value; return CreateHttpResponse(request, () => { HttpResponseMessage response = null; List<Customer> customers = null; var totalMovies = new int(); if (!string.IsNullOrEmpty(filter)) { filter = filter.Trim().ToLower(); customers = _customersRepository.GetAll() .OrderBy(c => c.Id) .Where(c => c.LastName.ToLower().Contains(filter) || c.IdentityCard.ToLower().Contains(filter) || c.FirstName.ToLower().Contains(filter)) .ToList(); } else { customers = _customersRepository.GetAll().ToList(); } totalMovies = customers.Count(); customers = customers.Skip(currentPage*currentPageSize) .Take(currentPageSize) .ToList(); var customersVM = Mapper.Map<IEnumerable<Customer>, IEnumerable<CustomerViewModel>>(customers); var pagedSet = new PaginationSet<CustomerViewModel> { Page = currentPage, TotalCount = totalMovies, TotalPages = (int) Math.Ceiling((decimal) totalMovies/currentPageSize), Items = customersVM }; response = request.CreateResponse(HttpStatusCode.OK, pagedSet); return response; }); }
public PaginationSet<PhotoViewModel> Get(int? page, int? pageSize) { PaginationSet<PhotoViewModel> pagedSet = null; try { int currentPage = page.Value; int currentPageSize = pageSize.Value; List<Photo> _photos = null; int _totalPhotos = new int(); _photos = _photoRepository .AllIncluding(p => p.Album) .OrderBy(p => p.Id) .Skip(currentPage * currentPageSize) .Take(currentPageSize) .ToList(); _totalPhotos = _photoRepository.GetAll().Count(); IEnumerable<PhotoViewModel> _photosVM = Mapper.Map<IEnumerable<Photo>, IEnumerable<PhotoViewModel>>(_photos); pagedSet = new PaginationSet<PhotoViewModel>() { Page = currentPage, TotalCount = _totalPhotos, TotalPages = (int)Math.Ceiling((decimal)_totalPhotos / currentPageSize), Items = _photosVM }; } catch (Exception ex) { _loggingRepository.Add(new Error() { Message = ex.Message, StackTrace = ex.StackTrace, DateCreated = DateTime.Now }); _loggingRepository.Commit(); } return pagedSet; }
//[AllowAnonymous] public IActionResult GetAllUsers(int? page=0, int? pageSize = 5) { int currentPage = page.Value; int currentPageSize = pageSize.Value; PaginationSet<ApplicationUser> pagedSet = new PaginationSet<ApplicationUser>(); IEnumerable<ApplicationUser> users = _context.Users .Skip(currentPage * currentPageSize) .Take(currentPageSize). ToList(); int _totalUser = _context.Users.ToList().Count; pagedSet = new PaginationSet<ApplicationUser>() { Page = currentPage, TotalCount = _totalUser, TotalPages = (int)Math.Ceiling((decimal)_totalUser / currentPageSize), Items = users }; return new ObjectResult(pagedSet); }
public HttpResponseMessage GetListPaging(HttpRequestMessage request, int page, int pageSize, string filter = null) { return(CreateHttpResponse(request, () => { HttpResponseMessage response = null; var query = AppRoleManager.Roles; if (page == 0) { var model = query.OrderBy(x => x.Name); IEnumerable <ApplicationRoleViewModel> modelVm = Mapper.Map <IEnumerable <AppRole>, IEnumerable <ApplicationRoleViewModel> >(model); response = request.CreateResponse(HttpStatusCode.OK, modelVm); } else { int totalRow = 0; if (!string.IsNullOrEmpty(filter)) { query = query.Where(x => x.Description.Contains(filter)); } totalRow = query.Count(); var model = query.OrderBy(x => x.Name).Skip((page - 1) * pageSize).Take(pageSize); IEnumerable <ApplicationRoleViewModel> modelVm = Mapper.Map <IEnumerable <AppRole>, IEnumerable <ApplicationRoleViewModel> >(model); PaginationSet <ApplicationRoleViewModel> pagedSet = new PaginationSet <ApplicationRoleViewModel>() { PageIndex = page, TotalRows = totalRow, PageSize = pageSize, Items = modelVm }; response = request.CreateResponse(HttpStatusCode.OK, pagedSet); } return response; })); }
public HttpResponseMessage GetListPaging(HttpRequestMessage request, int page, int pageSize, string filter = null) { return(CreateHttpResponse(request, () => { HttpResponseMessage response = null; int totalRow; var model = _courseCategoryService.GetCategories(page, pageSize, out totalRow, filter); var modelVm = Mapper.Map <IEnumerable <CourseCategory>, IEnumerable <CourseCategoryViewModel> >(model); var pagedSet = new PaginationSet <CourseCategoryViewModel> { Page = page, TotalCount = totalRow, TotalPages = (int)Math.Ceiling((decimal)totalRow / pageSize), Items = modelVm }; response = request.CreateResponse(HttpStatusCode.OK, pagedSet); return response; })); }
public async Task <PaginationSet <ContactViewModel> > GetAllContact(string keyword, bool isFriend, string currentUser, int page = 1, int pageSize = 8) { var query = await GetMultiAsync(x => (x.ContactSentId == currentUser || x.ContactReceivedId == currentUser) && x.IsFriend); if (!string.IsNullOrWhiteSpace(keyword)) { query = query.Where(x => x.PhoneNumber.Contains(keyword) || x.FullNameContactReceived.Contains(keyword) || x.FullNameContactSent.Contains(keyword)); } query = query.OrderByDescending(x => x.FullNameContactSent) .Skip((page - 1) * pageSize).Take(pageSize); int totalRow = query.Count(); var res = new PaginationSet <ContactViewModel>() { Page = page, TotalCount = totalRow, TotalPages = (int)Math.Ceiling((decimal)totalRow / pageSize), Items = _mapper.ProjectTo <ContactViewModel>(query).ToList(), MaxPage = int.Parse(ConfigHelper.GetByKey("MaxPage")) }; return(res); }
public ActionResult Search(string keyword, int page = 1, string sort = "") { //Get ProductCategory ViewBag.keyword = keyword; int pageSize = int.Parse(ConfigHelper.GetByKey("pageSize")); int totalRow = 0; var productModel = _productService.Search(keyword, page, pageSize, sort, out totalRow); var productViewModel = Mapper.Map <IEnumerable <Product>, IEnumerable <ProductViewModel> >(productModel); int totalPage = (int)Math.Ceiling((double)(totalRow / pageSize)); var paginationSet = new PaginationSet <ProductViewModel>() { Page = page, PageSize = pageSize, TotalPages = totalPage, TotalCount = totalRow, MaxPage = int.Parse(ConfigHelper.GetByKey("MaxPage")), Items = productViewModel }; return(View(paginationSet)); }
public IActionResult GetAllBooks(string keyword, int page = 1, int pageSize = 10, int sort = 0, string criteria = "BookId") { try { var list = _bookService.GetBooks(keyword); var listforDto = _mapper.Map <IEnumerable <Book>, IEnumerable <BookForListDto> >(list); int totalCount = list.Count(); //return Ok(totalCount); var response = _bookService.GetBooksPerPage(listforDto, page, pageSize, sort, criteria); var paginationSet = new PaginationSet <BookForListDto>() { Total = totalCount, Items = response }; return(Ok(paginationSet)); } catch (System.Exception) { return(BadRequest()); } }
public HttpResponseMessage ThongKeGiaHan(HttpRequestMessage request, int page, int pageSize, string fromDate, string toDate) { return(CreateHttpResponse(request, () => { var model = _thongKeService.GetAll(CurrentLink.ThongKeGiaHan + "?fromDate=" + fromDate + "&toDate=" + toDate); int totalRow = 0; totalRow = model.Count(); var query = model.OrderBy(x => x.Id).Skip(page * pageSize).Take(pageSize); PaginationSet <ThongKeGianHanViewModel> pagedSet = new PaginationSet <ThongKeGianHanViewModel>() { Page = page, TotalCount = totalRow, TotalPages = (int)Math.Ceiling((decimal)totalRow / pageSize), Items = query }; var response = request.CreateResponse(HttpStatusCode.OK, pagedSet); return response; })); }
public HttpResponseMessage GetbyFilter(HttpRequestMessage request, int?teamId, string userName, string email, string phoneNumber, int?page, int pageSize = 10) { try { var currentPage = page.HasValue ? page.Value : 0; int total = 0; var userService = IoC.Resolve <IUserService>(); var items = userService.GetbyFilter(CurrentUser.Instance.User.Id, CurrentUser.Instance.User.ComId, teamId, userName, email, phoneNumber, currentPage, pageSize, out total).Select(p => new UserViewModel { Id = p.Id, UserName = p.UserName, Email = p.Email, PhoneNumber = p.PhoneNumber, Address = p.Address, BirthDay = p.BirthDay.HasValue ? p.BirthDay.Value.ToString("dd/MM/yyyy") : string.Empty, CreateDate = p.CreateDate.ToString("dd/MM/yyyy"), FullName = p.FullName, TeamId = p.TeamId, ComId = p.ComId, Status = p.Status }).ToList(); var result = new PaginationSet <UserViewModel> { Page = currentPage, PageSize = pageSize, TotalCount = total, Items = items }; return(request.CreateResponse(HttpStatusCode.OK, result)); } catch (Exception ex) { Log(ex); return(request.CreateResponse(HttpStatusCode.BadRequest, TextHelper.ERROR_SYSTEM)); } }
public async Task <ActionResult> TimKiemNguoiDungPhanTrang(string MaNhom = "GP01", string tuKhoa = "", int soTrang = 1, int soPhanTuTrenTrang = 1) { var ktNhom = db.Nhom.Any(n => n.MaNhom == MaNhom); if (!ktNhom) { // I wish to return an error response how can i do that? var response = await tbl.TBLoi(ThongBaoLoi.Loi400, "Mã nhóm không hợp lệ!"); return(response); } IEnumerable <NguoiDungVM> lstResult = db.NguoiDung.Where(n => n.MaNhom == MaNhom && n.BiDanh.Contains(tuKhoa)).Select(n => new NguoiDungVM { TaiKhoan = n.TaiKhoan, HoTen = n.HoTen, Email = n.Email, SoDt = n.SoDt, MatKhau = n.MatKhau, MaLoaiNguoiDung = n.MaLoaiNguoiDung }); if (lstResult.Count() == 0) { lstResult = db.NguoiDung.Where(n => n.MaNhom == MaNhom && n.TaiKhoan == tuKhoa).Select(n => new NguoiDungVM { TaiKhoan = n.TaiKhoan, HoTen = n.HoTen, Email = n.Email, SoDt = n.SoDt, MatKhau = n.MatKhau, MaLoaiNguoiDung = n.MaLoaiNguoiDung }); } if (lstResult.Count() == 0) { lstResult = db.NguoiDung.Where(n => n.MaNhom == MaNhom && n.SoDt.Contains(tuKhoa)).Select(n => new NguoiDungVM { TaiKhoan = n.TaiKhoan, HoTen = n.HoTen, Email = n.Email, SoDt = n.SoDt, MatKhau = n.MatKhau, MaLoaiNguoiDung = n.MaLoaiNguoiDung }); } PaginationSet <NguoiDungVM> result = new PaginationSet <NguoiDungVM>(); result.CurrentPage = soTrang; result.TotalPages = (lstResult.Count() / soPhanTuTrenTrang) + 1; result.Items = lstResult.Skip((soTrang - 1) * soPhanTuTrenTrang).Take(soPhanTuTrenTrang); result.TotalCount = lstResult.Count(); return(Ok(result)); }
public async Task <IHttpActionResult> Get(Guid cadenaId, int?page = 1, int?pageSize = 10) { var pagedSet = new PaginationSet <LocalDto>(); try { if (await _authorizationService.AuthorizeAsync(User)) { var currentPage = page.Value; var currentPageSize = pageSize.Value; var locales = _localService.GetPagedList(cadenaId, currentPage > 0 ? currentPage - 1 : currentPage, currentPageSize); var localesDto = Mapper.Map <IEnumerable <Local>, IEnumerable <LocalDto> >(locales.Items); pagedSet = new PaginationSet <LocalDto> { Page = currentPage, TotalCount = (int)locales.TotalCount, TotalPages = locales.TotalPages, Items = localesDto }; } else { var codeResult = new CodeResultStatus(401); return(Ok(codeResult)); } } catch (Exception e) { Console.WriteLine(e); throw; } return(Ok(pagedSet)); }
public async Task <IHttpActionResult> GetByLocal(Guid localId, int?page = 1, int?pageSize = 10) { var pagedSet = new PaginationSet <ImagenLocalDto>(); try { if (await _authorizationService.AuthorizeAsync(User)) { var currentPage = page.Value; var currentPageSize = pageSize.Value; var dbEvaluations = _localService.GetImages(localId, currentPage > 0 ? currentPage - 1 : currentPage, currentPageSize); var evaluations = Mapper.Map <PagedList <ImagenLocal>, PagedList <ImagenLocalDto> >(dbEvaluations); pagedSet = new PaginationSet <ImagenLocalDto> { Page = currentPage, TotalCount = (int)evaluations.TotalCount, TotalPages = evaluations.TotalPages, Items = evaluations.Items }; } else { var codeResult = new CodeResultStatus(401); return(Ok(codeResult)); } } catch (Exception e) { Console.WriteLine(e); throw; } return(Ok(pagedSet)); }
public HttpResponseMessage GetAll(HttpRequestMessage req, string keyword, int page, int pageSize = 20) { return(CreateHttpResponse(req, () => { HttpResponseMessage res = null; int totalRow = 0; var employees = _employeeService.GetAll(keyword); totalRow = employees.Count(); var query = employees.OrderByDescending(x => x.Name).Skip(page * pageSize).Take(pageSize); var resData = Mapper.Map <IEnumerable <Employee>, IEnumerable <EmployeeViewModel> >(query); var paginationSet = new PaginationSet <EmployeeViewModel>() { Items = resData, Page = page, TotalRow = totalRow, TotalPage = (int)Math.Ceiling((decimal)totalRow / pageSize) }; res = req.CreateResponse(HttpStatusCode.OK, paginationSet); return res; })); }
public HttpResponseMessage GetListQuestionAnswer(HttpRequestMessage request, int page, int pageSize, string botId) { return(CreateHttpResponse(request, () => { HttpResponseMessage response = null; int totalRow = 0; string filter = "q.BotID = " + botId; var lstSearchQna = _moduleSearchEngineService.GetListMdQnA(filter, "", page, pageSize, null).ToList(); if (lstSearchQna.Count() != 0) { totalRow = lstSearchQna[0].Total; } var paginationSet = new PaginationSet <MdQnAViewModel>() { Items = lstSearchQna, Page = page, TotalCount = totalRow, MaxPage = pageSize, TotalPages = (int)Math.Ceiling((decimal)totalRow / pageSize) }; response = request.CreateResponse(HttpStatusCode.OK, paginationSet); return response; })); }
public HttpResponseMessage GetListPaging(HttpRequestMessage request, int page, int pageSize, string filter = null) { return(CreateHttpResponse(request, () => { HttpResponseMessage response = null; int totalRow = 0; var model = _appLicationUserManager.Users; totalRow = model.Count(); var query = model.OrderByDescending(x => x.CreatedDate).Skip(page * pageSize).Take(pageSize); IEnumerable <ApplicationUserViewModel> modelVm = Mapper.Map <IEnumerable <ApplicationUser>, IEnumerable <ApplicationUserViewModel> >(query); PaginationSet <ApplicationUserViewModel> pagedSet = new PaginationSet <ApplicationUserViewModel>() { Page = page, TotalCount = totalRow, TotalPages = (int)Math.Ceiling((decimal)totalRow / pageSize), Items = modelVm }; response = request.CreateResponse(HttpStatusCode.OK, pagedSet); return response; })); }
public HttpResponseMessage GetAll(HttpRequestMessage request, int?categoryId, string keyword, int page, int pageSize = 20) { Func <HttpResponseMessage> func = () => { int totalRow = 0; var model = _productService.GetAll(categoryId, keyword); totalRow = model.Count(); var query = model.OrderByDescending(x => x.CreatedDate).Skip(page - 1 * pageSize).Take(pageSize).ToList(); var responseData = Mapper.Map <List <Product>, List <ProductViewModel> >(query); var paginationSet = new PaginationSet <ProductViewModel>() { Items = responseData, PageIndex = page, PageSize = pageSize, TotalRows = totalRow }; var response = request.CreateResponse(HttpStatusCode.OK, paginationSet); return(response); }; return(CreateHttpResponse(request, func)); }
public HttpResponseMessage GetListPaging(HttpRequestMessage request, int page, int pageSize, string filter = null) { return(CreateHttpResponse(request, () => { HttpResponseMessage response = null; int totalRow = 0; var model = _appGroupService.GetAll(page, pageSize, out totalRow, filter).OrderByDescending(x => x.ID); IEnumerable <ApplicationGroupViewModel> modelVm = Mapper.Map <IEnumerable <ApplicationGroup>, IEnumerable <ApplicationGroupViewModel> >(model); PaginationSet <ApplicationGroupViewModel> pagedSet = new PaginationSet <ApplicationGroupViewModel>() { Page = page, TotalCount = totalRow, TotalPages = (int)Math.Ceiling((decimal)totalRow / pageSize), Items = modelVm }; response = request.CreateResponse(HttpStatusCode.OK, pagedSet); return response; })); }
public IActionResult GetAll([FromBody] SearchDTO searchItem) { if (searchItem.PageSize == 0) { searchItem.PageSize = 20; } int totalRow = 0; var suppliers = this._supplierRepository.GetAll( searchItem.Keyword, searchItem.Page, searchItem.PageSize, out totalRow); var suppliersVm = this._mapper.Map <IEnumerable <Supplier>, IEnumerable <SupplierViewModel> >(suppliers); var pagingVm = new PaginationSet <SupplierViewModel>(); pagingVm.Items = suppliersVm; pagingVm.Page = searchItem.Page; pagingVm.TotalCount = totalRow; pagingVm.TotalPage = (int)Math.Ceiling(((decimal)totalRow / searchItem.PageSize)); pagingVm.MaxPage = pagingVm.TotalPage - 1; return(Ok(pagingVm)); }
public HttpResponseMessage GetAll(HttpRequestMessage request, string keyword, int page, int pageSize = 6) { return(CreateHttpResponse(request, () => { int totalRow = 0; var model = _pageService.GetAll(keyword); totalRow = model.Count(); var query = model.OrderByDescending(x => x.CreatedDate).Skip(page * pageSize).Take(pageSize); var responseData = Mapper.Map <IEnumerable <Page>, IEnumerable <PageViewModel> >(query); var paginationSet = new PaginationSet <PageViewModel>() { Items = responseData, Page = page, TotalCount = totalRow, TotalPages = (int)Math.Ceiling((decimal)totalRow / pageSize) }; var response = request.CreateResponse(HttpStatusCode.OK, paginationSet); return response; })); }
public PaginationSet <ProductViewModel> Get(int page, int pageSize) { PaginationSet <ProductViewModel> pagedSet = null; try { var products = _productRepository .AllIncluding(p => p.ProductStatuses, p => p.ProductType) .OrderBy(p => p.Name) .Skip(page * pageSize) .Take(pageSize) .ToList(); var totalCount = _productRepository.GetAll().Count(); var viewModels = Mapper.Map <IEnumerable <Product>, IEnumerable <ProductViewModel> >(products); pagedSet = new PaginationSet <ProductViewModel>() { Page = page, TotalCount = totalCount, TotalPages = (int)Math.Ceiling((decimal)totalCount / pageSize), Items = viewModels }; } catch (Exception ex) { _loggingRepository.Add(new Error() { Message = ex.Message, StackTrace = ex.StackTrace, DateCreated = DateTime.Now }); _loggingRepository.Commit(); } return(pagedSet); }
public HttpResponseMessage GetListQuestionAnswer(HttpRequestMessage request, int page, int pageSize, string botId) { return(CreateHttpResponse(request, () => { HttpResponseMessage response = null; int totalRow = 0; string filter = "BotID = " + botId; var lstHistory = _historyService.GetHistoryByBotId(filter, "", page, pageSize, null).ToList(); if (lstHistory.Count() != 0) { totalRow = lstHistory[0].Total; } var paginationSet = new PaginationSet <StoreProcHistoryViewModel>() { Items = lstHistory, Page = page, TotalCount = totalRow, MaxPage = pageSize, TotalPages = (int)Math.Ceiling((decimal)totalRow / pageSize) }; response = request.CreateResponse(HttpStatusCode.OK, paginationSet); return response; })); }
public IActionResult Index(int page = 1) { int pageSize = 3; PaginationSet <IdentityUser> pagedSet = null; int currentPage = page; int currentPageSize = pageSize; List <IdentityUser> _users = null; int _totalusers = new int(); var u = _userManager.Users.ToList(); _users = u .OrderBy(p => p.UserName) .Skip(((currentPage) * currentPageSize) - currentPage) .Take(currentPageSize) .ToList(); var item = _users; _totalusers = _userManager.Users.Count(); pagedSet = new PaginationSet <IdentityUser>() { Page = currentPage, TotalCount = _totalusers, TotalPages = (int)Math.Ceiling(_totalusers / (double)currentPageSize), Items = item }; ViewBag.Roles = _roleManager.Roles.ToList().ToListViewModel(); return(View(pagedSet)); }
public PaginationSet <PhotoViewModel> Get(int id, int?page, int?pageSize) { PaginationSet <PhotoViewModel> pagedSet = null; try { int currentPage = page.Value; int currentPageSize = pageSize.Value; List <Photo> photos = null; int totalPhotos = new int(); Album album = this.albumRepo.GetSingle(a => a.Id == id, a => a.Photos); photos = album.Photos.OrderBy(p => p.Id).Skip(currentPage * currentPageSize).Take(currentPage).ToList(); totalPhotos = album.Photos.Count(); IEnumerable <PhotoViewModel> _photosVM = Mapper.Map <IEnumerable <Photo>, IEnumerable <PhotoViewModel> >(photos); pagedSet = new PaginationSet <PhotoViewModel>() { Page = currentPage, TotalCount = totalPhotos, TotalPages = (int)Math.Ceiling((decimal)totalPhotos / currentPageSize), Items = _photosVM }; } catch (Exception ex) { this.loggingRepo.Add(new Error() { Message = ex.Message, StackTrace = ex.StackTrace, DateCreated = DateTime.Now }); this.loggingRepo.Commit(); } return(pagedSet); }
public HttpResponseMessage GetListPaging(HttpRequestMessage request, string startDate, string endDate, string customerName, string paymentStatus, int page, int pageSize, string filter = null) { return(CreateHttpResponse(request, () => { HttpResponseMessage response = null; int totalRow = 0; var model = _orderService.GetList(startDate, endDate, customerName, paymentStatus, page, pageSize, out totalRow); List <OrderViewModel> modelVm = Mapper.Map <List <Order>, List <OrderViewModel> >(model); PaginationSet <OrderViewModel> pagedSet = new PaginationSet <OrderViewModel>() { PageIndex = page, PageSize = pageSize, TotalRows = totalRow, Items = modelVm, }; response = request.CreateResponse(HttpStatusCode.OK, pagedSet); return response; })); }
public async Task <IActionResult> Get(int?page, int?pageSize) { PaginationSet <WalkViewModel> pagedSet = new PaginationSet <WalkViewModel>(); try { //if (_signInManager.IsSignedIn(User)) if (true) { int currentPage = page.Value; int currentPageSize = pageSize.Value; List <Walk> _walks = null; int _totalWalks = new int(); //if (await _authorizationService.AuthorizeAsync(User, "AdminOnly")) if (true) { _walks = _walkRepository .AllIncluding(w => w.WalkSights) .OrderBy(w => w.Id) .Skip(currentPage * currentPageSize) .Take(currentPageSize) .ToList(); _totalWalks = _walkRepository.GetAll().Count(); } else { _walks = _walkRepository .FindBy(w => w.UserId == _userManager.GetUserId(User)) .OrderBy(w => w.Id) .Skip(currentPage * currentPageSize) .Take(currentPageSize) .ToList(); _totalWalks = _walks.Count(); } IEnumerable <WalkViewModel> _walksVM = Mapper.Map <IEnumerable <Walk>, IEnumerable <WalkViewModel> >(_walks); pagedSet = new PaginationSet <WalkViewModel>() { Page = currentPage, TotalCount = _totalWalks, TotalPages = (int)Math.Ceiling((decimal)_totalWalks / currentPageSize), Items = _walksVM }; } else { CodeResultStatus _codeResult = new CodeResultStatus(401); return(new ObjectResult(_codeResult)); } } catch (Exception ex) { _loggingRepository.Add(new Error() { Message = ex.Message, StackTrace = ex.StackTrace, CreatedDate = DateTime.Now }); _loggingRepository.Commit(); } return(new ObjectResult(pagedSet)); }
public IActionResult GetAdmin(int? page, int? pageSize = 12) { int currentPage = page.Value; int currentPageSize = pageSize.Value; PaginationSet<CardViewModel> pagedSet = new PaginationSet<CardViewModel>(); //var totalPages = (int)Math.Ceiling((double)totalSchedules / pageSize); IEnumerable<Card> _cards = _cardRepo .FindBy(c => c.IsDeleted == false) .OrderByDescending(u => u.DateCreated) .Skip(currentPage * currentPageSize) .Take(currentPageSize) .ToList(); int _totalCard = _cardRepo.FindBy(c => c.IsDeleted == false).Count(); //IEnumerable<CardViewModel> _cardVM=Mapper.Map<IEnumerable<Card>,IEnumerable<CardViewModel>>(_cards); IEnumerable<CardViewModel> _cardVM = Mapper.Map<IEnumerable<Card>, IEnumerable<CardViewModel>>(_cards); pagedSet = new PaginationSet<CardViewModel>() { Page = currentPage, TotalCount = _totalCard, TotalPages = (int)Math.Ceiling((decimal)_totalCard / currentPageSize), Items = _cardVM }; return new OkObjectResult(pagedSet); }
public IActionResult GetAllSubcribers(string keyword, int page = 1, int pageSize = 10, int sort = 0, string criteria = "subcriberid") { try { var response = _subcriberService.GetSubcribers(keyword); int totalCount = response.Count(); criteria = criteria.ToLower(); #region Sort by criteria if (criteria.Equals("subcriberid")) { if (sort == 0) { response = response.OrderByDescending(x => x.SubcriberId).Skip((page - 1) * pageSize).Take(pageSize); } else { response = response.OrderBy(x => x.SubcriberId).Skip((page - 1) * pageSize).Take(pageSize); } } else if (criteria.Equals("email")) { if (sort == 0) { response = response.OrderByDescending(x => x.Email).Skip((page - 1) * pageSize).Take(pageSize); } else { response = response.OrderBy(x => x.Email).Skip((page - 1) * pageSize).Take(pageSize); } } else //if (criteria.Equals("createdate")) { if (sort == 0) { response = response.OrderByDescending(x => x.CreatedDate.Year) .ThenByDescending(x => x.CreatedDate.Month) .ThenByDescending(x => x.CreatedDate.Day) .Skip((page - 1) * pageSize).Take(pageSize); } else { response = response.OrderBy(x => x.CreatedDate.Year) .ThenBy(x => x.CreatedDate.Month) .ThenBy(x => x.CreatedDate.Day) .Skip((page - 1) * pageSize).Take(pageSize); } } #endregion var paginationSet = new PaginationSet <Subcriber>() { Items = response, Total = totalCount, }; return(Ok(paginationSet)); } catch (System.Exception) { return(BadRequest()); } }
public TransactionCustomViewModel() { Transaction = new PaginationSet <TransactionViewModel>(); }
public HttpResponseMessage Search(HttpRequestMessage request, int id, int? page, int? pageSize, string filter = null) { int currentPage = page.Value; int currentPageSize = pageSize.Value; return CreateHttpResponse(request, () => { HttpResponseMessage response = null; List<Person> persons = null; int totalPersons = new int(); if (!string.IsNullOrEmpty(filter)) { filter = filter.Trim().ToLower(); persons = _personRepository.FindBy(c => (c.SurName.ToLower().Contains(filter.ToLower()) || c.FirstName.ToLower().Contains(filter.ToLower()) || c.NhsNumber.ToLower().Contains(filter.ToLower()) ) && (c.FamilyId == id) && c.Deleted == false) .OrderBy(c => c.SurName) .Skip(currentPage * currentPageSize) .Take(currentPageSize) .ToList(); totalPersons = _personRepository .FindBy(c => (c.SurName.ToLower().Contains(filter.ToLower()) || c.FirstName.ToLower().Contains(filter.ToLower())) && c.Deleted == false) .Count(c => (c.SurName.ToLower().Contains(filter.ToLower()) || c.FirstName.ToLower().Contains(filter.ToLower())) && c.Deleted == false); } else { persons = _personRepository .FindBy(c => c.FamilyId == id && c.Deleted == false) .OrderBy(c => c.ID) .Skip(currentPage * currentPageSize) .Take(currentPageSize) .ToList(); totalPersons = _personRepository .FindBy(c => c.FamilyId == id && c.Deleted == false).Count(); } IEnumerable<PersonViewModel> personsVM = Mapper.Map<IEnumerable<Person>, IEnumerable<PersonViewModel>>(persons); PaginationSet<PersonViewModel> pagedSet = new PaginationSet<PersonViewModel>() { Page = currentPage, TotalCount = totalPersons, TotalPages = (int)Math.Ceiling((decimal)totalPersons / currentPageSize), Items = personsVM }; response = request.CreateResponse<PaginationSet<PersonViewModel>>(HttpStatusCode.OK, pagedSet); return response; }); }
private HttpResponseMessage HttpResponseMessage(HttpRequestMessage request, string filter, int currentPage, int currentPageSize) { List<Book> books; if (!string.IsNullOrEmpty(filter)) { books = _booksRepository.GetAll() .OrderBy(m => m.Id) .Where(m => m.Title.ToLower().Contains(filter.ToLower().Trim())) .ToList(); } else { books = _booksRepository.GetAll().ToList(); } var totalMovies = books.Count(); books = books.Skip(currentPage*currentPageSize).Take(currentPageSize).ToList(); IEnumerable<BookViewModel> bookViewModels = Mapper.Map<IEnumerable<Book>, IEnumerable<BookViewModel>>(books); PaginationSet<BookViewModel> pagedSet = new PaginationSet<BookViewModel>() { Page = currentPage, TotalCount = totalMovies, TotalPages = (int) Math.Ceiling((decimal) totalMovies/currentPageSize), Items = bookViewModels }; var response = request.CreateResponse<PaginationSet<BookViewModel>>(HttpStatusCode.OK, pagedSet); return response; }
public HttpResponseMessage GetAll(HttpRequestMessage request, int page, int pageSize, string batDau, string ketThuc, bool vanglai, bool thang, string sort, string maytinh, string nhanvien) { return(CreateHttpResponse(request, () => { HttpContext.Current.Session[CommonConstants.SessionThongKeNhanh] = new List <ThongKeNhanhViewModel>(); DateTime _batdau = Convert.ToDateTime(batDau); DateTime _ketthuc = Convert.ToDateTime(ketThuc); var resultRa = _thongKeNhanhService.GetAll(batDau, ketThuc); var resultGiaHan = _giaHanService.GetAll(batDau, ketThuc); if (!resultRa.IsSuccessStatusCode) { return request.CreateErrorResponse(resultRa.StatusCode, resultRa.Content.ReadAsStringAsync().Result); } if (!resultGiaHan.IsSuccessStatusCode) { return request.CreateErrorResponse(resultGiaHan.StatusCode, resultGiaHan.Content.ReadAsStringAsync().Result); } IEnumerable <Ra> lst_ra = resultRa.Content.ReadAsAsync <IEnumerable <Ra> >().Result.ToList(); List <GiaHan> lst_giahan = resultGiaHan.Content.ReadAsAsync <IEnumerable <GiaHan> >().Result.ToList(); if (!string.IsNullOrEmpty(maytinh)) { List <string> lst_maytinh_selected = new List <string>(); var listItem = new JavaScriptSerializer().Deserialize <List <string> >(maytinh); foreach (var item in listItem) { lst_maytinh_selected.Add(item); } lst_ra = lst_ra.Where(_ra => lst_maytinh_selected.Contains(_ra.MayTinhId_Ra)).ToList(); lst_giahan = lst_giahan.Where(_gh => lst_maytinh_selected.Contains(_gh.MayTinhId)).ToList(); } else if (!string.IsNullOrEmpty(nhanvien)) { List <string> lst_nhanvien_selected = new List <string>(); var listItem = new JavaScriptSerializer().Deserialize <List <string> >(nhanvien); foreach (var item in listItem) { lst_nhanvien_selected.Add(item); } lst_ra = lst_ra.Where(_ra => lst_nhanvien_selected.Contains(_ra.NhanVienId_Ra)).ToList(); lst_giahan = lst_giahan.Where(_gh => lst_nhanvien_selected.Contains(_gh.NhanVienId)).ToList(); } List <ThongKeNhanhViewModel> listData = new List <ThongKeNhanhViewModel>(); int STT = 1; switch (sort) { case "ngay": do { ThongKeNhanhViewModel giaHanVm = new ThongKeNhanhViewModel(); giaHanVm.STT = STT; STT++; giaHanVm.MoTa = "Ngày " + _batdau.ToString("dd/MM/yyyy"); string _luot = ""; int _tongluot = 0; long _tongtien = 0; if (vanglai) { int _count = lst_ra.Where(_ra => (_ra.GioRa.Day == _batdau.Day) && (_ra.GioRa.Month == _batdau.Month) && (_ra.GioRa.Year == _batdau.Year) && (_ra.LoaiVeId > 0)).Count(); _luot += _count + " vãng lai"; _tongluot += _count; _tongtien += lst_ra.Where(_ra => (_ra.GioRa.Day == _batdau.Day) && (_ra.GioRa.Month == _batdau.Month) && (_ra.GioRa.Year == _batdau.Year)).Sum(_ra => _ra.GiaVe).Value; } if (thang) { if (_luot != "") { _luot += ", "; } int _count = lst_ra.Where(_ra => (_ra.GioRa.Day == _batdau.Day) && (_ra.GioRa.Month == _batdau.Month) && (_ra.GioRa.Year == _batdau.Year) && (_ra.LoaiVeId < 0)).Count(); _luot += _count + " vé tháng"; _tongluot += _count; _tongtien += lst_giahan.Where(_gh => (_gh.NgayGiaHan.Value.Day == _batdau.Day) && (_gh.NgayGiaHan.Value.Month == _batdau.Month) && (_gh.NgayGiaHan.Value.Year == _batdau.Year)).Sum(_ra => _ra.GiaVe).Value; } giaHanVm.SoLuotVao = _luot; giaHanVm.TongTien = _tongtien; if (_tongluot != 0) { giaHanVm.TrungBinh = Convert.ToInt64(_tongtien / _tongluot); } else { giaHanVm.TrungBinh = 0; } listData.Add(giaHanVm); _batdau = _batdau.AddDays(1); } while (_batdau <= _ketthuc); break; case "thang": do { ThongKeNhanhViewModel giaHanVm = new ThongKeNhanhViewModel(); giaHanVm.STT = STT; STT++; giaHanVm.MoTa = "Từ ngày: " + _batdau.ToString("dd/MM/yyyy") + " đến ngày: " + (new DateTime(_batdau.Year, _batdau.Month, DateTime.DaysInMonth(_batdau.Year, _batdau.Month))).ToString("dd/MM/yyyy"); string _luot = ""; int _tongluot = 0; long _tongtien = 0; if (vanglai) { int _count = lst_ra.Where(_ra => (_ra.GioRa.Day == _batdau.Day) && (_ra.GioRa.Month == _batdau.Month) && (_ra.GioRa.Year == _batdau.Year) && (_ra.LoaiVeId > 0)).Count(); _luot += _count + " vãng lai"; _tongluot += _count; _tongtien += lst_ra.Where(_ra => (_ra.GioRa.Day == _batdau.Day) && (_ra.GioRa.Month == _batdau.Month) && (_ra.GioRa.Year == _batdau.Year)).Sum(_ra => _ra.GiaVe).Value; } if (thang) { if (_luot != "") { _luot += ", "; } int _count = lst_ra.Where(_ra => (_ra.GioRa.Day == _batdau.Day) && (_ra.GioRa.Month == _batdau.Month) && (_ra.GioRa.Year == _batdau.Year) && (_ra.LoaiVeId < 0)).Count(); _luot += _count + " vé tháng"; _tongluot += _count; _tongtien += lst_giahan.Where(_gh => (_gh.NgayGiaHan.Value.Day == _batdau.Day) && (_gh.NgayGiaHan.Value.Month == _batdau.Month) && (_gh.NgayGiaHan.Value.Year == _batdau.Year)).Sum(_ra => _ra.GiaVe).Value; } giaHanVm.SoLuotVao = _luot; giaHanVm.TongTien = _tongtien; if (_tongluot != 0) { giaHanVm.TrungBinh = Convert.ToInt64(_tongtien / _tongluot); } else { giaHanVm.TrungBinh = 0; } listData.Add(giaHanVm); _batdau = _batdau.AddDays(-_batdau.Day + 1); _batdau = _batdau.AddMonths(1); } while (_batdau <= _ketthuc); break; case "nam": do { ThongKeNhanhViewModel giaHanVm = new ThongKeNhanhViewModel(); giaHanVm.STT = STT; STT++; giaHanVm.MoTa = "Từ ngày: " + _batdau.ToString("dd/MM/yyyy") + " đến ngày: " + (new DateTime(_batdau.Year, 12, 31)).ToString("dd/MM/yyyy"); string _luot = ""; int _tongluot = 0; long _tongtien = 0; if (vanglai) { int _count = lst_ra.Where(_ra => (_ra.GioRa.Day == _batdau.Day) && (_ra.GioRa.Month == _batdau.Month) && (_ra.GioRa.Year == _batdau.Year) && (_ra.LoaiVeId > 0)).Count(); _luot += _count + " vãng lai"; _tongluot += _count; _tongtien += lst_ra.Where(_ra => (_ra.GioRa.Day == _batdau.Day) && (_ra.GioRa.Month == _batdau.Month) && (_ra.GioRa.Year == _batdau.Year)).Sum(_ra => _ra.GiaVe).Value; } if (thang) { if (_luot != "") { _luot += ", "; } int _count = lst_ra.Where(_ra => (_ra.GioRa.Day == _batdau.Day) && (_ra.GioRa.Month == _batdau.Month) && (_ra.GioRa.Year == _batdau.Year) && (_ra.LoaiVeId < 0)).Count(); _luot += _count + " vé tháng"; _tongluot += _count; _tongtien += lst_giahan.Where(_gh => (_gh.NgayGiaHan.Value.Day == _batdau.Day) && (_gh.NgayGiaHan.Value.Month == _batdau.Month) && (_gh.NgayGiaHan.Value.Year == _batdau.Year)).Sum(_ra => _ra.GiaVe).Value; } giaHanVm.SoLuotVao = _luot; giaHanVm.TongTien = _tongtien; if (_tongluot != 0) { giaHanVm.TrungBinh = Convert.ToInt64(_tongtien / _tongluot); } else { giaHanVm.TrungBinh = 0; } listData.Add(giaHanVm); _batdau = _batdau.AddDays(-_batdau.Day + 1); _batdau = _batdau.AddMonths(-_batdau.Month + 1); _batdau = _batdau.AddYears(1); } while (_batdau <= _ketthuc); break; } int totalRow = listData.Count(); var query = listData.OrderBy(x => x.STT).Skip(page * pageSize).Take(pageSize); PaginationSet <ThongKeNhanhViewModel> pagedSet = new PaginationSet <ThongKeNhanhViewModel>() { Page = page, TotalCount = totalRow, TotalPages = (int)Math.Ceiling((decimal)totalRow / pageSize), Items = query }; HttpContext.Current.Session[CommonConstants.SessionThongKeNhanh] = listData; var response = request.CreateResponse(HttpStatusCode.OK, pagedSet); return response; })); }
public HttpResponseMessage Search(HttpRequestMessage request, int? page, int? pageSize, string filter = null) { int currentPage = page.Value; int currentPageSize = pageSize.Value; return CreateHttpResponse(request, () => { HttpResponseMessage response = null; List<Family> families = null; List<Family> familiesWithPeople = null; int totalFamilies = new int(); if (!string.IsNullOrEmpty(filter)) { filter = filter.Trim().ToLower(); families = _familyRepository.FindBy(c => (c.FamilyName.ToLower().Contains(filter) || c.FamilyIdentifier.ToLower().Contains(filter)) && c.Deleted == false) .OrderByDescending(c => c.FamilyName) .Skip(currentPage * currentPageSize) .Take(currentPageSize) .ToList(); //familiesWithPeople = _familyRepository.FindBy(c => c.Deleted == false).Where(p => p.Persons.Any(n => n.FirstName.Contains(filter))) // .OrderByDescending(c => c.FamilyName) // .Skip(currentPage * currentPageSize) // .Take(currentPageSize) // .ToList(); totalFamilies = _familyRepository .FindBy(c => (c.FamilyName.ToLower().Contains(filter) || c.FamilyIdentifier.ToLower().Contains(filter)) && c.Deleted == false) .Count(c => (c.FamilyName.ToLower().Contains(filter) || c.FamilyIdentifier.ToLower().Contains(filter)) && c.Deleted == false); } else { families = _familyRepository .FindBy(c => c.Deleted == false) .OrderByDescending(c => c.FirstRegisteredDate) .Skip(currentPage * currentPageSize) .Take(currentPageSize) .ToList(); totalFamilies = _familyRepository .FindBy(c => c.Deleted == false).Count(); } IEnumerable<FamilyViewModel> familiesVM = Mapper.Map<IEnumerable<Family>, IEnumerable<FamilyViewModel>>(families); PaginationSet<FamilyViewModel> pagedSet = new PaginationSet<FamilyViewModel>() { Page = currentPage, TotalCount = totalFamilies, TotalPages = (int)Math.Ceiling((decimal)totalFamilies / currentPageSize), Items = familiesVM }; response = request.CreateResponse<PaginationSet<FamilyViewModel>>(HttpStatusCode.OK, pagedSet); return response; }); }
public async Task <IActionResult> Get(int?page, int?pageSize, string username, string searchstring = null) { //var file = Request.; //using (DEFACEWEBSITEContext context = new DEFACEWEBSITEContext()) //{ PaginationSet <Messages> pagedSet = new PaginationSet <Messages>(); // var pagination = Request.Headers; //if (!string.IsNullOrEmpty(pagination)) //{ // string[] vals = pagination.ToString().Split(','); // int.TryParse(vals[0], out _page); // int.TryParse(vals[1], out _pageSize); //} //if (await _authorizationService.AuthorizeAsync(User, "AdminOnly")) //{ //DEFACEWEBSITEContext context = new DEFACEWEBSITEContext(); var result = _context.Messages.FromSql("dbo.Messages_Search @USER = {0}, @DOMAIN = {1} , @STATUS = {2}", username, null, null); int currentPage = page.Value; int currentPageSize = pageSize.Value; if (!String.IsNullOrEmpty(searchstring)) { result = result.Where(msg => msg.Domain.Contains(searchstring) || msg.User.Contains(searchstring) || msg.Title.ToLower().Contains(searchstring.ToLower())); } var totalRecord = result.Count(); var totalPages = (int)Math.Ceiling((double)totalRecord / pageSize.Value); var messages = result.Skip((currentPage) * currentPageSize).Take(currentPageSize).ToList(); Response.AddPagination(currentPage, currentPageSize, totalRecord, totalPages); //IEnumerable<Messages> listPagedMessage = //Mapper.Map<IEnumerable<Messages>, IEnumerable<Messages>>(messages); //messages.ToList().Clear(); //result.Clear(); pagedSet = new PaginationSet <Messages>() { Page = currentPage, TotalCount = totalRecord, TotalPages = totalPages, Items = messages }; // for(int i = 0; i< messages.Count; i++) //{ // if(i% 6 == 0) // { // //create row // //dislay array // } // else // { // for(int j = 0; j < messages.Count; j++) // { // } // } //} //context.Dispose(); return(new ObjectResult(pagedSet)); }
public HttpResponseMessage GetFamilyTree(HttpRequestMessage request, int id) { return CreateHttpResponse(request, () => { HttpResponseMessage response = null; List<Person> Persons = null; List<FamilyTree> familyTrees = new List<FamilyTree>(); Persons = _personRepository .FindBy(c => c.FamilyId == id && c.Deleted == false) .ToList(); int FatherId = 0; int MotherId = 0; int SpouseId = 0; PopulateFamilyStructure(Persons, familyTrees, ref FatherId, ref MotherId, ref SpouseId); IEnumerable<FamilyTreeViewModel> treeVM = Mapper.Map<IEnumerable<FamilyTree>, IEnumerable<FamilyTreeViewModel>>(familyTrees); var pagedSet = new PaginationSet<FamilyTreeViewModel>() { Page = 1, TotalCount = 10, TotalPages = (int)Math.Ceiling((decimal)100 / 10), Items = treeVM }; response = request.CreateResponse<PaginationSet<FamilyTreeViewModel>>(HttpStatusCode.OK, pagedSet); return response; }); }
public HttpResponseMessage Search(HttpRequestMessage request, int? page, int? pageSize, string filter = null) { int currentPage = page.Value; int currentPageSize = pageSize.Value; return CreateHttpResponse(request, () => { HttpResponseMessage response = null; List<User> users = null; int totalUsers = new int(); if (!string.IsNullOrEmpty(filter)) { filter = filter.Trim().ToLower(); users = _usersRepository.FindBy(c => c.Username.ToLower().Contains(filter)) .OrderBy(c => c.ID) .Skip(currentPage * currentPageSize) .Take(currentPageSize) .ToList(); totalUsers = _usersRepository.GetAll() .Where(c => c.Username.ToLower().Contains(filter)) .Count(); } else { users = _usersRepository.GetAll() .OrderBy(c => c.ID) .Skip(currentPage * currentPageSize) .Take(currentPageSize) .ToList(); totalUsers = _usersRepository.GetAll().Count(); } IEnumerable<UserViewModel> usersVM = Mapper.Map<IEnumerable<User>, IEnumerable<UserViewModel>>(users); PaginationSet<UserViewModel> pagedSet = new PaginationSet<UserViewModel>() { Page = currentPage, TotalCount = totalUsers, TotalPages = (int)Math.Ceiling((decimal)totalUsers / currentPageSize), Items = usersVM }; response = request.CreateResponse<PaginationSet<UserViewModel>>(HttpStatusCode.OK, pagedSet); return response; }); }
public HttpResponseMessage Get(HttpRequestMessage request, int? page, int? pageSize, string filter = null) { int currentPage = page.Value; int currentPageSize = pageSize.Value; return CreateHttpResponse(request, () => { List<AthleteDto> athletes; int totalAthletes; if (!string.IsNullOrEmpty(filter)) { athletes = _athletesRepository.GetAllByFilter(filter, currentPage, currentPageSize); totalAthletes = _athletesRepository.Count(filter); } else { athletes = _athletesRepository.GetAll(currentPage, currentPageSize); totalAthletes = _athletesRepository.Count(); } PaginationSet<AthleteDto> pagedSet = new PaginationSet<AthleteDto>() { Page = currentPage, TotalCount = totalAthletes, TotalPages = (int)Math.Ceiling((decimal)totalAthletes / currentPageSize), Items = athletes }; HttpResponseMessage response = request.CreateResponse<PaginationSet<AthleteDto>>(HttpStatusCode.OK, pagedSet); return response; }); }
public IActionResult GetAllShippingLocations(string keyword, int page = 1, int pageSize = 10, int sort = 0, string criteria = "districtid") { try { var list = _shippingService.GetShippingLocations(keyword); var response = _mapper.Map <IEnumerable <District>, IEnumerable <DistrictForListDto> >(list); int totalCount = list.Count(); criteria = criteria.ToLower(); #region Sort by criteria if (criteria.Equals("districtid")) { if (sort == 0) { response = response.OrderByDescending(x => x.DistrictID).Skip((page - 1) * pageSize).Take(pageSize); } else { response = response.OrderBy(x => x.DistrictID).Skip((page - 1) * pageSize).Take(pageSize); } } else if (criteria.Equals("district")) { if (sort == 0) { response = response.OrderByDescending(x => x.district).Skip((page - 1) * pageSize).Take(pageSize); } else { response = response.OrderBy(x => x.district).Skip((page - 1) * pageSize).Take(pageSize); } } else if (criteria.Equals("city")) { if (sort == 0) { response = response.OrderByDescending(x => x.city).Skip((page - 1) * pageSize).Take(pageSize); } else { response = response.OrderBy(x => x.city).Skip((page - 1) * pageSize).Take(pageSize); } } else //if (criteria.Equals("fee")) { if (sort == 0) { response = response.OrderByDescending(x => x.Fee).Skip((page - 1) * pageSize).Take(pageSize); } else { response = response.OrderBy(x => x.Fee).Skip((page - 1) * pageSize).Take(pageSize); } } #endregion var paginationSet = new PaginationSet <DistrictForListDto>() { Items = response, Total = totalCount, }; return(Ok(paginationSet)); } catch (System.Exception) { return(BadRequest()); } }
public HttpResponseMessage Get(HttpRequestMessage request, int? page, int? pageSize, string filter = null) { var currentPage = page.Value; var currentPageSize = pageSize.Value; return CreateHttpResponse(request, () => { HttpResponseMessage response = null; List<Movie> movies = null; var totalMovies = new int(); if (!string.IsNullOrEmpty(filter)) { movies = _moviesRepository.GetAll() .OrderBy(m => m.ID) .Where(m => m.Title.ToLower() .Contains(filter.ToLower().Trim())) .ToList(); } else { movies = _moviesRepository.GetAll().ToList(); } totalMovies = movies.Count(); movies = movies.Skip(currentPage*currentPageSize) .Take(currentPageSize) .ToList(); var moviesVM = Mapper.Map<IEnumerable<Movie>, IEnumerable<MovieViewModel>>(movies); var pagedSet = new PaginationSet<MovieViewModel> { Page = currentPage, TotalCount = totalMovies, TotalPages = (int) Math.Ceiling((decimal) totalMovies/currentPageSize), Items = moviesVM }; response = request.CreateResponse(HttpStatusCode.OK, pagedSet); return response; }); }
public HttpResponseMessage Get(HttpRequestMessage request, int? page, int? pageSize, string filter = null) { int currentPage = page.Value; int currentPageSize = pageSize.Value; return CreateHttpResponse(request, () => { HttpResponseMessage response = null; List<Material> materials = null; int totalMaterials = new int(); if (!string.IsNullOrEmpty(filter)) { materials = _materialsRepository .FindBy(m => m.Title.ToLower() .Contains(filter.ToLower().Trim())) .OrderBy(m => m.ID) .Skip(currentPage * currentPageSize) .Take(currentPageSize) .ToList(); totalMaterials = _materialsRepository .FindBy(m => m.Title.ToLower() .Contains(filter.ToLower().Trim())) .Count(); } else { materials = _materialsRepository .GetAll() .OrderBy(m => m.ID) .Skip(currentPage * currentPageSize) .Take(currentPageSize) .ToList(); totalMaterials = _materialsRepository.GetAll().Count(); } IEnumerable<MaterialViewModel> materialsVM = Mapper.Map<IEnumerable<Material>, IEnumerable<MaterialViewModel>>(materials); PaginationSet<MaterialViewModel> pagedSet = new PaginationSet<MaterialViewModel>() { Page = currentPage, TotalCount = totalMaterials, TotalPages = (int)Math.Ceiling((decimal)totalMaterials / currentPageSize), Items = materialsVM }; response = request.CreateResponse<PaginationSet<MaterialViewModel>>(HttpStatusCode.OK, pagedSet); return response; }); }
public IActionResult GetAllContacts(string keyword, int page = 1, int pageSize = 10, int sort = 0, string criteria = "contactid") { try { var list = _contactService.GetContacts(keyword); int totalCount = list.Count(); criteria = criteria.ToLower(); var response = _mapper.Map <IEnumerable <Contact>, IEnumerable <ContactForListDto> >(list); #region Sort by criteria if (criteria.Equals("contactid")) { if (sort == 0) { response = response.OrderByDescending(x => x.ContactID).Skip((page - 1) * pageSize).Take(pageSize); } else { response = response.OrderBy(x => x.ContactID).Skip((page - 1) * pageSize).Take(pageSize); } } if (criteria.Equals("name")) { if (sort == 0) { response = response.OrderByDescending(x => x.Name).Skip((page - 1) * pageSize).Take(pageSize); } else { response = response.OrderBy(x => x.Name).Skip((page - 1) * pageSize).Take(pageSize); } } if (criteria.Equals("message")) { if (sort == 0) { response = response.OrderByDescending(x => x.Message).Skip((page - 1) * pageSize).Take(pageSize); } else { response = response.OrderBy(x => x.Message).Skip((page - 1) * pageSize).Take(pageSize); } } if (criteria.Equals("email")) { if (sort == 0) { response = response.OrderByDescending(x => x.Email).Skip((page - 1) * pageSize).Take(pageSize); } else { response = response.OrderBy(x => x.Email).Skip((page - 1) * pageSize).Take(pageSize); } } if (criteria.Equals("date")) { if (sort == 0) { response = response.OrderByDescending(x => x.Date.Year) .ThenByDescending(x => x.Date.Month) .ThenByDescending(x => x.Date.Day).Skip((page - 1) * pageSize).Take(pageSize); } else { response = response.OrderBy(x => x.Date.Year) .ThenBy(x => x.Date.Month) .ThenBy(x => x.Date.Day).Skip((page - 1) * pageSize).Take(pageSize); } } else //if (criteria.Equals("status")) { if (sort == 0) { response = response.OrderByDescending(x => x.Status).Skip((page - 1) * pageSize).Take(pageSize); } else { response = response.OrderBy(x => x.Status).Skip((page - 1) * pageSize).Take(pageSize); } } #endregion var paginationSet = new PaginationSet <ContactForListDto>() { Items = response, Total = totalCount, }; return(Ok(paginationSet)); } catch (System.Exception) { return(BadRequest()); } }
public IActionResult GetAllPublishers(string keyword, int page = 1, int pageSize = 10, int sort = 0, string criteria = "publisherId") { try { var list = _publisherService.GetPublishers(keyword); int totalCount = list.Count(); criteria = criteria.ToLower(); var response = _mapper.Map <IEnumerable <Publisher>, IEnumerable <PublisherForListDto> >(list); if (response != null) { foreach (var item in response) { item.BookTitleCount = _publisherService.CountBookTitleInPublisher(item.PublisherID); } } #region sort by criteria if (criteria.Equals("publisherid")) { if (sort == 0) { response = response.OrderByDescending(x => x.PublisherID).Skip((page - 1) * pageSize).Take(pageSize); } else { response = response.OrderBy(x => x.PublisherID).Skip((page - 1) * pageSize).Take(pageSize); } } if (criteria.Equals("publisher")) { if (sort == 0) { response = response.OrderByDescending(x => x.publisher).Skip((page - 1) * pageSize).Take(pageSize); } else { response = response.OrderBy(x => x.publisher).Skip((page - 1) * pageSize).Take(pageSize); } } if (criteria.Equals("booktitlecount")) { if (sort == 0) { response = response.OrderByDescending(x => x.BookTitleCount).Skip((page - 1) * pageSize).Take(pageSize); } else { response = response.OrderBy(x => x.BookTitleCount).Skip((page - 1) * pageSize).Take(pageSize); } } #endregion var paginationSet = new PaginationSet <PublisherForListDto>() { Items = response, Total = totalCount, }; return(Ok(paginationSet)); } catch (System.Exception) { return(BadRequest()); } }