Exemplo n.º 1
0
 /// <summary>
 /// Deprecated Method for adding a new object to the UserPermissionPairs EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToUserPermissionPairs(UserPermissionPair userPermissionPair)
 {
     base.AddObject("UserPermissionPairs", userPermissionPair);
 }
Exemplo n.º 2
0
        public ActionResult Permissions(String operand)
        {
            var db = new ModelsDataContext();
            var permsModel = db.UserPermissionPairs;
            var allPermsModel = db.Permissions;

            return authenticatedAction(new String[] { "UU" }, ()=> formAction(() => {
                logger.DebugFormat("UsersController.Permissions accessed for {0}", operand);

                IEnumerable<String> raw_selectedPerms = permsModel
                    .Where(upp => upp.userName == operand)
                    .Select(upp => upp.permission);
                IEnumerable<String> raw_restPerms = allPermsModel
                    .Where(p => !(raw_selectedPerms.Contains(p.permission)))
                    .Select(p => p.permission);

                //(permission, description).
                List<Tuple<String, String>> selectedPerms_desc = new List<Tuple<String, String>>();
                foreach (String perm in raw_selectedPerms) {
                    selectedPerms_desc.Add(new Tuple<String, String>(
                        perm,
                        allPermsModel.FirstOrDefault(p => p.permission == perm).description
                    ));
                }

                List<Tuple<String, String>> restPerms_desc = new List<Tuple<String, String>>();
                foreach (String perm in raw_restPerms) {
                    restPerms_desc.Add(new Tuple<String, String>(
                        perm,
                        allPermsModel.FirstOrDefault(p => p.permission == perm).description
                    ));
                }

                ViewData["Username"] = operand;
                ViewData["SelectedPerms"] = selectedPerms_desc;
                ViewData["RestPerms"] = restPerms_desc;

                return View();
            },
            () => {
                //get the names for each permission.
                String raw_perm_descs = Request.Form["selectedperms"];
                List<String> perms;

                if (raw_perm_descs == null) {
                    perms = new List<String>();
                } else {
                    //split the raw_perm_descs up.
                    perms = new List<String>();
                    var encoded_perms = raw_perm_descs.Split(new Char[]{','});
                    var decoded_perms = new List<String>();

                    //urldecode them.
                    foreach (String encoded_perm in encoded_perms) {
                        decoded_perms.Add(HttpUtility.UrlDecode(encoded_perm));
                    }

                    //fetch their ID names.
                    foreach (String decoded_desc in decoded_perms) {
                        perms.Add(allPermsModel.FirstOrDefault(p => p.description == decoded_desc).permission);
                    }
                }

                //remove all the existing permissions for the user in question...
                IEnumerable<UserPermissionPair> permsForUser = permsModel.Where(upp => upp.userName == operand);
                foreach(UserPermissionPair permPair in permsForUser) {
                    permsModel.DeleteObject(permPair);
                }

                //...and readd the ones we need.
                var newPerms = (perms.Select((String p) => {
                    var foo = new UserPermissionPair();
                    foo.userName = operand;
                    foo.permission = p;
                    return foo;
                }));
                foreach (var perm in newPerms) {
                    db.UserPermissionPairs.AddObject(perm);
                }

                db.SaveChanges();

                logger.DebugFormat("UsersController.Permissions updated for {0} with new perms {1}", operand, perms.ToString());
                updateTableTimestamp("T_CRFPNM");

                return Redirect("/users");
            }));
        }
Exemplo n.º 3
0
 /// <summary>
 /// Create a new UserPermissionPair object.
 /// </summary>
 /// <param name="permission">Initial value of the permission property.</param>
 /// <param name="userName">Initial value of the userName property.</param>
 public static UserPermissionPair CreateUserPermissionPair(global::System.String permission, global::System.String userName)
 {
     UserPermissionPair userPermissionPair = new UserPermissionPair();
     userPermissionPair.permission = permission;
     userPermissionPair.userName = userName;
     return userPermissionPair;
 }