Esempio n. 1
0
        public IHttpActionResult FilterGames(string contentType, FilterCriteriaViewModel filterViewModel, string size, int page = 1)
        {
            if (!ModelState.IsValid)
            {
                return(Content(HttpStatusCode.BadRequest, CreateError()));
            }
            FilterCriteria  filters = _mapper.Map <FilterCriteriaViewModel, FilterCriteria>(filterViewModel);
            PaginationGames games   = _gameService.FilterGames(filters, page, size, CurrentLanguage);

            filterViewModel.Genres        = _mapper.Map <IEnumerable <Genre>, IList <GenreViewModel> >(_genreService.GetAllGenresAndMarkSelectedForFilter(filterViewModel.NameGenres, CurrentLanguage));
            filterViewModel.PlatformTypes = _mapper.Map <IEnumerable <PlatformType>, IList <PlatformTypeViewModel> >(_platformTypeService.GetAllPlatformTypesAndMarkSelected(filterViewModel.NamePlatformTypes, CurrentLanguage));
            filterViewModel.Publishers    = _mapper.Map <IEnumerable <Publisher>, IList <PublisherViewModel> >(_publisherService.GetAllPublishersAndMarkSelected(filterViewModel.NamePublishers, CurrentLanguage));

            var pageInfo = new PagingInfoViewModel
            {
                CurrentPage  = page,
                ItemsPerPage = size,
                TotalItems   = games.Count
            };

            var result = Serialize(new GamesAndFilterViewModel()
            {
                Filter     = filterViewModel,
                Games      = _mapper.Map <IEnumerable <Game>, IList <GameViewModel> >(games.Games),
                PagingInfo = pageInfo
            },
                                   contentType);

            return(result);
        }
Esempio n. 2
0
        public IHttpActionResult GetGames(string contentType)
        {
            PaginationGames games = _gameService.Get(CurrentLanguage);

            FilterCriteria filter = new FilterCriteria
            {
                Genres        = _genreService.Get(CurrentLanguage),
                Platformtypes = _platformTypeService.Get(CurrentLanguage),
                Publishers    = _publisherService.Get(CurrentLanguage)
            };

            var filterViewModel = _mapper.Map <FilterCriteria, FilterCriteriaViewModel>(filter);

            var pageInfo = new PagingInfoViewModel
            {
                CurrentPage  = 1,
                ItemsPerPage = "10",
                TotalItems   = games.Count
            };

            var result = Serialize(new GamesAndFilterViewModel
            {
                Filter     = filterViewModel,
                Games      = _mapper.Map <IEnumerable <Game>, IList <GameViewModel> >(games.Games),
                PagingInfo = pageInfo
            },
                                   contentType);

            return(result);
        }
Esempio n. 3
0
        private async Task <IEnumerable <User> > UserList_GetDataAsync(PagingInfoViewModel pagingInfo, string ttbSearchMessage, string rblEnableStatus)
        {
            IQueryable <User> q = DB.Users;

            string searchText = ttbSearchMessage?.Trim();

            if (!String.IsNullOrEmpty(searchText))
            {
                q = q.Where(u => u.Name.Contains(searchText) || u.ChineseName.Contains(searchText) || u.EnglishName.Contains(searchText));
            }

            if (GetIdentityName() != "admin")
            {
                q = q.Where(u => u.Name != "admin");
            }

            // 过滤启用状态
            if (rblEnableStatus != "all")
            {
                q = q.Where(u => u.Enabled == (rblEnableStatus == "enabled" ? true : false));
            }


            // 获取总记录数(在添加条件之后,排序和分页之前)
            pagingInfo.RecordCount = await q.CountAsync();

            // 排列和数据库分页
            q = SortAndPage <User>(q, pagingInfo);

            return(await q.ToListAsync());
        }
