Example #1
0
        public async Task <IActionResult> Index()
        {
            // 3.系統在Action【Home/Index】讀取首頁行銷圖示。
            List <HomeImageViewModel> lHIMV = await IMR.GetHomeImageList(0, 1000);

            // 4.系統在Action【Home/Index】讀取youtube影片網址。
            YoutubeVideoViewModel YVVM = await IPR.GetYoutubeVideoList();

            // 5.系統在Action【Home/Index】讀取最新商品清單。
            List <ProductListViewModel> lPLVM = await IPRR.GetNewProductList(6);

            // 6.系統傳回View【Home/Index】,並回傳new HomeViewModel { HomeImage=3讀取值, YoutubeVideo=4讀取值, NewProduct=5讀取值}。
            ViewBag.MemberMobile = HttpContext.Session.GetString("MemberMobile");
            if (HttpContext.Session.GetInt32("MemberLevelId") != null)
            {
                ViewBag.MemberLevelId = HttpContext.Session.GetInt32("MemberLevelId");
            }
            else
            {
                ViewBag.MemberLevelId = -1;
            }
            ViewBag.NickName = HttpContext.Session.GetString("NickName");

            return(View(new HomeViewModel {
                HomeImage = lHIMV, YoutubeVideo = YVVM, NewProduct = lPLVM
            }));
        }
        public async Task <IViewComponentResult> InvokeAsync(int Page = 1, int LinkType = 0, int StartPage = 1, string AClass = "page-link")
        {
            // 9-1.系統在ViewComponent【HomeImageList】中讀取Appsetting.json中的每頁筆數RowsPerPage以及分頁頁碼連結總數PageCount。
            int RowsPerPage = int.Parse(config["Page:RowsPerPage"]);
            int PageCount   = int.Parse(config["Page:PageCount"]);
            // 9-2.系統在ViewComponent【HomeImageList】讀取首頁行銷圖示總數。
            long memberCount = await IMR.GetHomeImageListCount();

            // 9-3.系統依9-2傳回值將9傳送頁碼重設在Between 1 and (9讀取記錄筆數/RowsPerPage)+(9讀取記錄筆數%RowsPerPage==0?0:1)。
            int TotalPages = (int)(memberCount / RowsPerPage);

            if (memberCount % RowsPerPage > 0)
            {
                TotalPages += 1;
            }
            if (Page < 1)
            {
                Page = 1;
            }
            if (Page > TotalPages)
            {
                Page = TotalPages;
            }
            if (Page <= 0)
            {
                Page = 1;
            }
            // 9-4.系統計算資料Skip數=(9傳送頁碼(預設1)-1)*9-1讀取RowsPerPage。
            int Skip = (Page - 1) * RowsPerPage;
            // 9-5.系統在ViewComponent【HomeImageListListViewComponent】讀取首頁行銷圖示清單:
            List <HomeImageViewModel> lMLVM = await IMR.GetHomeImageList(Skip, RowsPerPage);

            // 9-6.系統設定PagerTagHelper之相關參數
            int CurrentPage = Page;

            // 9-6-1.系統將管理者權限清單Session["EmployeeRights"]暫存在ViewBag.TR。
            ViewBag.TR = HttpContext.Session.GetObjectFromJson <List <int> >("EmployeeRights");
            // 9-7.系統回傳View(new HomeImageManageViewModel {
            //listHomeImageListViewModel = 9 - 5讀取值,
            //CurrentPage = 9 - 6設定值,
            //TotalPages = 9 - 6設定值,
            //PageCount = 9 - 6設定值,
            //StartPage = 9 - 6設定值,
            //Parameters = 9 - 6設定值
            //});
            return(View(new HomeImageManageViewModel
            {
                listHomeImageListViewModel = lMLVM,
                CurrentPage = CurrentPage,
                TotalPages = TotalPages,
                PageCount = PageCount,
                StartPage = StartPage,
                LinkType = LinkType,
                AClass = AClass
            }));
        }