Ejemplo n.º 1
0
        public async Task <int> Update(string id_LopHocPhan, string id_SinhVien, DanhSachSinhVienUpdateRequest request)
        {
            var record = await _context.DanhSach_SinhVien_LopHocPhans.FindAsync(id_LopHocPhan, id_SinhVien);

            if (record == null)
            {
                throw new QuanLySinhVien_Exceptions($"Không thể tìm thấy");
            }

            record.Diem = request.Diem;

            return(await _context.SaveChangesAsync());
        }
        public async Task <bool> Update(string lophocphan, string sinhvien, DanhSachSinhVienUpdateRequest 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/danhsachsinhviens/{lophocphan}/{sinhvien}", httpContent);

            return(response.IsSuccessStatusCode);
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> DeleteStudent(string lophocphan, string sinhvien)
        {
            var sinhVien = await _danhSachSinhVienApiClient.GetById(lophocphan, sinhvien);

            var lopHocPhan = await _lopHocPhanApiClient.GetById(lophocphan);

            if (sinhVien != null)
            {
                var updateRequest = new DanhSachSinhVienUpdateRequest()
                {
                    ID_SinhVien = sinhVien.ID_SinhVien
                };
                ViewBag.LopHocPhan = lopHocPhan;
                return(View(updateRequest));
            }
            return(RedirectToAction("Error", "Home"));
        }
        public async Task <IActionResult> Update(string id_LopHocPhan, string id_SinhVien, [FromBody] DanhSachSinhVienUpdateRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var affectedResult = await _danhSachSinhVienService.Update(id_LopHocPhan, id_SinhVien, request);

            if (affectedResult == 0)
            {
                return(BadRequest());
            }
            return(Ok());
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> DeleteStudent(string lophocphan, string sinhvien, DanhSachSinhVienUpdateRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            var result = await _danhSachSinhVienApiClient.Delete(lophocphan, sinhvien);

            if (result)
            {
                TempData["result"] = "Xóa thành công";
                return(RedirectToAction("Details", new { id = lophocphan }));
            }

            ModelState.AddModelError("", "Xóa không thành công");
            return(View(request));
        }