Esempio n. 4
0
        private async Task <IEnumerable <User> > RoleUserNew_GetDataAsync(PagingInfoViewModel pagingInfo, int roleID, string ttbSearchMessage)
        {
            IQueryable <User> q = DB.Users;

            string searchText = ttbSearchMessage?.Trim();

            if (!String.IsNullOrEmpty(searchText))
            {
                q = q.Where(u => u.Name.Contains(searchText) || u.ChineseName.Contains(searchText) || u.EnglishName.Contains(searchText));
            }

            q = q.Where(u => u.Name != "admin");

            // 排除已经属于本角色的用户
            q = q.Where(u => u.RoleUsers.All(r => r.RoleID != roleID));


            // 获取总记录数(在添加条件之后,排序和分页之前)
            pagingInfo.RecordCount = await q.CountAsync();

            // 排列和数据库分页
            q = SortAndPage <User>(q, pagingInfo);

            return(await q.ToListAsync());
        }
Esempio n. 5
0
        public ActionResult FilterGames(FilterCriteriaViewModel filterViewModel, string size, int page = 1)
        {
            PaginationGames games;

            if (ModelState.IsValid)
            {
                FilterCriteria filters = _mapper.Map <FilterCriteriaViewModel, FilterCriteria>(filterViewModel);
                games             = _gameService.FilterGames(filters, page, size, CurrentLanguageCode);
                TempData["games"] = games;
            }
            else
            {
                games             = TempData["games"] as PaginationGames;
                TempData["games"] = games;
            }

            filterViewModel.Genres        = _mapper.Map <IEnumerable <Genre>, IList <GenreViewModel> >(_genreService.GetAllGenresAndMarkSelectedForFilter(filterViewModel.NameGenres, CurrentLanguageCode));
            filterViewModel.PlatformTypes = _mapper.Map <IEnumerable <PlatformType>, IList <PlatformTypeViewModel> >(_platformTypeService.GetAllPlatformTypesAndMarkSelected(filterViewModel.NamePlatformTypes, CurrentLanguageCode));
            filterViewModel.Publishers    = _mapper.Map <IEnumerable <Publisher>, IList <PublisherViewModel> >(_publisherService.GetAllPublishersAndMarkSelected(filterViewModel.NamePublishers, CurrentLanguageCode));

            var pageInfo = new PagingInfoViewModel()
            {
                CurrentPage  = page,
                ItemsPerPage = size,
                TotalItems   = games.Count
            };

            return(View("games", new GamesAndFilterViewModel()
            {
                Filter = filterViewModel, Games = _mapper.Map <IEnumerable <Game>, IList <GameViewModel> >(games.Games), PagingInfo = pageInfo
            }));
        }
Esempio n. 6
0
        private static void CreateNextPageLink(PagingInfoViewModel pagingInfo, Func <int, string> pageUrl, StringBuilder builder)
        {
            var listElement = new TagBuilder("li");

            listElement.AddCssClass("page-item");

            var nextPageLink = new TagBuilder("a");

            nextPageLink.AddCssClass("page-link link-nt");
            nextPageLink.MergeAttribute("href", pageUrl(pagingInfo.CurrentPage + 1));
            nextPageLink.MergeAttribute("aria-label", "Next");

            var firstSpan = new TagBuilder("span");

            firstSpan.MergeAttribute("aria-hidden", "true");
            firstSpan.InnerHtml += "&raquo;";

            var secondSpan = new TagBuilder("span");

            secondSpan.AddCssClass("sr-only");
            secondSpan.InnerHtml += "Next";

            nextPageLink.InnerHtml += firstSpan;
            nextPageLink.InnerHtml += secondSpan;

            listElement.InnerHtml += nextPageLink;

            builder.Append(listElement.ToString());
        }
