public Task <PagedListDTO <OrderDTO> > GetOrders(BaseCriteriaDTO criteria) { //PageSize int pageSize = Convert.ToInt32(ConfigurationManager.AppSettings["pageSize"].ToString()); //filter (expression in DB) Expression <Func <Order, bool> > filterExpression = x => x.Id != "0"; //Azure cosmos db not support method toString, and we use the next Workarround int filterAmount = 0; int.TryParse(criteria.Filter, out filterAmount); if (!string.IsNullOrWhiteSpace(criteria.Filter)) { filterExpression = filterExpression.Join( x => (x.OrderCustomer != null && x.OrderCustomer.ContactName.ToUpper().Contains(criteria.Filter.ToUpper())) || x.ShipAdress.ToUpper().Contains(criteria.Filter.ToUpper()) || x.ShipCity.ToUpper().Contains(criteria.Filter.ToUpper()) || x.ShipCountry.ToUpper().Contains(criteria.Filter.ToUpper()) || x.ShipPostalCode.ToUpper().Contains(criteria.Filter.ToUpper()) || x.TotalAmount == filterAmount ); } //order by Expression <Func <Order, object> >[] orderByExpressions = this.GetOrderByExpressions_Orders(criteria.OrderBy); Tuple <List <Order>, int> q = repositoryOrders.GetAllAsync(criteria.PageNumber, pageSize, filterExpression, criteria.OrderAsc, orderByExpressions); //get total entities int totalItems = q.Item2; //parse to DTO List <OrderDTO> items = q.Item1.ToList().Select(m => new OrderDTO { Id = Convert.ToInt32(m.Id), Created_At = m.Created_At, //OrderCustomer = m.OrderCustomer, Details = m.OrdersDetails.Where(x => x != null).Select(a => new OrderDetailDTO { Id = Convert.ToInt32(a.OrderDetailId), OrderId = Convert.ToInt32(m.Id), Discount = a.Discount, ProductId = a.ProductId, ProductName = (a.ProductSold != null ? a.ProductSold.Name : ""), Quantity = a.Quantity }).ToList(), shipAdress = m.ShipAdress, shipCity = m.ShipCity, shipCountry = m.ShipCountry, shipPostalCode = m.ShipPostalCode, TotalAmount = m.TotalAmount }).ToList(); var res = new PagedListDTO <OrderDTO>(totalItems, pageSize, items, criteria.PageNumber); return(Task.FromResult(res)); }
public async Task <IHttpActionResult> PostGetOrders([FromBody] BaseCriteriaDTO criteria) { if (criteria == null) { return(BadRequest()); } PagedListDTO <OrderDTO> result = await orderService.GetOrders(criteria); return(Ok(result)); }
public async Task <ActionResult> GetAsync(int pageSize, int pageNumber) { try { PagedListDTO <UserDTO> users = await userService.GetUsers(pageSize, pageNumber); return(Ok(users)); } catch (Exception e) { logger.LogInformation("Error : {0}", e.Message); return(StatusCode(500)); } }
public HttpResponseMessage GetUsersbyRole(int role_id, [FromUri] int pageSize, [FromUri] int pageNumber) { if (role_id != -1) { var role = roleService.Get(role_id); if (role == null) { var roleErorMessage = "No roles with this id in database."; return(Request.CreateErrorResponse(HttpStatusCode.NoContent, roleErorMessage)); } } PagedListDTO <UserDTO> users = userService.GetUsersByRole(role_id, pageSize, pageNumber); return(Request.CreateResponse <PagedListDTO <UserDTO> >(HttpStatusCode.OK, users)); }
public async Task <ActionResult> GetUsersbyRoleAsync(int roleId, int pageSize, int pageNumber) { if (roleId != Constants.Roles.BlockedIndex) { var role = await roleService.GetAsync(roleId); if (role == null) { return(NoContent()); } } PagedListDTO <UserDTO> users = await userService.GetUsersByRoleAsync(roleId, pageSize, pageNumber); return(Ok(users)); }
public IActionResult GetSearchHistory(int page, int pageSize) { int totalPosts = dataService.SearchRepository.GetSearchHistoryCount(); int totalPages = (int)Math.Ceiling(totalPosts / (double)pageSize); List <Search> searchHistory = dataService.SearchRepository.GetSearchHistory().Skip(pageSize * page) .Take(pageSize).ToList(); PagedListDTO <Search> result = new PagedListDTO <Search> { TotalEntities = totalPosts, TotalPages = totalPages, CurrentPage = page, PrevLink = Link("/api/search/history/{0}/{1}", page, pageSize, -1, () => page > 0), NextLink = Link("/api/search/history/{0}/{1}", page, pageSize, 1, () => page < totalPages - 1), Content = searchHistory }; return(Ok(result)); }
public IActionResult GetPostsBySearchString(string substring, int page, int pageSize) { int totalPosts = _dataService.PostRepository.GetPostCountBySearchString(substring); int totalPages = (int)Math.Ceiling(totalPosts / (double)pageSize); try { List <SearchedPostDTO> posts = _dataService.PostRepository.GetPostsBySearchString(substring, page, pageSize) .Select(x => new SearchedPostDTO { Id = x.Id, CreateDate = x.CreateDate, Score = x.Score, Body = x.Body, Title = x.Title, MarkedPost = x.MarkedPost, Annotation = x.Annotation, User = x.User.DisplayName, Tags = x.Tags.Select(t => new TagDTO { Id = t.Id, Tag = t.Name }).ToList() }).ToList(); if (posts == null) { return(NotFound()); } PagedListDTO <SearchedPostDTO> result = new PagedListDTO <SearchedPostDTO> { TotalEntities = totalPosts, TotalPages = totalPages, CurrentPage = page, PrevLink = Link("/api/post/search/{0}/{1}/{2}", substring, page, pageSize, -1, () => page > 0), NextLink = Link("/api/post/search/{0}/{1}/{2}", substring, page, pageSize, 1, () => page < totalPages - 1), Content = posts }; return(Ok(result)); } catch (Exception e) { Console.WriteLine(e); return(NotFound()); } }
public async Task <PagedListDTO <ApplicationVM> > Handle(SearchAppQuery search, CancellationToken cancellationToken) { Func <IQueryable <Domain.Applications.Application>, IOrderedQueryable <Domain.Applications.Application> > orderBy; if (search.SortDescriptors != null && search.SortDescriptors.Any()) { orderBy = ExpressionsBuilder.GetOrderBy <Domain.Applications.Application>(search.SortDescriptors[0].Member, search.SortDescriptors[0].SortDirection == ListSortDirection.Ascending); } else { orderBy = contacts => contacts.OrderBy(a => a.Name); } var filterBy = ExpressionsBuilder.GetFilter <Domain.Applications.Application>(search); if (!search.PageSize.HasValue) { search.PageSize = int.MaxValue; } if (!search.Page.HasValue) { search.Page = 0; } var pagelist = _repository.Get(filterBy, search.Page.Value, search.PageSize.Value, orderBy); var result = new PagedListDTO <ApplicationVM>() { Rows = pagelist.Select(a => a.ToMap()).ToList(), PageIndex = pagelist.PageIndex, PageSize = pagelist.PageSize, TotalCount = pagelist.TotalCount, TotalPages = pagelist.TotalPages }; return(result); }
public HttpResponseMessage Search(string q, string role, [FromUri] int pageSize, [FromUri] int pageNumber) { if (q == null) { q = ""; } RoleDTO criteria = roleService.GetByName(role); string[] lines = q.Split(new [] { ' ' }, StringSplitOptions.RemoveEmptyEntries); int? searchParametr = null; if (role == "blocked") { searchParametr = -1; } if (lines.Length > 2) { lines = lines.Take(2).ToArray(); } PagedListDTO <UserDTO> users = criteria != null?userService.Search(lines, pageSize, pageNumber, criteria.Id) : userService.Search(lines, pageSize, pageNumber, searchParametr); return(Request.CreateResponse <PagedListDTO <UserDTO> >(HttpStatusCode.OK, users)); }
public async Task <Response <PagedQueryResultDTO <UserDTO> > > GetPaginated([FromBody] PagedListDTO pagedModel) { return(await this.businessService.GetPaginated(pagedModel)); }
public HttpResponseMessage GetUsersbyState(bool state, [FromUri] int pageSize, [FromUri] int pageNumber) { PagedListDTO <UserDTO> users = userService.GetUsersByState(state, pageSize, pageNumber); return(Request.CreateResponse <PagedListDTO <UserDTO> >(HttpStatusCode.OK, users)); }
public async Task <ActionResult> GetUsersbyStateAsync(bool state, int pageSize, int pageNumber) { PagedListDTO <UserDTO> users = await userService.GetUsersByStateAsync(state, pageSize, pageNumber); return(Ok(users)); }