Ejemplo n.º 1
0
        public ActionResult Edit(long id)
        {
            try{
                ViewBag.Head = "Roles - Edit";
                Models.RoleModel rle = new Models.RoleModel();
                CLayer.Role      rp  = BLayer.RolePermissions.GetRole(id);
                rle.Id            = rp.Id;
                rle.Name          = rp.Name;
                rle.PermissionIds = "";
                rle.Permissions   = BLayer.RolePermissions.GetAllPermissions((int)id);

                foreach (CLayer.RolePermission r in rle.Permissions)
                {
                    if (!r.HasAccess)
                    {
                        if (rle.PermissionIds == "")
                        {
                            rle.PermissionIds = r.ModuleId.ToString();
                        }
                        else
                        {
                            rle.PermissionIds = rle.PermissionIds + "," + r.ModuleId.ToString();
                        }
                    }
                }
                return(View(rle));
            }
            catch (Exception ex)
            {
                Common.LogHandler.HandleError(ex);
                return(Redirect("~/Admin/ErrorPage"));
            }
        }
Ejemplo n.º 2
0
        public long SaveRole(CLayer.Role role)
        {
            List <DataPlug.Parameter> param = new List <DataPlug.Parameter>();

            param.Add(Connection.GetParameter("pId", DataPlug.DataType._Varchar, role.Id));
            param.Add(Connection.GetParameter("pName", DataPlug.DataType._Varchar, role.Name));
            object val = Connection.ExecuteQueryScalar("role_Save", param);

            return(Connection.ToLong(val));
        }
Ejemplo n.º 3
0
        public ActionResult Save(Models.RoleModel data)
        {
            try
            {
                CLayer.Role rp = new CLayer.Role();
                rp.Id   = data.Id;
                rp.Name = data.Name;
                long   roleId = BLayer.RolePermissions.SaveRole(rp);
                string ids    = data.PermissionIds;
                if (ids == null)
                {
                    ids = "";
                }
                if (ids != "")
                {
                    ids = ids.Trim();
                }

                if (ids == "")
                {
                    BLayer.RolePermissions.ClearBlockedPermissions(roleId);
                }
                else
                {
                    string[]   id   = ids.Split(new char[] { ',' });
                    List <int> pids = new List <int>();
                    int        j    = 0;
                    for (int i = 0; i < id.Length; i++)
                    {
                        j = 0;
                        if (int.TryParse(id[i], out j))
                        {
                            pids.Add(j);
                        }
                    }
                    if (pids.Count > 0)
                    {
                        BLayer.RolePermissions.SaveRolePermission((int)roleId, pids);
                    }
                    else
                    {
                        BLayer.RolePermissions.ClearBlockedPermissions(roleId);
                    }
                }
            }
            catch (Exception ex)
            {
                Common.LogHandler.HandleError(ex);
                return(Redirect("~/Admin/ErrorPage"));
            }
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 4
0
        public CLayer.Role GetRole(long id)
        {
            String    sql = "Select * from Roles Where Id=" + id.ToString();
            DataTable dt  = Connection.GetSQLTable(sql);

            if (dt.Rows.Count == 0)
            {
                return(null);
            }

            CLayer.Role r = new CLayer.Role();
            r.Id   = Connection.ToLong(dt.Rows[0]["Id"]);
            r.Name = Connection.ToString(dt.Rows[0]["Name"]);

            return(r);
        }
Ejemplo n.º 5
0
 public static long SaveRole(CLayer.Role role)
 {
     DataLayer.RolePermissions rp = new DataLayer.RolePermissions();
     return(rp.SaveRole(role));
 }