Esempio n. 7
0
        public ActionResult GetGames()
        {
            PaginationGames games = _gameService.Get(CurrentLanguageCode);

            FilterCriteria filter = new FilterCriteria()
            {
                Genres        = _genreService.Get(CurrentLanguageCode),
                Platformtypes = _platformTypeService.Get(CurrentLanguageCode),
                Publishers    = _publisherService.Get(CurrentLanguageCode)
            };

            var filterViewModel = _mapper.Map <FilterCriteria, FilterCriteriaViewModel>(filter);

            var pageInfo = new PagingInfoViewModel()
            {
                CurrentPage  = 1,
                ItemsPerPage = "10",
                TotalItems   = games.Count
            };

            TempData["games"] = games;
            return(View(new GamesAndFilterViewModel()
            {
                Filter = filterViewModel, Games = _mapper.Map <IEnumerable <Game>, IList <GameViewModel> >(games.Games), PagingInfo = pageInfo
            }));
        }
Esempio n. 8
0
        public async Task <IActionResult> OnPostOnline_DoPostBackAsync(string[] Grid1_fields, int Grid1_pageIndex, string Grid1_sortField, string Grid1_sortDirection,
                                                                       string ttbSearchMessage, int ddlGridPageSize, string actionType)
        {
            var ttbSearchMessageUI = UIHelper.TwinTriggerBox("ttbSearchMessage");

            if (actionType == "trigger1")
            {
                ttbSearchMessageUI.Text(String.Empty);
                ttbSearchMessageUI.ShowTrigger1(false);

                // 清空传入的搜索值
                ttbSearchMessage = String.Empty;
            }
            else if (actionType == "trigger2")
            {
                ttbSearchMessageUI.ShowTrigger1(true);
            }


            var grid1UI    = UIHelper.Grid("Grid1");
            var pagingInfo = new PagingInfoViewModel
            {
                SortField     = Grid1_sortField,
                SortDirection = Grid1_sortDirection,
                PageIndex     = Grid1_pageIndex,
                PageSize      = ddlGridPageSize
            };

            grid1UI.DataSource(await Online_GetDataAsync(pagingInfo, ttbSearchMessage), Grid1_fields);
            grid1UI.RecordCount(pagingInfo.RecordCount);

            return(UIHelper.Result());
        }
Esempio n. 9
0
        public async Task <IActionResult> OnGetAsync()
        {
            PowerCoreRoleUserNew    = CheckPower("CoreRoleUserNew");
            PowerCoreRoleUserDelete = CheckPower("CoreRoleUserDelete");

            // 表格1
            var grid1PagingInfo = new PagingInfoViewModel
            {
                SortField     = "Name",
                SortDirection = "DESC"
            };

            Roles = await Sort <Role>(DB.Roles, grid1PagingInfo).ToListAsync();

            if (Roles.Count() == 0)
            {
                // 没有角色数据
                return(Content("请先添加角色!"));
            }
            var grid1SelectedRowID = Roles.First().ID;

            Grid1SelectedRowID = grid1SelectedRowID.ToString();
            Grid1PagingInfo    = grid1PagingInfo;


            Users = await RoleUser_LoadDataAsync(grid1SelectedRowID);

            return(Page());
        }
Esempio n. 10
0
        protected async Task <IActionResult> LoadGrid(string[] Grid1_fields, int Grid1_pageIndex, string Grid1_sortField, string Grid1_sortDirection, string ttbSearchMessage, int ddlGridPageSize, string actionType)
        {
            var grid1UI    = UIHelper.Grid("Grid1");
            var pagingInfo = new PagingInfoViewModel
            {
                SortField     = Grid1_sortField,
                SortDirection = Grid1_sortDirection,
                PageIndex     = Grid1_pageIndex,
                PageSize      = ddlGridPageSize
            };

            var users = await GetDataAsync(pagingInfo, ttbSearchMessage);

            // 1. 设置总项数
            grid1UI.RecordCount(pagingInfo.RecordCount);
            // 2. 设置每页显示项数
            if (actionType == "changeGridPageSize")
            {
                grid1UI.PageSize(ddlGridPageSize);
            }
            // 3.设置分页数据
            grid1UI.DataSource(users, Grid1_fields);

            return(UIHelper.Result());
        }
