public static UserViewModel UserViewModel(this User model) { var viewModel = new UserViewModel(); viewModel.InjectFrom(model); return viewModel; }
public virtual ActionResult AddUser() { var viewModel = new UserViewModel(); viewModel.RolesListItems = Roles.GetAllRoles().Select(x => new SelectListItem() { Text = x, Value = x }); viewModel.InstituteItems = this._institutionManager.GetAll().Select(x => new SelectListItem() { Text = x.Name, Value = x.Id.ToString() }); return PartialView(MVC.AdminUser.Views.Partial.UserFields, viewModel); }
public virtual ActionResult AddUser(UserViewModel viewModel) { if (ModelState.IsValid && Request.IsAjaxRequest()) { var status = WebSecurity.Register(viewModel.Username, viewModel.Password, viewModel.Email, true, viewModel.FirstName, viewModel.LastName); if (status == MembershipCreateStatus.Success) { if (Roles.RoleExists(viewModel.Role)) { Roles.AddUserToRole(viewModel.Username, viewModel.Role); } var user = WebSecurity.GetUser(viewModel.Username); this._institutionManager.AddUserToInstitutes(viewModel.Institutions.Select(x => x.Id), (Guid)user.ProviderUserKey); return this.Json(new { success = true }); } } return this.Json(new { success = false, errors = this.ModelErrorString() }); }