public async Task <int> Update(string id, PhongUpdateRequest request) { var phong = await _context.Phongs.FindAsync(id); if (phong == null) { throw new QuanLySinhVien_Exceptions($"Không thể tìm thấy: {id}"); } phong.TenCoSo = request.TenCoSo; return(await _context.SaveChangesAsync()); }
public async Task <IActionResult> Update(string id, [FromBody] PhongUpdateRequest request) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var affectedResult = await _phongService.Update(id, request); if (affectedResult == 0) { return(BadRequest()); } return(Ok()); }
public async Task <bool> Update(string id, PhongUpdateRequest request) { var client = _httpClientFactory.CreateClient(); client.BaseAddress = new Uri(_configuration["BaseAddress"]); var sessions = _httpContextAccessor.HttpContext.Session.GetString("Token"); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", sessions); var json = JsonConvert.SerializeObject(request); var httpContent = new StringContent(json, Encoding.UTF8, "application/json"); var response = await client.PutAsync($"/api/phongs/{id}", httpContent); return(response.IsSuccessStatusCode); }