Esempio n. 11
0
        private static void CreatePreviousPageLink(PagingInfoViewModel pagingInfo, Func <int, string> pageUrl, StringBuilder builder)
        {
            var listElement = new TagBuilder("li");

            listElement.AddCssClass("page-item");

            var previousLinkPage = new TagBuilder("a");

            previousLinkPage.AddCssClass("page-link link-pr");
            previousLinkPage.MergeAttribute("href", pageUrl(pagingInfo.CurrentPage - 1));
            previousLinkPage.MergeAttribute("aria-label", "Previous");

            var firstSpan = new TagBuilder("span");

            firstSpan.MergeAttribute("aria-hidden", "true");
            firstSpan.InnerHtml += "&laquo;";

            var secondSpan = new TagBuilder("span");

            secondSpan.AddCssClass("sr-only");
            secondSpan.InnerHtml += "Previous";

            previousLinkPage.InnerHtml += firstSpan;
            previousLinkPage.InnerHtml += secondSpan;

            listElement.InnerHtml += previousLinkPage;

            builder.Append(listElement.ToString());
        }
        protected override async Task <IEnumerable <CarOwner> > GetDataAsync(PagingInfoViewModel pagingInfo, string ttbSearchMessage)
        {
            IQueryable <CarOwner> q = ParkDB.CarOwners;

            string searchText = ttbSearchMessage?.Trim();

            if (!String.IsNullOrEmpty(searchText))
            {
                q = q.Where(u => u.Username.Contains(searchText));
            }

            if (GetIdentityName() != "admin")
            {
                q = q.Where(u => u.Username != "admin");
            }



            // 获取总记录数(在添加条件之后,排序和分页之前)
            pagingInfo.RecordCount = await q.CountAsync();

            // 排列和数据库分页
            q = SortAndPage(q, pagingInfo);

            return((await q.Include(p => p.TransactionRecords).Include(p => p.Cars).ToListAsync())
                   .Select(p => new ExtendCarOwner().Apply(p, ParkDB).Result));
        }
Esempio n. 13
0
        public void GivenADocumentsViewModel_WhenIGetACollectionOfDocumentViewModels_ThenItIsInitialized()
        {
            var model = new DocumentsViewModel();
            List <DocumentViewModel> documents           = model.Documents;
            PagingInfoViewModel      pagingInfoViewModel = model.PagingInfo;

            documents.Should().NotBeNull();
            pagingInfoViewModel.Should().NotBeNull();
        }
Esempio n. 14
0
 public async Task OnGetAsync()
 {
     PagingInfo = new PagingInfoViewModel
     {
         PageIndex = 0,
         PageSize  = ConfigHelper.PageSize
     };
     ParkAreas = await GetDataAsync(PagingInfo, string.Empty);
 }
Esempio n. 15
0
 public void SetUp()
 {
     _pagingInfo = new PagingInfoViewModel
     {
         CurrentPage  = 2,
         TotalItems   = 28,
         ItemsPerPage = 10,
         TotalPages   = (int)Math.Ceiling((decimal)28 / 10)
     };
 }
Esempio n. 16
0
        public static MvcHtmlString PageLinks(this HtmlHelper html,
                                              PagingInfoViewModel pagingInfo, Func <int, string> pageUrl)
        {
            var builder = new StringBuilder();

            CreatePreviousPageLink(pagingInfo, pageUrl, builder);
            CreatePageLinks(pagingInfo, pageUrl, builder);
            CreateNextPageLink(pagingInfo, pageUrl, builder);

            return(MvcHtmlString.Create(builder.ToString()));
        }
