private int AddUser(UserEditViewModel userDetail) { var user = new MyUser() { UserName = userDetail.UserName, IPAddress = Request.ServerVariables["REMOTE_ADDR"], BrowserInfo = Request.Browser.Type, Email = userDetail.Email, DateRegistered = DateTime.Now }; using (var userManager = new UserManager<MyUser, long>( new UserStore<MyUser, MyRole, long, MyLogin, MyUserRole, MyClaim>(new ApplicationDbContext()))) { var result = userManager.Create(user, userDetail.Password); if (result == IdentityResult.Success) { user = userManager.FindByName(userDetail.UserName); _userRepository.AssignStartupUserPreferenceTableColumns((int)user.Id); } } return (int)user.Id; }
private void UpdateUser(UserEditViewModel userDetail) { var user = _userRepository.Get(userDetail.Id); Band defaultBand = null; if (userDetail.DefaultBandId > 0) { defaultBand = _bandRepository.Get(userDetail.DefaultBandId); } if (user != null) { user.UserName = userDetail.UserName; user.Email = userDetail.Email; user.IsDisabled = userDetail.IsDisabled; user.DefaultBand = defaultBand; }; _userRepository.Update(user); }
private UserEditViewModel LoadUserEditViewModel(int id) { User user = null; if (id > 0) { user = _userRepository.Get(id); } var vm = new UserEditViewModel { Id = (user != null) ? user.Id : 0, UserName = (user != null) ? user.UserName : string.Empty, Email = (user != null) ? user.Email : string.Empty, UserBands = new SelectList((user != null) ? new Collection<object> { new { Value = "0", Display = "<None>" } }.ToArray() .Union( user.UserBands .Select(x => new { Value = x.Band.Id, Display = x.Band.Name })).ToArray() : new Collection<object>().ToArray(), "Value", "Display", (user != null) ? (user.DefaultBand != null) ? user.DefaultBand.Id : 0 : 0) }; return vm; }