public ProfilLibraryViewModel PreparedPage(string userId) { var user = this.context.Users .FirstOrDefault(u => u.DeletedOn == null && u.Id == userId); ProfilLibraryViewModel profil = new ProfilLibraryViewModel(); if (user != null) { profil.AvatarLocation = user.Avatar; profil.LibararyName = user.LibararyName; profil.LibraryLocation = user.LibraryLocation; } return(profil); }
public async Task <IActionResult> ChangePassword(ProfilLibraryViewModel 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.libraryProfileService.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(ProfilLibraryViewModel 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.libraryProfileService.SaveChanges(model, this.userId); return(this.View(model)); }
public List <object> SaveChanges(ProfilLibraryViewModel model, string userId) { var user = this.context.Users .FirstOrDefault(u => u.DeletedOn == null && u.Id == userId); ProfilLibraryViewModel profil = new ProfilLibraryViewModel(); var result = new List <object>(); string resultTitle = "Неуспешно редактиран профил"; if (user != null) { user.Avatar = model.AvatarLocation; user.LibararyName = model.LibararyName; user.LibraryLocation = model.LibraryLocation; this.context.SaveChanges(); resultTitle = "Успешно редактиран профил"; this.messageService.AddMessageAtDB(userId, resultTitle); } result.Add(this.PreparedPage(userId)); result.Add(resultTitle); return(result); }