public void Editprofile(string username, EditprofileViewModel edit) { if (edit.UserAvatar != null) { string Imagepath = ""; if (edit.AvatarName != "Deafault.jpg") { Imagepath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/UserAvatar", edit.AvatarName); if (File.Exists(Imagepath)) { File.Delete(Imagepath); } } edit.AvatarName = Namegenerator.GenerateUniqcode() + Path.GetExtension(edit.UserAvatar.FileName); Imagepath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/UserAvatar", edit.AvatarName); using (var stream = new FileStream(Imagepath, FileMode.Create)) { edit.UserAvatar.CopyTo(stream); } } var user = getuserbyusername(username); user.UserName = edit.UserName; user.Email = edit.Email; user.UserAvatar = edit.AvatarName; updateuser(user); }
public IActionResult Editprofile(EditprofileViewModel edit) { if (!ModelState.IsValid) { return(View(edit)); } _Userservice.Editprofile(edit.UserName, edit); HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme); return(Redirect("/Login?Editprofile=true")); }
public ActionResult Editprofile() { var userid = User.Identity.GetUserId(); var user = db.Users.Where(a => a.Id == userid).Single(); EditprofileViewModel profile = new EditprofileViewModel(); profile.Email = user.Email; profile.UserName = user.UserName; profile.curruntPassword = ""; return(View(profile)); }
public async Task <KoinoniaUsers> UpdateProfile(EditprofileViewModel model) { //get the old profile var UserProfileToUpdate = usersRepo.Get(model.Id); //before updating, check if new update is null or whitespace UserProfileToUpdate.FirstName = string.IsNullOrWhiteSpace(model.FirstName) ? UserProfileToUpdate.FirstName : model.FirstName; UserProfileToUpdate.LastName = string.IsNullOrWhiteSpace(model.LastName) ? UserProfileToUpdate.LastName : model.LastName; UserProfileToUpdate.stateOfOrigin = model.StateOfOrigin == default ? UserProfileToUpdate.stateOfOrigin : model.StateOfOrigin; UserProfileToUpdate.Gender = model.Gender == default ? UserProfileToUpdate.Gender : model.Gender; UserProfileToUpdate.PhoneNumber = string.IsNullOrWhiteSpace(model.PhoneNumber) ? UserProfileToUpdate.PhoneNumber : model.PhoneNumber; usersRepo.Update(UserProfileToUpdate); await usersRepo.SaveChangesAsync(); return(UserProfileToUpdate); }
public async Task <IActionResult> EditProfile(EditprofileViewModel model) { if (model != null) { //get the current login user to update his profile var appUser = await GetUser(); model.Id = Guid.Parse(appUser.Id); var result = await userService.UpdateProfile(model); if (result != null) { return(Ok(result)); } } return(BadRequest(new { message = "model is null" })); }
public ActionResult Editprofile(EditprofileViewModel profile) { var userid = User.Identity.GetUserId(); var user = db.Users.Where(a => a.Id == userid).Single(); if (!UserManager.CheckPassword(user, profile.curruntPassword)) { ViewBag.message = "the password is not correct"; } else { var newpasshash = UserManager.PasswordHasher.HashPassword(profile.newPassword); user.UserName = profile.UserName; user.Email = profile.Email; user.PasswordHash = newpasshash; db.Entry(user).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); ViewBag.message = "The Modified is successfully"; } return(View(profile)); }