コード例 #1
0
        public async Task <Response <CaThiResponse> > GetCaThi(long id)
        {
            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" }
                       }
            }
            ;

            var lopHoc = await _lopHocRepo.GetLopHocById(caThi.IdLopHoc);

            var deThi = await _deThiRepo.GetDeThiById(caThi.IdDeThi);

            var dsIdCauHoi = _deThiRepo.GetDsIdCauHoi(deThi.Id);
            var dsCauHoi   = await _cauHoiRepo.GetMultipleCauHoiById(dsIdCauHoi);

            var deThiResponse = new DeThiResponse(deThi, dsCauHoi);
            var giamThi       = await _taiKhoanRepo.GetTaiKhoanById(caThi.IdGiamThi);

            var caThiResponse = new CaThiResponse(caThi, lopHoc, deThiResponse, giamThi);

            return(new Response <CaThiResponse>
            {
                StatusCode = 200,
                Success = true,
                Data = caThiResponse
            });
        }
    }
コード例 #2
0
        public async Task <Response <DeThiResponse> > TaoDeThi(long idHocPhan, TaoDeThiRequest request)
        {
            var hocPhan = await _hocPhanRepo.GetHocPhanById(idHocPhan);

            if (hocPhan == null)
            {
                return new Response <DeThiResponse>
                       {
                           StatusCode = 400,
                           Success    = false,
                           Errors     = new[] { "Không tìm thấy học phần" }
                       }
            }
            ;

            var deThi = new DeThi
            {
                TenDeThi  = request.TenDeThi,
                DeThiThu  = request.DeThiThu,
                SanSang   = false,
                IdHocPhan = idHocPhan,
            };

            deThi.DsCauHoi = new List <ChiTietDeThi>();

            foreach (var idCauHoi in request.DsIdCauHoi)
            {
                deThi.DsCauHoi.Add(new ChiTietDeThi {
                    IdCauHoi = idCauHoi
                });
            }

            var newDeThi = await _deThiRepo.CreateDeThi(deThi);

            var dsIdCauHoi = _deThiRepo.GetDsIdCauHoi(deThi.Id);
            var dsCauHoi   = await _cauHoiRepo.GetMultipleCauHoiById(dsIdCauHoi);

            var deThiResponse = new DeThiResponse(newDeThi, dsCauHoi);

            return(new Response <DeThiResponse>
            {
                StatusCode = 201,
                Success = true,
                Data = deThiResponse
            });
        }
    }
コード例 #3
0
        public async Task <Response <DeThiResponse> > CapNhatDeThi(long id, CapNhatDeThiRequest request)
        {
            var deThi = await _deThiRepo.GetDeThiById(id);

            if (deThi == null)
            {
                return new Response <DeThiResponse>
                       {
                           StatusCode = 400,
                           Success    = false,
                           Errors     = new[] { "Không tìm thấy đề thi" }
                       }
            }
            ;

            deThi.TenDeThi = request.TenDeThi;
            deThi.SanSang  = request.SanSang;

            deThi.DsCauHoi = new List <ChiTietDeThi>();

            foreach (var idCauHoi in request.DsIdCauHoi)
            {
                deThi.DsCauHoi.Add(new ChiTietDeThi
                {
                    IdDeThi  = deThi.Id,
                    IdCauHoi = idCauHoi
                });
            }

            var updatedDeThi = await _deThiRepo.UpdateDethi(deThi);

            var dsIdCauHoi = _deThiRepo.GetDsIdCauHoi(deThi.Id);
            var dsCauHoi   = await _cauHoiRepo.GetMultipleCauHoiById(dsIdCauHoi);

            var deThiResponse = new DeThiResponse(updatedDeThi, dsCauHoi);

            return(new Response <DeThiResponse>
            {
                StatusCode = 200,
                Success = true,
                Data = deThiResponse
            });
        }
    }
コード例 #4
0
        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
            });
        }
    }
コード例 #5
0
        public async Task <Response <List <CaThiResponse> > > GetDsCaThi(long idHocPhan)
        {
            var hocPhan = await _hocPhanRepo.GetHocPhanById(idHocPhan);

            if (hocPhan == null)
            {
                return new Response <List <CaThiResponse> >
                       {
                           StatusCode = 400,
                           Success    = false,
                           Errors     = new[] { "Không tìm thấy học phần" }
                       }
            }
            ;

            var dsCaThi         = _caThiRepo.GetAll(idHocPhan);
            var dsCaThiResponse = new List <CaThiResponse>();

            foreach (var caThi in dsCaThi)
            {
                var lopHoc = await _lopHocRepo.GetLopHocById(caThi.IdLopHoc);

                var deThi = await _deThiRepo.GetDeThiById(caThi.IdDeThi);

                var dsIdCauHoi = _deThiRepo.GetDsIdCauHoi(deThi.Id);
                var dsCauHoi   = await _cauHoiRepo.GetMultipleCauHoiById(dsIdCauHoi);

                var deThiResponse = new DeThiResponse(deThi, dsCauHoi);
                var giamThi       = await _taiKhoanRepo.GetTaiKhoanById(caThi.IdGiamThi);

                var caThiResponse = new CaThiResponse(caThi, lopHoc, deThiResponse, giamThi);
                dsCaThiResponse.Add(caThiResponse);
            }

            return(new Response <List <CaThiResponse> >
            {
                StatusCode = 200,
                Success = true,
                Data = dsCaThiResponse
            });
        }
    }
