Пример #1
0
        public ActionResult ManageAccount(List <AccInManageAccViewModel> model, int?page, string viewType, string search, string userAction)
        {
            if (Session["Username"] != null)
            {
                string username = Session["Username"] != null ? Session["Username"] as string : string.Empty;

                // thực hiện hành động của người dùng
                userAction = userAction == null ? string.Empty : userAction;
                switch (userAction)
                {
                case "Khóa tài khoản":
                    dao.BlockAccounts(model);
                    break;

                case "Mở khóa tài khoản":
                    dao.UnlockAccounts(model);
                    break;

                default:     // không làm gì cả
                    break;
                }

                // xử lý theo từng cách hiển thị:
                viewType = viewType == null ? "" : viewType;
                search   = search == null ? "" : search;

                SuccessAndMsg getListUsersResult = dao.GetListAccInManageAccs(viewType, search);
                if (getListUsersResult.IsSuccess)
                {
                    // Trả về danh sách các sản phẩm theo điều kiện lọc
                    model = getListUsersResult.Value as List <AccInManageAccViewModel>;

                    ModelState.Clear(); // xóa các dữ liệu cũ

                    int pageSize   = 10;
                    int pageNumber = (page ?? 1); // trả về giá trị của page nếu nó là 1 giá trị khác null, nếu không trả về 1

                    ViewBag.PagedList  = model.ToPagedList(pageNumber, pageSize);
                    ViewBag.TotalPages = model.Count % 10 == 0 ? model.Count / 10 : model.Count / 10 + 1;
                    ViewBag.ViewType   = viewType;
                    ViewBag.SearchKey  = search;
                    ViewBag.UserAction = userAction;
                    return(View(model.OrderByDescending(u => u.Username).Skip((pageNumber - 1) * 10).Take(10).ToList()));
                }
            }

            return(View(model));
        }