Beispiel #1
0
        public ActionResult PermissionUser(int?userId)
        {
            List <User> lstUser = db.Users.Where(x => x.ID != 1).OrderBy(x => x.ID).ToList();

            if (userId == null)
            {
                userId = lstUser[0].ID;
            }

            string userName = db.Users.Find(userId).Name;

            ViewBag.lstUser  = lstUser;
            ViewBag.UserName = userName;

            //Danh sách role (roleId) hiện tại của user => Chỉ lấy roleId
            List <string> lstRoleUser = db.User_Permission.Where(x => x.UserID == userId).Select(x => x.RoleId).ToList();

            List <PermissionModel> lstPermissionModel = new PermissionDao().GetListPermissionModel(lstRoleUser);

            string currentRole = "";

            foreach (string roleId in lstRoleUser)
            {
                currentRole += roleId + "*";
            }

            ViewBag.userId             = userId;
            ViewBag.currentRole        = currentRole;
            ViewBag.lstPermissionGroup = lstPermissionModel;
            return(View());
        }
Beispiel #2
0
        public ActionResult Create(Uzivatel collection)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var dao = new UzivatelDao();
                    collection.WindowsId = collection.WindowsId.ToUpper();
                    collection.Id        = (int)dao.Create(collection);
                    if (collection.Role.Id > 0)
                    {
                        var permDao = new PermissionDao();
                        permDao.Create(new Permission()
                        {
                            Role      = collection.Role,
                            WindowsId = collection.WindowsId
                        });
                    }

                    TempData[MessagesHelper.Success] = Resources.UzivatelTexts.UserAdded;
                    return(RedirectToAction("Index"));
                }
                else
                {
                    TempData[MessagesHelper.Warning] = "Zkontrolujte zadané údaje";
                }
            }
            catch
            {
                TempData[MessagesHelper.Warning] = "Zkontrolujte zadané údaje";
            }
            return(View(collection));
        }
Beispiel #3
0
        public ActionResult PermissionGroup(int?groupId)
        {
            List <UserGroup> lstUserGroup = db.UserGroups.Where(x => x.ID != 1).OrderBy(x => x.ID).ToList();

            if (groupId == null)
            {
                groupId = lstUserGroup[0].ID;
            }
            string groupName = db.UserGroups.Find(groupId).Name;

            ViewBag.lstUserGroup = lstUserGroup;
            ViewBag.groupName    = groupName;

            //Danh sách role (roleId) hiện tại của group => Chỉ lấy roleId
            List <string> lstRoleGroup = db.Group_Permission.Where(x => x.GroupId == groupId).Select(x => x.RoleId).ToList();

            List <PermissionModel> lstPermissionModel = new PermissionDao().GetListPermissionModel(lstRoleGroup);

            string currentRole = "";

            foreach (string roleId in lstRoleGroup)
            {
                currentRole += roleId + "*";
            }

            ViewBag.groupId            = groupId;
            ViewBag.currentRole        = currentRole;
            ViewBag.lstPermissionGroup = lstPermissionModel;
            return(View());
        }
Beispiel #4
0
        public ActionResult Edit(Permission mode)
        {
            string id = mode.BusinessID;

            try
            {
                if (ModelState.IsValid)
                {
                    PermissionDao dao = new PermissionDao();


                    dao.Update(mode);
                    if (dao.Update(mode) > 0)
                    {
                        SetAlert("Cập nhật thành công", "success");
                        return(RedirectToAction("Index", "Permission", new { id = id }));
                    }
                    else
                    {
                        SetAlert("Không thành công", "danger");
                    }
                    return(RedirectToAction("Index", "Permission", new { id = id }));
                }
                else
                {
                    SetAlert("Không thành công", "danger");
                    return(RedirectToAction("Index", "Permission", new { id = id }));
                }
            }
            catch
            {
                return(RedirectToAction("Index", "Permission", new { id = mode.BusinessID }));
            }
        }
Beispiel #5
0
        // GET: Admin/Permistion/Edit/5
        public ActionResult Edit(int id)
        {
            PermissionDao dao = new PermissionDao();
            var           pm  = dao.GetPermistionByID(id);

            ViewBag.BusinessID = pm.BusinessID;
            return(View(pm));
        }