Esempio n. 17
0
        protected async Task <NewsListViewModel> GetNewsAsync(int?newsSource, bool?orderByDate, int page)
        {
            var pagingInfo = new PagingInfoViewModel
            {
                CurrentPage  = page,
                ItemsPerPage = NEWS_PER_PAGE
            };
            var requestFormData = new RequestFormData
            {
                NewsSource = newsSource
            };

            if (orderByDate.HasValue)
            {
                requestFormData.OrderByDate = orderByDate.Value;
            }

            var newsListViewModel = new NewsListViewModel
            {
                News            = Enumerable.Empty <NewsViewModel>(),
                PagingInfo      = pagingInfo,
                RequestFormData = requestFormData
            };

            if (!(await _dbContext.NewsSources.AnyAsync()))
            {
                return(newsListViewModel);
            }

            var news = _dbContext.News.Include(n => n.NewsSource).AsQueryable();

            if (requestFormData.NewsSource.HasValue)
            {
                if ((await _dbContext.NewsSources.FindAsync(requestFormData.NewsSource.Value)) == null)
                {
                    return(newsListViewModel);
                }

                news = news.Where(n => n.NewsSource.Id == requestFormData.NewsSource.Value);
            }

            pagingInfo.TotalItems = await news.CountAsync();

            news = requestFormData.OrderByDate ?
                   news.OrderByDescending(n => n.PublishDate) :
                   news.OrderBy(n => n.NewsSource.Name);

            news = news.Skip((pagingInfo.CurrentPage - 1) * NEWS_PER_PAGE).Take(NEWS_PER_PAGE);

            newsListViewModel.News = await news.ProjectTo <NewsViewModel>(_mapper.ConfigurationProvider).ToArrayAsync();

            return(newsListViewModel);
        }
Esempio n. 18
0
 public async Task OnGetAsync(int?carOwnerID)
 {
     this.carOwnerID = carOwnerID;
     PagingInfo      = new PagingInfoViewModel
     {
         SortField     = "Time",
         SortDirection = "DESC",
         PageIndex     = 0,
         PageSize      = ConfigHelper.PageSize
     };
     TransactionRecords = await GetDataAsync(PagingInfo, string.Empty);
 }
Esempio n. 19
0
        public UsersViewModel(IList <Entities.ApplicationUser> users)
        {
            foreach (var user in users)
            {
                var x = new ApplicationUserViewModel(user);
                this._users.Add(x);
            }

            this.AddUserViewModel = new AddUserViewModel();

            PagingInfo = new PagingInfoViewModel();
        }
Esempio n. 20
0
        public UsersViewModel(IEnumerable <ApplicationUser> users)
        {
            foreach (var user in users)
            {
                var x = new ApplicationUserViewModel(user);
                this._users.Add(x);
            }

            this.AddUserViewModel = new AddUserViewModel();

            PagingInfo = new PagingInfoViewModel();
        }
Esempio n. 21
0
 private async Task<IEnumerable<User>> RoleUser_LoadDataAsync(int grid1SelectedRowID)
 {
     // 表格2
     var grid2PagingInfo = new PagingInfoViewModel
     {
         SortField = "Name",
         SortDirection = "DESC",
         PageIndex = 0,
         PageSize = ConfigHelper.PageSize
     };
     Grid2PagingInfo = grid2PagingInfo;
     return await RoleUser_GetDataAsync(grid2PagingInfo, grid1SelectedRowID, String.Empty);
 }
Esempio n. 22
0
        public async Task <IActionResult> OnPostRoleUser_Grid1_SortAsync(string[] Grid1_fields, string Grid1_sortField, string Grid1_sortDirection)
        {
            var grid1UI    = UIHelper.Grid("Grid1");
            var pagingInfo = new PagingInfoViewModel
            {
                SortField     = Grid1_sortField,
                SortDirection = Grid1_sortDirection
            };

            grid1UI.DataSource(await Sort <Role>(DB.Roles, pagingInfo).ToListAsync(), Grid1_fields, clearSelection: false);

            return(UIHelper.Result());
        }
Esempio n. 23
0
        private async Task <IEnumerable <User> > RoleUserNew_LoadDataAsync(int roleID)
        {
            var pagingInfo = new PagingInfoViewModel
            {
                SortField     = "Name",
                SortDirection = "DESC",
                PageIndex     = 0,
                PageSize      = ConfigHelper.PageSize
            };

            PagingInfo = pagingInfo;

            return(await RoleUserNew_GetDataAsync(pagingInfo, roleID, String.Empty));
        }
