Exemplo n.º 1
0
        public ActionResult Role(string roleName)
        {
            if (!string.IsNullOrEmpty(roleName) && RoleExists(roleName))
            {
                var entity = _services.GetByUserName(roleName);
                ModelRoleFunction model = new ModelRoleFunction();
                model.UserName = roleName;
                var _News     = _services.GetByUserNameCode(model.UserName, "TINTUC");
                var _Document = _services.GetByUserNameCode(model.UserName, "DOCUMENT");
                var _Media    = _services.GetByUserNameCode(model.UserName, "MEDIA");
                var _Caledar  = _services.GetByUserNameCode(model.UserName, "CALENDAR");
                var _Trained  = _services.GetByUserNameCode(model.UserName, "TRAINED");
                if (_Trained != null)
                {
                    model.IdTrained             = _Trained.Id;
                    model.FunctionAdminTrained  = _Trained.ActionAdmin;
                    model.FunctionEditTrained   = _Trained.ActionEdit;
                    model.FunctionAddTrained    = _Trained.ActionAdd;
                    model.FunctionDeleteTrained = _Trained.ActionDelete;
                }

                if (_Media != null)
                {
                    model.IdMedia             = _Media.Id;
                    model.FunctionAdminMedia  = _Media.ActionAdmin;
                    model.FunctionEditMedia   = _Media.ActionEdit;
                    model.FunctionAddMedia    = _Media.ActionAdd;
                    model.FunctionDeleteMedia = _Media.ActionDelete;
                }
                if (_News != null)
                {
                    model.IdNews             = _News.Id;
                    model.FunctionAdminNews  = _News.ActionAdmin;
                    model.FunctionEditNews   = _News.ActionEdit;
                    model.FunctionAddNews    = _News.ActionAdd;
                    model.FunctionDeleteNews = _News.ActionDelete;
                }

                if (_Document != null)
                {
                    model.IdDocument             = _Document.Id;
                    model.FunctionAdminDocument  = _Document.ActionAdmin;
                    model.FunctionEditDocument   = _Document.ActionEdit;
                    model.FunctionAddDocument    = _Document.ActionAdd;
                    model.FunctionDeleteDocument = _Document.ActionDelete;
                }
                if (_Caledar != null)
                {
                    model.IdCalendar             = _Caledar.Id;
                    model.FunctionAdminCalendar  = _Caledar.ActionAdmin;
                    model.FunctionEditCalendar   = _Caledar.ActionEdit;
                    model.FunctionAddCalendar    = _Caledar.ActionAdd;
                    model.FunctionDeleteCalendar = _Caledar.ActionDelete;
                }
                return(View(model));
            }
            return(RedirectToAction("Index"));
        }
Exemplo n.º 2
0
 public bool checkEdit()
 {
     _RoleCurent = _Roleservices.GetByUserNameCode(User.Identity.Name, "TINTUC");
     if (_RoleCurent != null && _RoleCurent.ActionEdit)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 3
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));
            }
        }
Exemplo n.º 4
0
        public ActionResult Role(string id)
        {
            if (!string.IsNullOrEmpty(id))
            {
                ApplicationDbContext db = new ApplicationDbContext();
                var role = db.Roles.Find(id);

                ModelRoleFunction model = new ModelRoleFunction();
                model.UserName = role.Name;
                var _News     = _services.GetByUserNameCode(role.Name, "TINTUC");
                var _Document = _services.GetByUserNameCode(role.Name, "DOCUMENT");
                var _Media    = _services.GetByUserNameCode(role.Name, "MEDIA");
                var _Caledar  = _services.GetByUserNameCode(role.Name, "CALENDAR");
                var _Trained  = _services.GetByUserNameCode(role.Name, "TRAINED");
                if (_Trained != null)
                {
                    model.IdTrained             = _Trained.Id;
                    model.FunctionAdminTrained  = _Trained.ActionAdmin;
                    model.FunctionEditTrained   = _Trained.ActionEdit;
                    model.FunctionAddTrained    = _Trained.ActionAdd;
                    model.FunctionDeleteTrained = _Trained.ActionDelete;
                }

                if (_Media != null)
                {
                    model.IdMedia             = _Media.Id;
                    model.FunctionAdminMedia  = _Media.ActionAdmin;
                    model.FunctionEditMedia   = _Media.ActionEdit;
                    model.FunctionAddMedia    = _Media.ActionAdd;
                    model.FunctionDeleteMedia = _Media.ActionDelete;
                }
                if (_News != null)
                {
                    model.IdNews             = _News.Id;
                    model.FunctionAdminNews  = _News.ActionAdmin;
                    model.FunctionEditNews   = _News.ActionEdit;
                    model.FunctionAddNews    = _News.ActionAdd;
                    model.FunctionDeleteNews = _News.ActionDelete;
                }

                if (_Document != null)
                {
                    model.IdDocument             = _Document.Id;
                    model.FunctionAdminDocument  = _Document.ActionAdmin;
                    model.FunctionEditDocument   = _Document.ActionEdit;
                    model.FunctionAddDocument    = _Document.ActionAdd;
                    model.FunctionDeleteDocument = _Document.ActionDelete;
                }
                if (_Caledar != null)
                {
                    model.IdCalendar             = _Caledar.Id;
                    model.FunctionAdminCalendar  = _Caledar.ActionAdmin;
                    model.FunctionEditCalendar   = _Caledar.ActionEdit;
                    model.FunctionAddCalendar    = _Caledar.ActionAdd;
                    model.FunctionDeleteCalendar = _Caledar.ActionDelete;
                    model.ChuyenMucDonViId       = _Caledar.ChuyenMucId ?? 0;
                }
                IEnumerable <DropdownModel> category = _servicesContent.Dropdownlist(model.ChuyenMucDonViId, null, "DONVIPHONGKHOA", 1);
                ViewBag.ChuyenMucDonViId = category.Select(x => new SelectListItem {
                    Text = x.Text, Value = x.Value.ToString()
                });
                return(View(model));
            }
            return(RedirectToAction("Index"));
        }