public IHttpActionResult Get(int pageSize, int pageNumber, string sortField) { int totalCount = 0; var page = new Page { PageSize = pageSize, PageNumber = pageNumber }; var categories = categoryService.GetPaged(pageSize, pageNumber, sortField, ref totalCount); IEnumerable<CategoryViewModel> categoryViewModels = new List<CategoryViewModel>(); Mapper.Map(categories, categoryViewModels); PagedCollectionViewModel<CategoryViewModel> viewModel = new PagedCollectionViewModel<CategoryViewModel> { Data = categoryViewModels, TotalCount = totalCount }; return Ok(viewModel); }
public IHttpActionResult Get(int pageSize, int pageNumber, string sortField) { int totalCount = 0; var page = new Page { PageSize = pageSize, PageNumber = pageNumber }; var settings = settingService.GetPaged(pageSize, pageNumber, sortField, ref totalCount); IEnumerable<SettingViewModel> settingViewModels = new List<SettingViewModel>(); Mapper.Map(settings, settingViewModels); PagedCollectionViewModel<SettingViewModel> viewModel = new PagedCollectionViewModel<SettingViewModel> { Data = settingViewModels, TotalCount = totalCount }; return Ok(viewModel); }
public IHttpActionResult Get(int count, int page, string sortField, string sortOrder) { string userEmail = RequestContext.Principal.Identity.Name; var user = userManager.FindByName(userEmail); int totalCount = 0; var resources = resourceService.GetPagedResourcesByUserId(user.Id, count, page, sortField, sortOrder, ref totalCount).ToList(); IEnumerable<ResourceViewModel> resourceViewModels = new List<ResourceViewModel>(); Mapper.Map(resources, resourceViewModels); PagedCollectionViewModel<ResourceViewModel> viewModel = new PagedCollectionViewModel<ResourceViewModel> { Data = resourceViewModels, TotalCount = totalCount }; return Ok(viewModel); }
public IHttpActionResult Get(int count, int page, string sortField, string sortOrder) { string userEmail = RequestContext.Principal.Identity.Name; var user = userManager.FindByName(userEmail); int totalCount = 0; var resources = resourceService.GetPagedResourcesByUserId(user.Id, count, page, sortField, sortOrder, ref totalCount).ToList(); IEnumerable <ResourceViewModel> resourceViewModels = new List <ResourceViewModel>(); Mapper.Map(resources, resourceViewModels); PagedCollectionViewModel <ResourceViewModel> viewModel = new PagedCollectionViewModel <ResourceViewModel> { Data = resourceViewModels, TotalCount = totalCount }; return(Ok(viewModel)); }
public IHttpActionResult GetUsers(int page = 1, int pageSize = 10, string searchTerm = null) { try { var users = _user.GetAllUsers().ToList(); if (!string.IsNullOrEmpty(searchTerm)) { users = users.Where(x => x.Surname.StartsWith(searchTerm, StringComparison.CurrentCultureIgnoreCase) || x.Forename.StartsWith(searchTerm, StringComparison.CurrentCultureIgnoreCase) || x.Email.StartsWith(searchTerm, StringComparison.CurrentCultureIgnoreCase)).ToList(); } // Prepare paged items before hand as we don't want to convert all users to userViewModels and then paginate. var pagedUsers = new PagedCollection().GetPagedCollection(users.OrderBy(x => x.Forename).ThenBy(x => x.Surname), page, pageSize); var userViewModelList = new List <CurrentUserViewModel>(); foreach (var user in pagedUsers.Items) { var displayName = (_user.GetAdDetailsByAccountName(user.UserName) ?? new ApplicationUser()).DisplayName; var userRoles = _user.GetUserRoles(user.Id).ToList(); userViewModelList.Add(new CurrentUserViewModel { EmailAddress = user.Email, Forename = user.Forename, Surname = user.Surname, DisplayName = displayName, Id = user.Id, IsAdmin = userRoles.Any(a => a.Equals(Roles.Administrator, StringComparison.CurrentCultureIgnoreCase)), Roles = userRoles, Username = user.UserName }); } var viewModel = new PagedCollectionViewModel <CurrentUserViewModel> { Items = userViewModelList, Page = pagedUsers.Page, TotalCount = pagedUsers.TotalCount, TotalPages = pagedUsers.TotalPages }; return(Ok(viewModel)); } catch (Exception ex) { return(WebApiErrorHandler.Throw(ex)); } }
public IHttpActionResult GetPhotos(int count, int page) { string userId = RequestContext.Principal.Identity.GetUserId(); int totalCount = 0; var photos = _photoService.GetPagedByUserId(userId, count, page, ref totalCount).ToList(); IEnumerable <PhotoViewModel> viewModels = new List <PhotoViewModel>(); Mapper.Map(photos, viewModels); PagedCollectionViewModel <PhotoViewModel> viewModel = new PagedCollectionViewModel <PhotoViewModel> { Data = viewModels, TotalCount = totalCount }; return(Ok(viewModel)); }
public IHttpActionResult Get(int pageSize, int pageNumber, string sortField) { int totalCount = 0; var page = new Page { PageSize = pageSize, PageNumber = pageNumber }; var settings = settingService.GetPaged(pageSize, pageNumber, sortField, ref totalCount); IEnumerable <SettingViewModel> settingViewModels = new List <SettingViewModel>(); Mapper.Map(settings, settingViewModels); PagedCollectionViewModel <SettingViewModel> viewModel = new PagedCollectionViewModel <SettingViewModel> { Data = settingViewModels, TotalCount = totalCount }; return(Ok(viewModel)); }
public IHttpActionResult Get(int pageSize, int pageNumber, string sortField) { int totalCount = 0; var page = new Page { PageSize = pageSize, PageNumber = pageNumber }; var categories = categoryService.GetPaged(pageSize, pageNumber, sortField, ref totalCount); IEnumerable <CategoryViewModel> categoryViewModels = new List <CategoryViewModel>(); Mapper.Map(categories, categoryViewModels); PagedCollectionViewModel <CategoryViewModel> viewModel = new PagedCollectionViewModel <CategoryViewModel> { Data = categoryViewModels, TotalCount = totalCount }; return(Ok(viewModel)); }
public IHttpActionResult Search(SettingSE se) { var page = new Page { PageSize = se.PageSize, PageNumber = se.PageNumber }; var settings = settingService.Search(se); int totalCount = settings.Count(); settings = settings.OrderByPropertyName(se.SortField, se.SortOrder); settings = settings.GetPage <Setting>(page); IEnumerable <SettingViewModel> settingViewModels = new List <SettingViewModel>(); Mapper.Map(settings, settingViewModels); PagedCollectionViewModel <SettingViewModel> viewModel = new PagedCollectionViewModel <SettingViewModel> { Data = settingViewModels, TotalCount = totalCount }; return(Ok(viewModel)); }
public IHttpActionResult Search(CategorySE se) { var page = new Page { PageSize = se.PageSize, PageNumber = se.PageNumber }; var categories = categoryService.Search(se); int totalCount = categories.Count(); categories = categories.OrderByPropertyName(se.SortField, se.SortOrder); categories = categories.GetPage <Category>(page); IEnumerable <CategoryViewModel> categoryViewModels = new List <CategoryViewModel>(); Mapper.Map(categories, categoryViewModels); PagedCollectionViewModel <CategoryViewModel> viewModel = new PagedCollectionViewModel <CategoryViewModel> { Data = categoryViewModels, TotalCount = totalCount }; return(Ok(viewModel)); }
// GET api/GDrive public IHttpActionResult Get(int page = 1, int pageSize = 10, string searchTerm = "") { try { var files = _drive.SearchFileNames(searchTerm ?? string.Empty); var pagedFiles = new PagedCollection().GetPagedCollection(files.OrderBy(x => x.FileName).ThenByDescending(x => x.UploadedOn), page, pageSize); var viewModel = new PagedCollectionViewModel <FileContent> { Items = pagedFiles.Items, Page = pagedFiles.Page, TotalCount = pagedFiles.TotalCount, TotalPages = pagedFiles.TotalPages }; return(Ok(viewModel)); } catch (Exception ex) { return(WebApiErrorHandler.Throw(ex)); } }
public IHttpActionResult Search(CategorySE se) { var page = new Page { PageSize = se.PageSize, PageNumber = se.PageNumber}; var categories = categoryService.Search(se); int totalCount = categories.Count(); categories = categories.OrderByPropertyName(se.SortField, se.SortOrder); categories = categories.GetPage<Category>(page); IEnumerable<CategoryViewModel> categoryViewModels = new List<CategoryViewModel>(); Mapper.Map(categories, categoryViewModels); PagedCollectionViewModel<CategoryViewModel> viewModel = new PagedCollectionViewModel<CategoryViewModel> { Data = categoryViewModels, TotalCount = totalCount }; return Ok(viewModel); }
public IHttpActionResult Search(SettingSE se) { var page = new Page { PageSize = se.PageSize, PageNumber = se.PageNumber}; var settings = settingService.Search(se); int totalCount = settings.Count(); settings = settings.OrderByPropertyName(se.SortField, se.SortOrder); settings = settings.GetPage<Setting>(page); IEnumerable<SettingViewModel> settingViewModels = new List<SettingViewModel>(); Mapper.Map(settings, settingViewModels); PagedCollectionViewModel<SettingViewModel> viewModel = new PagedCollectionViewModel<SettingViewModel> { Data = settingViewModels, TotalCount = totalCount }; return Ok(viewModel); }