public async Task <HttpResponseMessage> UpdateUserInfor(UpdateInfoRequest updateInfoRequest, string token) { using (var client = new HttpClient()) { client.BaseAddress = new Uri(UriString); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); return(await client.PutAsJsonAsync("UpdateInfo", updateInfoRequest)); } }
public ActionResult <ReadUserDto> updateUserInfo(UpdateInfoRequest update) { try{ CheckId(update.Id); return(_service.updateInfo(update)); }catch (Exception e) { return(NotFound(e.Message)); } }
public ReadUserDto updateInfo(UpdateInfoRequest user) { if (user == null || !isUserExists(user.Id)) { throw new Exception("Not found"); } User u = _userService.GetById(user.Id); if (!BC.Verify(user.OldPassword, u.Password)) { throw new Exception("Wrong Password"); } u.Email = user.Email; u.Gender = user.Gender; u.Name = user.Name; u.CityId = user.CityId; _userService.Update(u); return(new ReadUserDto { Email = user.Email, Name = user.Name, Id = u.Id, Gender = user.Gender, IsAdmin = u.IsAdmin, CityId = user.CityId }); }
public async Task <string> UpdateUserInfor(HttpRequest Request, HttpResponse Response, string name, string email, string pass, string oldpass, int cityID, bool gender) { var cookie = JsonConvert.DeserializeObject <Cookie_Data>(_cookieService.ReadCookie(Request, "user")); UpdateInfoRequest update = new UpdateInfoRequest() { Id = cookie.id, Name = name, Email = email, Password = pass, OldPassword = oldpass, CityId = cityID, Gender = gender, }; var result = await _userRepo.UpdateUserInfor(update, cookie.token); string message = result.Content.ReadAsStringAsync().Result; if (result.IsSuccessStatusCode) { return(""); } else if ((result.StatusCode.ToString() == "Unauthorized")) { await RefreshToken(Response, cookie); cookie = JsonConvert.DeserializeObject <Cookie_Data>(_cookieService.ReadCookie(Request, "user")); result = await _userRepo.UpdateUserInfor(update, cookie.token); message = result.Content.ReadAsStringAsync().Result; return(message); } else { return(message); } }