public async Task <IActionResult> EditUserProfile(Guid userId, EditUserProfileModel model) { if (!await UserExists(userId)) { return(NotFound()); } const string actionViewPath = ViewsDirectoryPath + nameof(EditUserProfile) + ".cshtml"; var currentUserId = new Guid(_userManager.GetUserId(HttpContext.User)); model.UserId = userId; if (!await _databaseContext.UserPermissionsOperator.GetUserDataEditPermissionAsync(userId, currentUserId)) { return(Forbid()); } if (!ModelState.IsValid) { return(View(actionViewPath, model)); } var userObject = await _databaseContext.Users.FirstAsync(u => u.Id == userId); userObject.FullName = model.FullName; userObject.InstitutionName = model.InstitutionName; _databaseContext.Users.Update(userObject); await _databaseContext.SaveChangesAsync(); return(RedirectToAction("UserProfile", "Users", new { area = "Social", userId })); }
public async Task <IActionResult> EditProfile(string phone, string fullname, string address) { HttpClient client = new HttpClient(); string token = HttpContext.Session.GetString("userToken"); client.DefaultRequestHeaders.Add("Authorization", "Bearer " + token); var model = new EditUserProfileModel() { FullName = fullname, PhoneNumber = phone, Address = address }; var content = _responseAPI.GetContent <EditUserProfileModel>(model); HttpResponseMessage rs = await client.PutAsync(_responseAPI.APIHost + "api/Account/Information", content); if (rs.IsSuccessStatusCode) { TempData["Notify"] = "Edit Profile Successfully!"; return(RedirectToAction("Index", "User")); } else { return(RedirectToAction("Index", "User")); } }