Example #1
0
        public bool Update(Role role)
        {
            if (role == null || role.RoleId == 0 || String.IsNullOrEmpty(role.Name))
            {
                return false;
            }

            RoleDataProvider.Update(role);

            return true;
        }
Example #2
0
 public static void Update(Role role)
 {
     SqlParameter[] parameters = new SqlParameter[3];
     parameters[0] = new SqlParameter("@RoleId", SqlDbType.Int);
     parameters[0].Value = role.RoleId;
     parameters[1] = new SqlParameter("@RoleName", SqlDbType.VarChar);
     parameters[1].Value = role.Name;
     parameters[2] = new SqlParameter("@Permissions", SqlDbType.VarChar);
     if (role.Permissions != null && role.Permissions.Any())
     {
         parameters[2].Value = String.Join(",", role.Permissions.ToArray());
     }
     else
     {
         parameters[2].Value = String.Empty;
     }
     SqlHelper.ExecuteNonQuery(ConnectionHelper.ConnectionString
         , CommandType.StoredProcedure
         , "t_Role_Update"
         , parameters);
 }
Example #3
0
        public ActionResult Edit(RoleModel model)
        {
            if (model == null)
            {
                TempData["Error"] = "The post data is null";
                return View("Error");
            }
            if (!ModelState.IsValid)
            {
                ModelState.AddModelError("", "Please input role name");
                return View(model);
            }

            if (!model.SelectedPermissions.Any())
            {
                ModelState.AddModelError("", "Please select some permssions.");
                return View(model);
            }
            try
            {
                var role = new Role
                {
                    RoleId = model.RoleId,
                    Name = model.RoleName,
                    Permissions = model.SelectedPermissions
                };
                bool isSuccess = RoleManager.Instance.Update(role);
                if (!isSuccess)
                {
                    ModelState.AddModelError("", "Error hanppen, check your input.");
                    return View(model);
                }

                return RedirectToAction("index");
            }
            catch (Exception ex)
            {
                TempData["Error"] = ex.Message;
                return View("Error");
            }
        }
Example #4
0
        public static Role LoadById(int roleId)
        {
            Role role = null;

            SqlParameter[] parameters = new SqlParameter[1];
            parameters[0] = new SqlParameter("@RoleId", SqlDbType.Int);
            parameters[0].Value = roleId;

            using (var reader = SqlHelper.ExecuteReader(
                  ConnectionHelper.ConnectionString
                , CommandType.StoredProcedure
                , "t_Role_LoadById"
                , parameters))
            {
                
                if (reader.Read())
                {
                    role = new Role
                    {
                        RoleId = reader.GetInt32(0),
                        Name = reader.GetString(1),
                        InsertDate = reader.GetDateTime(2)
                    };
                }

                if (role != null && reader.NextResult())
                {
                    while (reader.Read())
                    {
                        if (reader.IsDBNull(0))
                        {
                            continue;
                        }
                        role.Permissions.Add(reader.GetString(0));
                    }
                }

                return role;
                
            }

        }