コード例 #6
0
ファイル: TaoCaThi.cs プロジェクト: lnnduy/do-an-chuyen-nganh
        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
            });
        }
    }
コード例 #7
0
        public async Task <Response <CaThiResponse> > KetThucCaThi(long idTaiKhoan, long id)
        {
            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" }
                       }
            }
            ;

            if (caThi.IdGiamThi != idTaiKhoan)
            {
                return new Response <CaThiResponse>
                       {
                           StatusCode = 403,
                           Success    = false,
                           Errors     = new[] { "Không có quyền thực hiện thao tác. Giám thị được chỉ định mới có thể thực hiện thao tác này" }
                       }
            }
            ;

            if (caThi.TrangThai != TrangThaiCaThi.DaBatDau && caThi.TrangThai != TrangThaiCaThi.DaKetThuc)
            {
                return new Response <CaThiResponse>
                       {
                           StatusCode = 403,
                           Success    = false,
                           Errors     = new[] { "Ca thi chưa bắt đầu" }
                       }
            }
            ;

            if (caThi.TrangThai == TrangThaiCaThi.DaKetThuc)
            {
                return new Response <CaThiResponse>
                       {
                           StatusCode = 403,
                           Success    = false,
                           Errors     = new[] { "Ca thi đã kết thúc" }
                       }
            }
            ;

            caThi.TrangThai = TrangThaiCaThi.DaKetThuc;

            await _caThiRepo.UpdateCaThi(caThi);

            var lopHoc = await _lopHocRepo.GetLopHocById(caThi.IdLopHoc);

            var deThi = await _deThiRepo.GetDeThiById(caThi.IdDeThi);

            var dsIdCauHoi = _deThiRepo.GetDsIdCauHoi(deThi.Id);
            var dsCauHoi   = await _cauHoiRepo.GetMultipleCauHoiById(dsIdCauHoi);

            var deThiResponse = new DeThiResponse(deThi, dsCauHoi);
            var giamThi       = await _taiKhoanRepo.GetTaiKhoanById(caThi.IdGiamThi);

            var caThiResponse = new CaThiResponse(caThi, lopHoc, deThiResponse, giamThi);

            return(new Response <CaThiResponse>
            {
                StatusCode = 200,
                Success = true,
                Data = caThiResponse
            });
        }
    }
}
コード例 #8
0
        public async Task <Response <CaThiResponse> > BatDauCaThi(long idTaiKhoan, long id, long ticks)
        {
            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" }
                       }
            }
            ;

            if (caThi.IdGiamThi != idTaiKhoan)
            {
                return new Response <CaThiResponse>
                       {
                           StatusCode = 403,
                           Success    = false,
                           Errors     = new[] { "Không có quyền thực hiện thao tác. Giám thị được chỉ định mới có thể thực hiện thao tác này" }
                       }
            }
            ;

            if (caThi.TrangThai == TrangThaiCaThi.DaBatDau)
            {
                return new Response <CaThiResponse>
                       {
                           StatusCode = 403,
                           Success    = false,
                           Errors     = new[] { "Ca thi đã bắt đầu" }
                       }
            }
            ;

            var random  = new Random();
            var maBaoVe = random.Next(100000, 999999);

            caThi.MaBaoVe        = maBaoVe.ToString();
            caThi.TrangThai      = TrangThaiCaThi.DaBatDau;
            caThi.ThoiGianBatDau = ticks;

            await _caThiRepo.UpdateCaThi(caThi);

            var lopHoc = await _lopHocRepo.GetLopHocById(caThi.IdLopHoc);

            var deThi = await _deThiRepo.GetDeThiById(caThi.IdDeThi);

            var dsIdCauHoi = _deThiRepo.GetDsIdCauHoi(deThi.Id);
            var dsCauHoi   = await _cauHoiRepo.GetMultipleCauHoiById(dsIdCauHoi);

            var deThiResponse = new DeThiResponse(deThi, dsCauHoi);
            var giamThi       = await _taiKhoanRepo.GetTaiKhoanById(caThi.IdGiamThi);

            var caThiResponse = new CaThiResponse(caThi, lopHoc, deThiResponse, giamThi);

            return(new Response <CaThiResponse>
            {
                StatusCode = 200,
                Success = true,
                Data = caThiResponse
            });
        }
    }
}