Exemplo n.º 1
0
        public async Task <IActionResult> Details(string id)
        {
            var requestDanhSachSinhVien = new DanhSachSinhVienPagingRequest()
            {
                Keyword   = id,
                PageIndex = 1,
                PageSize  = 1000
            };

            var infoLopHocPhan = await _lopHocPhanApiClient.GetById(id);

            var danhSachSinhVien = await _danhSachSinhVienApiClient.GetAllByIdLopHocPhan(requestDanhSachSinhVien);

            if (danhSachSinhVien != null)
            {
                if (TempData["result"] != null)
                {
                    ViewBag.SuccessMessage = TempData["result"];
                }
                ViewBag.infoLopHocPhan = infoLopHocPhan;
                ViewBag.ID_LopHocPhan  = id;

                return(View(danhSachSinhVien));
            }
            return(RedirectToAction("Error", "Home"));
        }
        public async Task <IActionResult> GetAllByIdChuongTrinhDaoTao([FromQuery] DanhSachSinhVienPagingRequest request)
        {
            var results = await _danhSachSinhVienService.GetAllByIdLopHocPhan(request);

            return(Ok(results));
        }
Exemplo n.º 3
0
        public async Task <PagedResult <DanhSachSinhVienViewModel> > GetAllByIdLopHocPhan(DanhSachSinhVienPagingRequest request)
        {
            var query = from dssv in _context.DanhSach_SinhVien_LopHocPhans
                        join sv in _context.SinhViens on dssv.ID_SinhVien equals sv.ID
                        select new { dssv, sv };

            if (!string.IsNullOrEmpty(request.Keyword))
            {
                query = query.Where(x => x.dssv.ID_LopHocPhan.Contains(request.Keyword));
            }

            int totalRow = await query.CountAsync();

            var lopHocPhan = await _context.LopHocPhans.FindAsync(request.Keyword);

            var data = await query.Skip((request.PageIndex - 1) *request.PageSize)
                       .Take(request.PageSize)
                       .Select(x => new DanhSachSinhVienViewModel()
            {
                ID_LopHocPhan = x.dssv.ID_LopHocPhan,
                ID_SinhVien   = x.dssv.ID_SinhVien,
                LopHocPhan    = lopHocPhan,
                SinhVien      = x.sv,
                Diem          = x.dssv.Diem,
                LanThi        = x.dssv.LanThi
            }).ToListAsync();

            var pagedResult = new PagedResult <DanhSachSinhVienViewModel>()
            {
                TotalRecords = totalRow,
                PageIndex    = request.PageIndex,
                PageSize     = request.PageSize,
                Items        = data
            };

            return(pagedResult);
        }
        public async Task <PagedResult <DanhSachSinhVienViewModel> > GetAllByIdLopHocPhan(DanhSachSinhVienPagingRequest request)
        {
            var sessions = _httpContextAccessor
                           .HttpContext
                           .Session
                           .GetString(SystemConstants.AppSettings.Token);

            var client = _httpClientFactory.CreateClient();

            client.BaseAddress = new Uri(_configuration[SystemConstants.AppSettings.BaseAddress]);
            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", sessions);

            var response = await client.GetAsync(
                $"/api/danhsachsinhviens/paging?pageIndex={request.PageIndex}" +
                $"&pageSize={request.PageSize}" +
                $"&keyword={request.Keyword}"
                );

            var body = await response.Content.ReadAsStringAsync();

            var danhSachSinhVien = JsonConvert.DeserializeObject <PagedResult <DanhSachSinhVienViewModel> >(body);

            return(danhSachSinhVien);
        }