Beispiel #1
0
        public ActionResult Edit(string id)
        {
            int     idNo = Convert.ToInt32(id);
            RoleRPS role = RoleRPS.GetRole(idNo);

            return(View(role));
        }
Beispiel #2
0
        public ActionResult Welcome()
        {
            string  user = User.Identity.Name;
            RoleRPS role = new RoleRPS {
                ID = 1, Name = "database_admin"
            };

            return(Json(role, JsonRequestBehavior.AllowGet));
        }
Beispiel #3
0
        // GET: Role
        public ActionResult Index(string msg)
        {
            if (!string.IsNullOrEmpty(msg))
            {
                ViewBag.Message = msg;
            }
            IEnumerable <RoleRPS> result = RoleRPS.GetRoles();

            return(View(result));
        }
Beispiel #4
0
        public int CreateRole(RoleRPS rle)
        {
            string sqlString = " INSERT INTO [ROLES] (NAME, ISDEFAULT, ISACTIVE) VALUES (@RoleName,1,1);";

            SqlParameter[] param = new SqlParameter[]
            {
                new SqlParameter("@RoleName", rle.Name)
            };
            return(ExecNonQuery(sqlString, param));
        }
Beispiel #5
0
 public ActionResult Create(RoleRPS role)
 {
     if (ModelState.IsValid)
     {
         role.Create();
         ViewBag.Message = "Created role successfully.";
         return(RedirectToAction("Index", new { msg = "Created role successfully." }));
     }
     ViewBag.Message = "Error in creating Role";
     return(View(role));
 }
Beispiel #6
0
 public ActionResult Edit(RoleRPS role)
 {
     if (ModelState.IsValid)
     {
         //Save changes
         role.Update();
         ViewBag.Message = "updated Role successfully";
         return(View(role));
     }
     ViewBag.Message = "Failed to update Role";
     return(View(role));
 }
Beispiel #7
0
        public int UpdateRole(RoleRPS rle)
        {
            string sqlString = "UPDATE ROLES SET NAME = @RoleName, ISACTIVE = @IsActive WHERE ID = @Id;";

            SqlParameter[] param = new SqlParameter[]
            {
                new SqlParameter("@RoleName", rle.Name),
                new SqlParameter("@IsActive", rle.IsActive),
                new SqlParameter("@Id", rle.ID)
            };
            return(ExecNonQuery(sqlString, param));
        }
        public RoleModule GetRoleModule(int roleId)
        {
            string sqlString = string.Empty;

            sqlString += "SELECT ID, NAME, ISDEFAULT, ISACTIVE FROM [ROLES] WHERE ID = @RoleId; ";
            sqlString += "select b.ID, b.[Name], b.DESCRIPTION, b.LINKURL, b.PARENTID, b.SORTID, "
                         + "(select Count(MODULE_ID) from ROLEMODULES WHERE ROLE_ID = @RoleId AND MODULE_ID = b.ID) as IsAuth "
                         + "FROM MODULES b WHERE ISDELETED = 0;";
            SqlParameter[] param = new SqlParameter[]
            {
                new SqlParameter("@RoleId", roleId)
            };
            DataSet ds = QuerySet(sqlString, param);
            //table[0] = Role
            //table[1] = Module
            RoleModule roleModule = new RoleModule();

            if (ds.Tables[0].Rows.Count > 0)
            {
                DataRow dr  = ds.Tables[0].Rows[0];
                RoleRPS rle = new RoleRPS
                {
                    ID        = Convert.ToInt32(dr["ID"]),
                    Name      = dr["NAME"].ToString(),
                    IsActive  = Convert.ToBoolean(dr["ISACTIVE"]),
                    IsDefault = Convert.ToBoolean(dr["ISDEFAULT"])
                };
                roleModule.Role = rle;
            }
            if (ds.Tables[1].Rows.Count > 0)
            {
                foreach (DataRow dr in ds.Tables[1].Rows)
                {
                    ModuleRPS mod = new ModuleRPS
                    {
                        ID           = Convert.ToInt32(dr["id"]),
                        Name         = dr["Name"].ToString(),
                        Description  = dr["DESCRIPTION"].ToString(),
                        LinkURL      = dr["LINKURL"].ToString(),
                        ParentId     = Convert.ToInt32(dr["PARENTID"]),
                        SortId       = Convert.ToInt32(dr["SORTID"]),
                        IsAuthorized = Convert.ToInt32(dr["IsAuth"]) > 0 ? true : false
                    };
                    roleModule.Module.Add(mod);
                }
            }
            return(roleModule);
        }
Beispiel #9
0
        public List <RoleRPS> GetRoles()
        {
            List <RoleRPS> list = new List <RoleRPS>();

            string    sqlString = "SELECT ID, NAME, ISDEFAULT, ISACTIVE FROM [ROLES]";
            DataTable dt        = QueryTable(sqlString);

            if (dt.Rows.Count > 0)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    RoleRPS rle = BindDataRow(dr);
                    list.Add(rle);
                }
            }
            return(list);
        }
Beispiel #10
0
        public RoleRPS GetRole(int Id)
        {
            string sqlString = "SELECT ID, NAME, ISDEFAULT, ISACTIVE FROM [ROLES] WHERE ID = @RoleId";

            SqlParameter[] param = new SqlParameter[]
            {
                new SqlParameter("@RoleId", Id)
            };
            DataTable dt = QueryTable(sqlString, param);

            if (dt.Rows.Count > 0)
            {
                DataRow dr  = dt.Rows[0];
                RoleRPS rle = BindDataRow(dr);
                return(rle);
            }
            return(null);
        }
Beispiel #11
0
        public RoleRPS GetRoleByUsername(string user)
        {
            string sqlString = "Select r.[ID],r.ISACTIVE,r.ISDEFAULT, r.[NAME] From ROLES r, USERROLES ur, USERS u " +
                               "Where u.LOGINNAME = @Username and u.ID = ur.[USER_ID] and ur.[ROLE_ID] = r.[ID];";

            SqlParameter[] param = new SqlParameter[]
            {
                new SqlParameter("@Username", user)
            };
            DataTable dt = QueryTable(sqlString, param);

            if (dt.Rows.Count > 0)
            {
                DataRow dr  = dt.Rows[0];
                RoleRPS rle = BindDataRow(dr);
                return(rle);
            }
            return(null);
        }
Beispiel #12
0
        private ActionResult TestJson()
        {
            List <RoleRPS> roles = RoleRPS.GetRoles();

            return(Json(roles, JsonRequestBehavior.AllowGet));
        }
Beispiel #13
0
 public RoleModule()
 {
     Role   = new RoleRPS();
     Module = new List <ModuleRPS>();
 }