示例#1
0
        public ActionResult Index(string _searchKey, int?_parentId, int?_pageIndex)
        {
            string      _userName = null;
            ContentView result;

            if (User.IsInRole("Admin"))
            {
                _userName = null;
                result    = _services.GetAll(_searchKey, null, null, _parentId, "LICHCONGTAC", 1, false, _pageIndex, 20, _userName, null);
                IEnumerable <DropdownModel> category = _services.Dropdownlist(_parentId.GetValueOrDefault(), null, "DONVIPHONGKHOA", 1);
                ViewBag._parentId = category.Select(x => new SelectListItem {
                    Text = x.Text, Value = x.Value.ToString()
                });
            }
            else
            {
                _userName = User.Identity.Name;
                result    = _services.GetAll(_searchKey, null, null, _parentId, "LICHCONGTAC", 1, false, null, null, _userName, null);

                var um                  = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(new ApplicationDbContext()));
                var user                = um.FindById(User.Identity.GetUserId());
                var _roleUser           = user.Roles.FirstOrDefault();
                ApplicationDbContext db = new ApplicationDbContext();
                var role                = db.Roles.Find(_roleUser.RoleId);
                var _Trained            = _servicesRoleFunction.GetByUserNameCode(role.Name, "TRAINED");
                IEnumerable <DropdownModel> category = _services.Dropdownlist2(_Trained.ChuyenMucId.GetValueOrDefault(), null, "DONVIPHONGKHOA", 1);
                ViewBag._parentId = category.Select(x => new SelectListItem {
                    Text = x.Text, Value = x.Value.ToString()
                });
            }
            int totalPage = result?.Total ?? 0;

            ViewBag.TotalPage = totalPage;
            ViewBag.PageIndex = _pageIndex ?? 1;
            ViewBag.SearchKey = string.IsNullOrWhiteSpace(_searchKey) ? string.Empty : _searchKey;

            if (result != null && result.ViewContents.Count() > 0)
            {
                IEnumerable <ModelLichCongTac> model = result.ViewContents.Select(x => new ModelLichCongTac
                {
                    Id       = x.contentId,
                    Link     = x.contentAlias,
                    ParentId = x.contentParentId,
                    Name     = x.contentName,
                    Body     = x.contentBody
                });
                if (User.IsInRole("Admin"))
                {
                    return(View(model));
                }
                else
                {
                    return(View(model.ToList().Take(5)));
                }
            }
            else
            {
                List <ModelLichCongTac> model = new List <ModelLichCongTac>();
                return(View(model));
            }
        }