public async Task <IActionResult> Update(string id, [FromBody] GiangVienUpdateRequest request) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var affectedResult = await _giangVienService.Update(id, request); if (affectedResult == 0) { return(BadRequest()); } return(Ok()); }
public async Task <bool> Update(string id, GiangVienUpdateRequest 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/giangviens/{id}", httpContent); return(response.IsSuccessStatusCode); }
public async Task <IActionResult> Edit(string id, GiangVienUpdateRequest request) { if (!ModelState.IsValid) { return(View()); } var result = await _giangVienApiClient.Update(id, request); if (result) { TempData["result"] = "Cập nhật thành công"; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Cập nhật không thành công"); return(View(request)); }
public async Task <IActionResult> Edit(string id) { var giangVien = await _giangVienApiClient.GetById(id); if (giangVien != null) { var updateRequest = new GiangVienUpdateRequest() { Ho = giangVien.Ho, Ten = giangVien.Ten, DiaChi = giangVien.DiaChi, Email = giangVien.Email, SoDienThoai = giangVien.SoDienThoai, GioiTinh = giangVien.GioiTinh, NgaySinh = giangVien.NgaySinh, IsActive = giangVien.IsActive }; return(View(updateRequest)); } return(RedirectToAction("Error", "Home")); }
public async Task <int> Update(string id, GiangVienUpdateRequest request) { var giangVien = await _context.GiangViens.FindAsync(id); if (giangVien == null) { throw new QuanLySinhVien_Exceptions($"Không thể tìm thấy: {id}"); } giangVien.Ho = request.Ho; giangVien.Ten = request.Ten; giangVien.HoTen = request.Ho + " " + request.Ten; giangVien.DiaChi = request.DiaChi; giangVien.Email = request.Email; giangVien.SoDienThoai = request.SoDienThoai; giangVien.GioiTinh = request.GioiTinh; giangVien.NgaySinh = request.NgaySinh; giangVien.IsActive = request.IsActive; return(await _context.SaveChangesAsync()); }