public ActionResult SitesManagement(int page = 1, int pageSize = 50, string title = "", int?areaId = null) { ViewBag.Title = ""; ViewBag.MessageStatus = TempData["MessageStatus"]; ViewBag.Message = TempData["Message"]; if (pageSize == 1) { pageSize = CMSHelper.pageSizes[0]; } @ViewBag.PageSizes = CMSHelper.pageSizes; int CurrentUserId = WebMatrix.WebData.WebSecurity.CurrentUserId; string userName = User.Identity.Name; int skip = (page - 1) * pageSize; int totalRows = 0; List <SiteModel> list = new List <SiteModel>(); #region Lấy dữ liệu if (userName == "administrator") { list = sitesService.GetAll(skip, pageSize, out int totalRow, title, areaId, null).AsEnumerable().Select(item => new SiteModel { Id = item.Id, Name = item.Name, DeviceId = item.DeviceId, Latitude = item.Latitude, Longtitude = item.Longtitude, CreateDay = item.CreateDay, NguoiTao = userProfileService.userProfileResponsitory.Single(item.CreateBy).FullName, IsActive = item.IsActive, GroupsName = groupService.groupResponsitory.Single(item.Group_Id).Name, AreasName = areasService.areaResponsitory.Single(item.Area_Id).Name }).ToList(); totalRows = totalRow; } else { int groupId = userProfileService.userProfileResponsitory.Single(CurrentUserId).Group_Id.Value; list = sitesService.GetAll(skip, pageSize, out int totalRow, title, areaId, groupId).AsEnumerable().Select(item => new SiteModel { Id = item.Id, Name = item.Name, Latitude = item.Latitude, DeviceId = item.DeviceId, Longtitude = item.Longtitude, CreateDay = item.CreateDay, NguoiTao = userProfileService.userProfileResponsitory.Single(item.CreateBy).FullName, IsActive = item.IsActive, GroupsName = groupService.groupResponsitory.Single(item.Group_Id).Name, AreasName = areasService.areaResponsitory.Single(item.Area_Id).Name }).ToList(); totalRows = totalRow; } #endregion #region Hiển thị dữ liệu và phân trang SitesViewModel viewModel = new SitesViewModel { Sites = new StaticPagedList <SiteModel>(list, page, pageSize, totalRows), PagingInfo = new PagingInfo { CurrentPage = page, ItemsPerPage = pageSize, TotalItems = totalRows } }; #endregion return(View(viewModel)); }