public async Task <ActionResult <ClientProfileDto> > GetMyProfile() { var userProfileResult = await _clientRepository.GetUserProfile(this.UserId()); if (!userProfileResult) { Response.StatusCode = (int)HttpStatusCode.InternalServerError; return(Conflict(HttpStatusCode.InternalServerError.ToString())); } return(Ok(AccountProfileVM.FromAccountProfileDto(userProfileResult))); }
public async Task <IActionResult> Profile() { var myUser = await userManager.GetUserAsync(HttpContext.User); User user = mysticoContext.GetUserByAspUserId(myUser.Id); AccountProfileVM viewModel = new AccountProfileVM() { FirstName = user.FirstName, LastName = user.LastName, Email = user.Email }; return(View(viewModel)); }
public async Task <IActionResult> Profile(AccountProfileVM viewModel) { if (!ModelState.IsValid) { return(View(viewModel)); } //Updater vår userProfile var myUser = await userManager.GetUserAsync(HttpContext.User); User user = mysticoContext.GetUserByAspUserId(myUser.Id); try { mysticoContext.UpdateUserProfile(viewModel, user); var resultUserName = await userManager.SetUserNameAsync(myUser, viewModel.Email); var resultEmail = await userManager.SetEmailAsync(myUser, viewModel.Email); await userManager.UpdateNormalizedUserNameAsync(myUser); await userManager.UpdateNormalizedEmailAsync(myUser); if (viewModel.Password != null) { var resultPassWord = await userManager.ChangePasswordAsync(myUser, viewModel.CurrentPassword, viewModel.Password); } viewModel.Message = "Du har uppdaterat din profil"; } catch { viewModel.Message = "Knas!"; } finally { viewModel.Password = ""; viewModel.CurrentPassword = ""; viewModel.PasswordCheck = ""; } return(View(viewModel)); }
// MY PROFILE public ActionResult MyProfile() { UserRepository userRepo = new UserRepository(); User user = userRepo.GetById(AuthenticationService.LoggedUser.ID); AccountProfileVM p = new AccountProfileVM() { ID = user.ID, FirstName = user.FirstName, LastName = user.LastName, Username = user.Username, Password = user.Password, Email = user.Email }; if (user.ImageName != null) { p.ImageName = user.ImageName; } return(View(p)); }
public ActionResult MyProfile(AccountProfileVM model) { if (ModelState.IsValid) { UserRepository userRepo = new UserRepository(); User user = userRepo.GetById(model.ID); user.FirstName = model.FirstName; user.LastName = model.LastName; user.Password = model.Password; if (model.Image != null && model.Image.ContentLength > 0) { if (model.Image.ContentType.Contains("image")) { model.ImageName = Path.GetFileName(model.Image.FileName); string imagePath = Server.MapPath("~/Images/" + model.ImageName); model.Image.SaveAs(imagePath); user.ImageName = model.ImageName; } else { ModelState.AddModelError(string.Empty, "Uploaded file isn't an image!"); return(View(model)); } } bool userDoesntExist = true; if (model.Username != user.Username) { User userUsername = userRepo.GetAll(us => us.Username == model.Username).FirstOrDefault(); if (userUsername != null) { ModelState.AddModelError("Username", "Username already exists"); userDoesntExist = false; } user.Username = model.Username; } if (model.Email != user.Email) { User userEmail = userRepo.GetAll(us => us.Email == model.Email).FirstOrDefault(); if (userEmail != null) { ModelState.AddModelError("Email", "Email already exists"); userDoesntExist = false; } user.Email = model.Email; } if (userDoesntExist) { userRepo.Save(user); return(RedirectToAction("Index", "Home")); } } return(View(model)); }