// Enable initialization with an instance of ApplicationUser: public SelectUserRolesViewModel(ClinikeUser user) : this() { UserName = user.UserName; Id = user.Id; var Db = new ClinikeContext(); // Add all available roles to the list of EditorViewModels: var allRoles = ClinikeIdentityRoleEx.GetAll(); foreach (var role in allRoles) { // An EditorViewModel will be used by Editor Template: var chkEditorVm = new CheckBoxEditorViewModel() { Name = role.Name, Id = role.Id, Title = role.Title }; Roles.Add(chkEditorVm); } // 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 = Roles.Find(r => r.Id == userRole.RoleId); checkUserRole.Selected = true; } }
// Allow Initialization with an instance of ApplicationUser: public EditUserViewModel(ClinikeUser user) { Id = user.Id; UserName = user.UserName; Email = user.Email; }
// Return a pre-poulated instance of AppliationUser: public ClinikeUser GetUser() { var user = new ClinikeUser() { UserName = UserName, Email = Email, }; return user; }