public async Task <int> Update(int hocky, int namhoc, HocKyNamHocUpdateRequest request) { var hocKyNamHoc = await _context.HocKy_NamHocs.FindAsync(hocky, namhoc); if (hocKyNamHoc == null) { throw new QuanLySinhVien_Exceptions($"Không thể tìm thấy {hocky}, {namhoc}"); } hocKyNamHoc.NgayBatDau = request.NgayBatDau; hocKyNamHoc.NgayKetThuc = request.NgayKetThuc; return(await _context.SaveChangesAsync()); }
public async Task <IActionResult> Update(int hocky, int namhoc, [FromBody] HocKyNamHocUpdateRequest request) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var affectedResult = await _hocKyNamHocService.Update(hocky, namhoc, request); if (affectedResult == 0) { return(BadRequest()); } return(Ok()); }
public async Task <bool> Update(int hocky, int namhoc, HocKyNamHocUpdateRequest 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/hockynamhocs/{hocky}/{namhoc}", httpContent); return(response.IsSuccessStatusCode); }
public async Task <IActionResult> Edit(int hocky, int namhoc) { var hocKyNamHoc = await _hocKyNamHocApiClient.GetById(hocky, namhoc); if (hocKyNamHoc != null) { var updateRequest = new HocKyNamHocUpdateRequest() { HocKy = hocKyNamHoc.HocKy, NamHoc = hocKyNamHoc.NamHoc, NgayBatDau = hocKyNamHoc.NgayBatDau, NgayKetThuc = hocKyNamHoc.NgayKetThuc }; return(View(updateRequest)); } return(RedirectToAction("Error", "Home")); }
public async Task <IActionResult> Edit(int hocky, int namhoc, HocKyNamHocUpdateRequest request) { if (!ModelState.IsValid) { return(View()); } var result = await _hocKyNamHocApiClient.Update(hocky, namhoc, 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)); }