// Enable initialization with an instance of ApplicationUser:
        public SelectUserRolesViewModel(ApplicationUser user)
            : this()
        {
            this.UserName = user.UserName;
            this.Email = user.Email;
            this.Dpi = user.Dpi;
            this.Nombre = user.Nombre;
            this.Apellido = user.Apellido;
            this.Direccion = user.Direccion;
            this.Telefono = user.Telefono;
            this.Referencia1 = user.Referencia1;
            this.Referencia2 = user.Referencia2;
            this.TelefonoReferencia1 = user.TelefonoReferencia1;
            this.TelefonoReferencia2 = user.TelefonoReferencia2;

            var Db = new ApplicationDbContext();

            // Add all available roles to the list of EditorViewModels:
            var allRoles = Db.Roles;
            foreach (var role in allRoles)
            {
                // An EditorViewModel will be used by Editor Template:
                var rvm = new SelectRoleEditorViewModel(role);
                this.Roles.Add(rvm);
            }

            // Set the Selected property to true for those roles for 
            // which the current user is a member:
            foreach (var userRole in user.Roles)
            {
                var checkUserRole =
                    this.Roles.Find(r => r.RoleName == userRole.Role.Name);
                checkUserRole.Selected = true;
            }
        }
示例#2
0
        // Enable initialization with an instance of Users:
        public SelectUserRolesViewModel(Users user)
            : this()
        {
            this.UserName  = user.UserName;
            this.PersonaId = user.PersonaId;

            var Db = new ApplicationDbContext();

            // Add all available roles to the list of EditorViewModels:
            var allRoles = Db.Roles;

            foreach (var role in allRoles)
            {
                // An EditorViewModel will be used by Editor Template:
                var rvm = new SelectRoleEditorViewModel(role);
                this.Roles.Add(rvm);
            }

            // Set the Selected property to true for those roles for
            // which the current user is a member:
            foreach (var userRole in user.Roles)
            {
                var checkUserRole =
                    this.Roles.Find(r => r.RoleName == userRole.Role.Name);
                checkUserRole.Selected = true;
            }
        }