public ProfilAdminViewModel PreparedPage(string userId) { var user = this.context .Users .FirstOrDefault(u => u.Id == userId); var model = new ProfilAdminViewModel() { AvatarLocation = user.Avatar, FirstName = user.FirstName, LastName = user.LastName, }; return(model); }
public ProfilAdminViewModel SaveChanges(ProfilAdminViewModel model, string userId) { var user = this.context.Users .FirstOrDefault(u => u.Id == userId); user.Avatar = model.AvatarLocation; user.FirstName = model.FirstName; user.LastName = model.LastName; this.context.SaveChanges(); var message = $"Успешно променен профил"; this.messageService.AddMessageAtDB(userId, message); var returnModel = this.PreparedPage(userId); return(returnModel); }
public async Task <IActionResult> ChangePassword(ProfilAdminViewModel model) { var startUp = this.StartUp(); if (startUp != null) { return(startUp); } var user = await this.userManager.GetUserAsync(this.User); if (user == null) { return(this.NotFound($"Unable to load user with ID '{this.userManager.GetUserId(this.User)}'.")); } var changPassword = model.ResetPasswordViewModel; var changePasswordResult = await this.userManager.ChangePasswordAsync(user, changPassword.OldPassword, changPassword.NewPassword); var returnModel = this.adminProfileService.PreparedPage(this.userId); if (!changePasswordResult.Succeeded) { foreach (var error in changePasswordResult.Errors) { this.ModelState.AddModelError(string.Empty, error.Description); } this.ViewData["message"] = "Неуспешно сменяне на парола!"; return(this.View("Profile", returnModel)); } await this.signInManager.RefreshSignInAsync(user); this.ViewData["message"] = "Успешно сменена на парола!"; return(this.View("Profile", returnModel)); }
public IActionResult Profile(ProfilAdminViewModel model) { var startUp = this.StartUp(); if (startUp != null) { return(startUp); } var pic = model.Photo; if (pic != null) { var fileName = Path.Combine( this.hostingEnvironment.WebRootPath + "/img/Avatars", Path.GetFileName(this.userId + "_" + pic.FileName)); pic.CopyTo(new FileStream(fileName, FileMode.Create)); model.AvatarLocation = "/img/Avatars/" + Path.GetFileName(fileName); } var returnModel = this.adminProfileService.SaveChanges(model, this.userId); return(this.View(returnModel)); }