Beispiel #6
0
 internal static PermissionDao getPermission()
 {
     if (permissionDao == null)
     {
         permissionDao = new PermissionDao();
     }
     return(permissionDao);
 }
        internal static PermissionDao getPermission()
        {
            if (permissionDao == null)
            {
                permissionDao = new PermissionDao(ConnectionProvider.getProvide());
            }

            return(permissionDao);
        }
        public JsonResult Delete(long id)
        {
            var model = new PermissionDao().Delete(id);

            return(Json(new
            {
                status = model
            }));
        }
Beispiel #9
0
        public virtual void LoadPermission()
        {
            var permDao  = new PermissionDao();
            var permItem = permDao.GetByUser(WindowsId);

            if (permItem != null)
            {
                Role = permItem.Role;
            }
        }
Beispiel #10
0
        public void GetAllPermissionsTest()
        {
            var    target         = new PermissionDao();
            string loginid        = "permissionDao_loginid1";
            string resourceInfoId = "Role";

            IList <Permission> actual = target.GetAllPermissions(loginid, resourceInfoId);

            Assert.AreEqual(2, actual.Count);
        }
        public JsonResult Edit(string data)
        {
            JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer();
            var model  = javaScriptSerializer.Deserialize <Permission>(data);
            var result = new PermissionDao().Edit(model);

            return(Json(new
            {
                status = result
            }));
        }
        public JsonResult ViewDetail(long id)
        {
            var model = new PermissionDao().ViewDetail(id);

            return(Json(new
            {
                status = true,
                id = model.ID,
                name = model.PermissionName,
                des = model.Desciption
            }));
        }
Beispiel #13
0
        public ActionResult Edit(int id, Uzivatel collection)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var dao = new UzivatelDao();
                    collection.WindowsId = collection.WindowsId.ToUpper();
                    dao.Update(collection);

                    var permDao  = new PermissionDao();
                    var permItem = permDao.GetByUser(collection);
                    if (collection.Role.Id == 0)
                    {
                        if (permItem != null)
                        {
                            permDao.Delete(permItem);
                        }
                    }
                    else
                    {
                        if (permItem == null)
                        {
                            permDao.Create(new Permission()
                            {
                                Role      = collection.Role,
                                WindowsId = collection.WindowsId
                            });
                        }
                        else if (permItem.Role.Id != collection.Role.Id)
                        {
                            permItem.Role.Id = collection.Role.Id;
                            permDao.Update(permItem);
                        }
                    }

                    TempData[MessagesHelper.Success] = Resources.UzivatelTexts.UserUpdated;
                    return(RedirectToAction("Index"));
                }
                else
                {
                    TempData[MessagesHelper.Warning] = "Zkontrolujte zadané údaje";
                }
            }
            catch
            {
                TempData[MessagesHelper.Warning] = "Zkontrolujte zadané údaje";
            }
            return(View(collection));
        }
        public ActionResult SavePermission(string data, string FunctionId)
        {
            var           model          = new JavaScriptSerializer().Deserialize <List <SavePermission> >(data);
            PermissionDao _permissiondao = new PermissionDao();

            _permissiondao.DeleteAll(FunctionId);
            Permission permission = null;

            try
            {
                foreach (var item in model)
                {
                    permission            = new Permission();
                    permission.RoleId     = item.RoleId;
                    permission.FunctionId = FunctionId;
                    permission.CanCreate  = Boolean.Parse(item.CanCreate);
                    permission.CanDelete  = Boolean.Parse(item.CanDelete);
                    permission.CanRead    = Boolean.Parse(item.CanRead);
                    permission.CanUpdate  = Boolean.Parse(item.CanUpdate);
                    _permissiondao.Save(permission);
                }
                var functions = new FunctionDao().GetAllWithParent(FunctionId);
                if (functions.Any())
                {
                    foreach (var item in functions)
                    {
                        _permissiondao.DeleteAll(item.Id);
                        foreach (var p in model)
                        {
                            var childPermission = new Permission();
                            childPermission.FunctionId = item.Id;
                            childPermission.RoleId     = p.RoleId;
                            childPermission.CanCreate  = Boolean.Parse(p.CanCreate);
                            childPermission.CanDelete  = Boolean.Parse(p.CanDelete);
                            childPermission.CanRead    = Boolean.Parse(p.CanRead);
                            childPermission.CanUpdate  = Boolean.Parse(p.CanUpdate);
                            _permissiondao.Save(childPermission);
                        }
                    }
                }
                return(Json(new { status = true }, JsonRequestBehavior.AllowGet));
            }
            catch
            {
                return(Json(new { status = false }, JsonRequestBehavior.AllowGet));
            }
        }