Esempio n. 24
0
        private async Task <IEnumerable <Online> > Online_LoadDataAsync()
        {
            var pagingInfo = new PagingInfoViewModel
            {
                SortField     = "UpdateTime",
                SortDirection = "DESC",
                PageIndex     = 0,
                PageSize      = ConfigHelper.PageSize
            };

            PagingInfo = pagingInfo;

            return(await Online_GetDataAsync(pagingInfo, String.Empty));
        }
        public async Task OnGetAsync()
        {
            var pagingInfo = new PagingInfoViewModel
            {
                SortField     = "Username",
                SortDirection = "DESC",
                PageIndex     = 0,
                PageSize      = ConfigHelper.PageSize
            };

            PagingInfo = pagingInfo;

            CarOwners = (await GetDataAsync(pagingInfo, string.Empty)).Cast <ExtendCarOwner>();
        }
        public async Task OnGetAsync()
        {
            var pagingInfo = new PagingInfoViewModel
            {
                SortField     = "Username",
                SortDirection = "DESC",
                PageIndex     = 0,
                PageSize      = ConfigHelper.PageSize
            };

            PagingInfo        = pagingInfo;
            ViewBag.MobileUrl = await Park.Models.Config.GetAsync(ParkDB, "MobileUrl", "http://请填写手机端地址");

            CarOwners = (await GetDataAsync(pagingInfo, string.Empty)).Cast <ExtendCarOwner>();
        }
Esempio n. 27
0
        public static MvcHtmlString PageLinks(this HtmlHelper html, PagingInfoViewModel pagingInfo, Func <int, string> pageUrl)
        {
            StringBuilder result = new StringBuilder(); for (int i = 1; i <= pagingInfo.TotalPages; i++)

            {
                TagBuilder tag = new TagBuilder("a"); tag.MergeAttribute("href", pageUrl(i));
                tag.InnerHtml = i.ToString(); if (i == pagingInfo.CurrentPage)
                {
                    tag.AddCssClass("selected"); tag.AddCssClass("btn-primary");
                }
                tag.AddCssClass("btn btn-default");
                result.Append(tag.ToString());
            }
            return(MvcHtmlString.Create(result.ToString()));
        }
        public async Task OnGetAsync(int?parkAreaID)
        {
            this.parkAreaID = parkAreaID;
            var pagingInfo = new PagingInfoViewModel
            {
                SortField     = "ID",
                SortDirection = "ASC    ",
                PageIndex     = 0,
                PageSize      = ConfigHelper.PageSize
            };

            PagingInfo = pagingInfo;

            ParkingSpaces = (await GetDataAsync(pagingInfo, string.Empty));
        }
Esempio n. 29
0
        public void CanSendPaginationViewModel()
        {
            //Arrange
            // controller arranged from the controller fixture

            //Act
            var result = GetViewModel <TweetListViewModel>(Controller.Get(2));

            //Assert
            PagingInfoViewModel pageInfo = result.PagingInfo;

            Assert.Equal(2, pageInfo.CurrentPage);
            Assert.Equal(3, pageInfo.ItemsPerPage);
            Assert.Equal(9, pageInfo.TotalItems);
            Assert.Equal(3, pageInfo.TotalPages);
        }
Esempio n. 30
0
        public void AddAppManCoEmails(PagedResult <Entities.AppManCoEmail> appManCoEmails)
        {
            appManCoEmails.Results.ToList().ForEach(x => AppManCoEmails.Add(new AppManCoEmailViewModel(x)));

            PagingInfo = new PagingInfoViewModel
            {
                CurrentPage  = appManCoEmails.CurrentPage,
                TotalItems   = appManCoEmails.TotalItems,
                ItemsPerPage = appManCoEmails.ItemsPerPage,
                TotalPages   = appManCoEmails.TotalPages,
                StartRow     = appManCoEmails.StartRow,
                EndRow       = appManCoEmails.EndRow
            };

            CurrentPage = PagingInfo.CurrentPage.ToString();
        }