示例#1
0
        public async Task <ActionResult> ShopAjax(int?page)
        {
            try
            {
                string url        = "hang-hoa/doc-mot-trang";
                int    pageNumber = (page == null || page < 1) ? 1 : page.Value;
                var    input      = new PagedInput {
                    PageIndex = pageNumber, PageSize = 12
                };
                HangHoaPagedOutput result = await ApiHelper <HangHoaPagedOutput> .RunPostAsync(url, input);

                ViewBag.OnePageOfData = new StaticPagedList <HangHoaOutput>(result.Items, input.PageIndex, input.PageSize, result.TotalItemCount);
                if (Request.IsAjaxRequest())
                {
                    return(PartialView("_ShopAjaxPartial"));
                }
                return(View());
            }
            catch (Exception ex)
            {
                return(View("Error", model: ex.Message));
            }
        }
示例#2
0
        public async Task <ActionResult> TraCuuTheoLoaiAjax(int?id, int?page)
        {
            string urlLoai = $"loai/doc-theo-id?value={id}";
            string urlHangHoaTheoLoaiId = "hang-hoa/doc-mot-trang-theo-loai-id";

            if (id == null || id < 0)
            {
                return(RedirectToAction("Index", "Home"));
            }
            try
            {
                LoaiOutput loaiItem = await ApiHelper <LoaiOutput> .RunPostAsync(urlLoai);

                if (loaiItem == null)
                {
                    return(View(viewName: "BaoLoi", model: $"Loai {id} khong ton tai san pham"));
                }
                int pageNumber = (page == null || page < 1) ? 1 : page.Value;
                var input      = new PagedInputLoaiId {
                    PageIndex = pageNumber, PageSize = 12, Id = loaiItem.ID
                };
                HangHoaPagedOutput result = await ApiHelper <HangHoaPagedOutput> .RunPostAsync(urlHangHoaTheoLoaiId, input);

                ViewBag.OnePageOfData = new StaticPagedList <HangHoaOutput>(result.Items, input.PageIndex, input.PageSize, result.TotalItemCount);
                ViewBag.LoaiID        = loaiItem.ID;
                if (Request.IsAjaxRequest())
                {
                    return(PartialView("_ShopAjaxPartial"));
                }
                return(View("ShopAjax"));
            }
            catch (Exception ex)
            {
                return(View(viewName: "BaoLoi", model: $"Lỗi truy cập dữ liệu {ex.Message}"));
            }
        }