public async Task <IActionResult> TaoCaThi(long idHocPhan, TaoCaThiRequest request) { var claim = User.Claims.FirstOrDefault(c => c.Type == "id"); if (!User.Identity.IsAuthenticated || claim == null) { return(Unauthorized()); } var serviceResult = await _caThiService.TaoCaThi(idHocPhan, request); return(Ok(serviceResult)); }
public async Task <Response <CaThiResponse> > CapNhatCaThi(long id, TaoCaThiRequest request) { var caThi = await _caThiRepo.GetCaThiById(id); if (caThi == null) { return new Response <CaThiResponse> { StatusCode = 400, Success = false, Errors = new[] { "Không tìm thấy ca thi" } } } ; caThi.TenCaThi = request.TenCaThi; caThi.ThoiGianBatDau = request.ThoiGianBatDau; caThi.ThoiGianThi = request.ThoiGianThi; caThi.IdLopHoc = request.IdLopHoc; caThi.IdGiamThi = request.IdGiamThi; caThi.IdDeThi = request.IdDeThi; var updatedCaThi = await _caThiRepo.UpdateCaThi(caThi); var lopHoc = await _lopHocRepo.GetLopHocById(updatedCaThi.IdLopHoc); var deThi = await _deThiRepo.GetDeThiById(updatedCaThi.IdDeThi); var dsIdCauHoi = _deThiRepo.GetDsIdCauHoi(deThi.Id); var dsCauHoi = await _cauHoiRepo.GetMultipleCauHoiById(dsIdCauHoi); var deThiResponse = new DeThiResponse(deThi, dsCauHoi); var giamThi = await _taiKhoanRepo.GetTaiKhoanById(updatedCaThi.IdGiamThi); var caThiResponse = new CaThiResponse(updatedCaThi, lopHoc, deThiResponse, giamThi); return(new Response <CaThiResponse> { StatusCode = 200, Success = true, Data = caThiResponse }); } }
public async Task <Response <CaThiResponse> > TaoCaThi(long idHocPhan, TaoCaThiRequest request) { var hocPhan = await _hocPhanRepo.GetHocPhanById(idHocPhan); if (hocPhan == null) { return new Response <CaThiResponse> { StatusCode = 400, Success = false, Errors = new[] { "Không tìm thấy học phần" } } } ; var caThi = new CaThi { TenCaThi = request.TenCaThi, ThoiGianBatDau = request.ThoiGianBatDau, ThoiGianThi = request.ThoiGianThi, TrangThai = TrangThaiCaThi.ChuaBatDau, IdHocPhan = idHocPhan, IdLopHoc = request.IdLopHoc, IdGiamThi = request.IdGiamThi, IdDeThi = request.IdDeThi }; var newCaThi = await _caThiRepo.CreateCaThi(caThi); var lopHoc = await _lopHocRepo.GetLopHocById(newCaThi.IdLopHoc); var deThi = await _deThiRepo.GetDeThiById(newCaThi.IdDeThi); var dsIdCauHoi = _deThiRepo.GetDsIdCauHoi(deThi.Id); var dsCauHoi = await _cauHoiRepo.GetMultipleCauHoiById(dsIdCauHoi); var deThiResponse = new DeThiResponse(deThi, dsCauHoi); var giamThi = await _taiKhoanRepo.GetTaiKhoanById(newCaThi.IdGiamThi); var caThiResponse = new CaThiResponse(newCaThi, lopHoc, deThiResponse, giamThi); var dsSinhVien = _sinhVienRepo.GetAllInLopHoc(lopHoc.Id); foreach (var sinhVien in dsSinhVien) { var thiSinh = new ThiSinh { IdCaThi = newCaThi.Id, IdSinhVien = sinhVien.Id, SoLanDangNhap = 0, TenMay = null, DiaChiIp = null, TrangThaiThi = TrangThaiThi.ChuaThi }; await _thiSinhRepo.CreateThiSinh(thiSinh); } return(new Response <CaThiResponse> { StatusCode = 201, Success = true, Data = caThiResponse }); } }