Beispiel #15
0
        public ActionResult Delete(long id)
        {
            try
            {
                // TODO: Add delete logic here

                PermissionDao bdDao = new PermissionDao();

                bdDao.Delete(id);
                // SetAlert("Xóa thành công", "success");
                return(RedirectToAction("Index"));
            }
            catch
            {
                // SetAlert("Không xóa được", "danger");
                return(View());
            }
        }
Beispiel #16
0
        public ActionResult Delete(int id)
        {
            var dao  = new UzivatelDao();
            var item = dao.GetById(id);

            if (item == null)
            {
                return(RedirectToAction("Index"));
            }
            var permDao  = new PermissionDao();
            var permItem = permDao.GetByUser(item);

            if (permItem != null)
            {
                permDao.Delete(permItem);
            }

            dao.Delete(item);
            TempData[MessagesHelper.Success] = Resources.UzivatelTexts.UserDeleted;
            return(RedirectToAction("Index"));
        }
        public void GetAllPermissionsTest()
        {
            var target = new PermissionDao();
            string loginid = "permissionDao_loginid1";
            string resourceInfoId = "Role";

            IList<Permission> actual = target.GetAllPermissions(loginid, resourceInfoId);
            Assert.AreEqual(2, actual.Count);
        }
Beispiel #18
0
 public PermissionService()
 {
     Dao = new PermissionDao();
 }
 public RoleViewProxy()
 {
     RoleDao = new RoleDao(context);
     PermissionDao = new PermissionDao(context);
 }
        // GET: Admin/Permission
        public ActionResult Index(string id)
        {
            var model = new PermissionDao().GetByID(id);

            return(View(model));
        }
 public PermissionManagerImpl()
 {
     permissionDao     = PermissionDao.getInstance();
     permissionUserDao = PermissionUserDao.getInstance();
 }
        public ActionResult LoadPermission(string functionID)
        {
            List <PermissionModel> permissions = new List <PermissionModel>();
            var role          = new RoleDao().load();
            var lispermission = new PermissionDao().GetByFunctionId(functionID);

            if (lispermission.Count == 0)
            {
                foreach (var item in role)
                {
                    permissions.Add(new PermissionModel()
                    {
                        RoleId    = item.Id,
                        CanCreate = false,
                        CanDelete = false,
                        CanRead   = false,
                        CanUpdate = false,
                        AppRole   = new RoleModel()
                        {
                            Id          = item.Id,
                            Description = item.Description,
                            Role        = item.Role,
                        }
                    });
                }
            }
            else
            {
                foreach (var item in role)
                {
                    if (!lispermission.Any(m => m.RoleId.Equals(item.Id)))
                    {
                        permissions.Add(new PermissionModel()
                        {
                            RoleId    = item.Id,
                            CanCreate = false,
                            CanDelete = false,
                            CanRead   = false,
                            CanUpdate = false,
                            AppRole   = new RoleModel()
                            {
                                Id          = item.Id,
                                Description = item.Description,
                                Role        = item.Role,
                            }
                        });
                    }
                    else
                    {
                        var add = lispermission.Where(m => m.RoleId.Equals(item.Id)).Select(m => new PermissionModel
                        {
                            RoleId    = item.Id,
                            CanCreate = m.CanCreate,
                            CanDelete = m.CanDelete,
                            CanRead   = m.CanRead,
                            CanUpdate = m.CanUpdate,
                            AppRole   = new RoleModel()
                            {
                                Id          = item.Id,
                                Description = item.Description,
                                Role        = item.Role,
                            }
                        }).ToList();
                        permissions.AddRange(add);
                    }
                }
            }
            return(PartialView("_DetailPermission", permissions));
        }
 public RoleViewService()
 {
     RoleDao = new RoleDao(context);
     PermissionDao = new PermissionDao(context);
 }