public async Task <IActionResult> Setting(IFormFile LoadedFile, UserSettingViewModel editedUser) { if (ModelState.IsValid) { User user = await db.Users.FirstOrDefaultAsync(n => n.UserName == editedUser.UserName); var _passwordValidator = HttpContext.RequestServices.GetService(typeof(IPasswordValidator <User>)) as IPasswordValidator <User>; var _passwordHasher = HttpContext.RequestServices.GetService(typeof(IPasswordHasher <User>)) as IPasswordHasher <User>; IdentityResult result = await _passwordValidator.ValidateAsync(_userManager, user, editedUser.NewPassword); if (result.Succeeded) { user.PasswordHash = _passwordHasher.HashPassword(user, editedUser.NewPassword); await _userManager.UpdateAsync(user); return(Redirect("~/Account?user="******"User not found"); } return(RedirectToAction("Index", "Home")); }
public async Task <IActionResult> UpdateUserSettings([FromBody] UserSettingViewModel model) { try { if (_user.IsNull()) { return(Unauthorized(IdentityEnums.Errors.WhenAuthorizationUserNotFound.ToString())); } var userid = _user.FindFirstValue(ClaimTypes.NameIdentifier); var userInfo = await _dbContext.UserInfo.AsTracking().SingleOrDefaultAsync(p => p.UserId == userid); if (userInfo.IsNull()) { throw new NotFoundException($"User {userid} not found"); } userInfo.UpdateInfo(new PersonName(model.FirstName, model.MiddleName, model.LastName), model.PhoneNumber, new Address(model.City, model.Street, model.Number)); await _dbContext.SaveChangesAsync(); return(Ok()); } catch (Exception e) { throw; } }
public ActionResult EditUserSettingView(int userSettingId, int settingId, string settingValue) { UserSettingViewModel model = null; if (userSettingId > 0) { var setting = _settingService.GetUserSettingById(userSettingId); if (setting == null || User.Identity.GetUserId() != setting.ApplicationUserID) { throw new Exception("Ustawienie nie istnieje lub próbujesz edytować nie swoje ustawienia!"); } model = Mapper.Map <UserSettingViewModel>(setting); } else { var setting = _settingService.GetSettingById(settingId); if (setting == null) { throw new Exception("Ustawienie nie istnieje!"); } model = new UserSettingViewModel() { Id = 0, SettingId = setting.Id, SettingDescription = setting.SettingDescription, SettingType = setting.SettingValueType, SettingValue = settingValue }; } return(PartialView("_EditUserSettingView", model)); }
public async Task<IActionResult> UserSettings() { var model = new UserSettingViewModel { SettingDefinitions = _settingDefinitionProvider.SettingDefinitions, UserSettings = await _settingService.GetAllSettingsAsync() }; return View(model); }
public ActionResult Setting() { var id = User.Identity.GetUserId(); var currentUser = _context.Users.SingleOrDefault(x => x.Id == id); var viewModel = new UserSettingViewModel { User = currentUser }; return(View(viewModel)); }
public MainWindowViewModel(string userID) { _bussiness = new MainWindowBussiness(userID); Teaching = new TeachingManagementViewModel(_bussiness.Teaching); Calling = new NameCallingManagementViewModel(_bussiness.Calling); Payment = new PaymentViewModel(_bussiness.Payment); Overdue = new OverdueViewModel(_bussiness.Overdue); Statistic = new StatisticViewModel(_bussiness.Statistic); Setting = new UserSettingViewModel(_bussiness.UserSetting); MainFunc = 0; }
public async Task <IActionResult> UserSetting(UserSettingViewModel model) { if (ModelState.IsValid) { var settings = Mapper.Map <UserSetting>(model); await _configurationManager.SaveSettingAsync(settings); Notifier.Success("你已成功保存了用户配置。"); return(RedirectToAction(nameof(UserSetting))); } return(View(model)); }
public ActionResult EditUserSetting(UserSettingViewModel model) { var result = new { Success = "true", Message = "Success" }; if (ModelState.IsValid) { try { var userId = User.Identity.GetUserId(); if (model.Id == 0) //setting for the user doesnt exist yet { var userSetting = new UserSetting() { ApplicationUserID = userId, SettingId = model.SettingId, SettingValue = model.SettingValue }; _settingService.CreateUserSetting(userSetting); } else { var setting = _settingService.GetUserSettingById(model.Id); if (setting != null) { setting.SettingValue = model.SettingValue; _settingService.UpdateUserSetting(setting); } } } catch (Exception e) { logger.Error(e, e.Message); result = new { Success = "false", Message = WebResources.ErrorMessage }; return(Json(result, JsonRequestBehavior.AllowGet)); } } else { var error = ModelState.Values.SelectMany(v => v.Errors).FirstOrDefault().ErrorMessage; result = new { Success = "false", Message = error }; return(Json(result, JsonRequestBehavior.AllowGet)); } return(Json(result, JsonRequestBehavior.AllowGet)); }
public ActionResult ChangeUserDetail(UserSettingViewModel model) { var userInDB = _context.Users.SingleOrDefault(x => x.Id == model.User.Id); if (userInDB == null) { return(RedirectToAction("Setting")); } userInDB.Name = model.User.Name; userInDB.PhoneNumber = model.User.PhoneNumber; userInDB.Address = model.User.Address; _context.SaveChanges(); return(RedirectToAction("Setting")); }
public ActionResult UserSettings() { string userId = User.Identity.GetUserId(); if (!string.IsNullOrEmpty(userId)) { RedirectToAction("Index", "Home"); } var settings = Mapper.Map <List <UserSettingViewModel> >(_settingService.AllUserSetting(userId)); var existingSettingsId = settings.Select(x => x.Id).ToList(); var defaultSettings = _settingService.AllSettings().Where(x => !existingSettingsId.Contains(x.Id)).ToList(); foreach (var setting in defaultSettings) { var userSettingViewModel = new UserSettingViewModel() { Id = 0, SettingId = setting.Id, SettingDescription = setting.SettingDescription, SettingType = setting.SettingValueType }; if (setting.SettingValueType == "System.Int32") { userSettingViewModel.SettingValue = _defaultNumberOfDays.ToString(); } else { userSettingViewModel.SettingValue = string.Empty; } settings.Add(userSettingViewModel); } var user = _applicationUserManager.FindById(userId); var model = new UserSettingsViewModel() { UserId = userId, Settings = settings, TwoFactorEnabled = user.TwoFactorEnabled }; return(View(model)); }
public async Task<IActionResult> UserSettings(UserSettingViewModel model) { if (!ModelState.IsValid) { return View(model); } var user = await GetCurrentUserAsync(); foreach (var item in model.UserSettings) { _settingService.SetCustomSettingValueForUser(user, item.Key, item.Value); } await _userManager.UpdateAsync(user); return RedirectToAction("UserSettings"); }
public async Task <IActionResult> UserSettings([FromForm] UserSettingViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var result = ActionResultFilter(await _identityService.SetHttpContext(HttpContext).UpdateUserSettings(model)); if (result.Item1.IsOk()) { SetViewMessage(true, "Update success."); } else { SetViewMessage(false, result.Item1.ToString()); } return(View(model)); }
public ActionResult DeactivateUserAccount(UserSettingViewModel model) { return(Json(model, JsonRequestBehavior.AllowGet)); }
public ActionResult ChangeUserInformation(UserSettingViewModel model) { return(Json(model, JsonRequestBehavior.AllowGet)); }
public ActionResult UpdatePassword(UserSettingViewModel model) { return(Json(model, JsonRequestBehavior.AllowGet)); }
public UserSettingController(CompositionContainer container, object shellView) { this.container = container; this.shellView = shellView; userSettingViewModel = container.GetExportedValue<UserSettingViewModel>(); }