コード例 #1
0
        public async Task <IActionResult> Create(DoAnForCreateDto doAn)
        {
            try
            {
                var result = await _repo.Create(doAn);

                return(StatusCode(201, new SuccessResponseDto
                {
                    Message = "Tạo " + _entityName + " mới thành công!",
                    Result = new SuccessResponseResultWithSingleDataDto
                    {
                        Data = result
                    }
                }));
            }
            catch (Exception e)
            {
                return(StatusCode(500, new FailedResponseDto
                {
                    Message = "Tạo " + _entityName + " mới thất bại!",
                    Result = new FailedResponseResultDto
                    {
                        Errors = e
                    }
                }));
            }
        }
コード例 #2
0
ファイル: DoAnRepository.cs プロジェクト: MariettaEcseri/GTMS
        public async Task <DoAn> Create(DoAnForCreateDto doAn)
        {
            var danhSachDoAn = await _context.DanhSachDoAn.OrderByDescending(x => x.MaDoAn).FirstOrDefaultAsync();

            var maDoAn = 0;

            if (danhSachDoAn == null)
            {
                maDoAn = 0;
            }
            else
            {
                maDoAn = danhSachDoAn.MaDoAn + 1;
            }

            var newDoAn = new DoAn
            {
                MaDoAn           = maDoAn,
                TenDoAn          = doAn.TenDoAn,
                MoTa             = doAn.MoTa,
                MaHuongNghienCuu = doAn.MaHuongNghienCuu,
                LienKetTaiDoAn   = doAn.LienKetTaiDoAn,
                ThoiGianBaoCao   = doAn.ThoiGianBaoCao,
                MaHocKy          = doAn.MaHocKy,
                DiemTongKet      = 8,
                NhanXetChung     = doAn.NhanXetChung,
                DiaDiemBaoCao    = doAn.DiaDiemBaoCao,
                ThoiGianTao      = DateTime.Now,
                ThoiGianCapNhat  = DateTime.Now,
                TrangThai        = 1
            };

            await _context.DanhSachDoAn.AddAsync(newDoAn);

            await _context.SaveChangesAsync();

            // Hướng dẫn đồ án
            for (int i = 0; i < doAn.HuongDanDoAn.Count; i++)
            {
                var record = new HuongDanDoAn
                {
                    MaDoAn      = maDoAn,
                    MaGiangVien = doAn.HuongDanDoAn.ElementAt(i).MaGiangVien,
                    NhanXet     = doAn.HuongDanDoAn.ElementAt(i).NhanXet
                };

                await _context.DanhSachHuongDanDoAn.AddAsync(record);

                await _context.SaveChangesAsync();
            }

            // Phản biện đồ án
            for (int i = 0; i < doAn.PhanBienDoAn.Count; i++)
            {
                var record = new PhanBienDoAn
                {
                    MaDoAn      = maDoAn,
                    MaGiangVien = doAn.PhanBienDoAn.ElementAt(i).MaGiangVien,
                    NhanXet     = doAn.PhanBienDoAn.ElementAt(i).NhanXet
                };

                await _context.DanhSachPhanBienDoAn.AddAsync(record);

                await _context.SaveChangesAsync();
            }

            // Hội đồng bảo vệ
            for (int i = 0; i < doAn.BaoVeDoAn.Count; i++)
            {
                var record = new ThanhVienHDBV
                {
                    MaDoAn      = maDoAn,
                    MaGiangVien = doAn.BaoVeDoAn.ElementAt(i).MaGiangVien,
                    ChucVu      = doAn.BaoVeDoAn.ElementAt(i).ChucVu
                };

                await _context.DanhSachThanhVienHDBV.AddAsync(record);

                await _context.SaveChangesAsync();
            }

            // Điểm đồ án
            for (int i = 0; i < doAn.DiemDoAn.Count; i++)
            {
                var record = new DiemDoAn
                {
                    MaDoAn      = maDoAn,
                    MaGiangVien = doAn.DiemDoAn.ElementAt(i).MaGiangVien,
                    Diem        = doAn.DiemDoAn.ElementAt(i).Diem,
                    HeSo        = doAn.DiemDoAn.ElementAt(i).HeSo
                };

                await _context.DanhSachDiemDoAn.AddAsync(record);

                await _context.SaveChangesAsync();
            }

            // Thực hiện đồ án
            for (int i = 0; i < doAn.ThucHienDoAn.Count; i++)
            {
                var oldRecord        = _context.DanhSachSinhVien.AsNoTracking().FirstOrDefault(x => x.MaSinhVien == doAn.ThucHienDoAn.ElementAt(i));
                var sinhVienToUpdate = new SinhVien
                {
                    MaSinhVien      = doAn.ThucHienDoAn.ElementAt(i),
                    HoVaTen         = oldRecord.HoVaTen,
                    MaLop           = oldRecord.MaLop,
                    GioiTinh        = oldRecord.GioiTinh,
                    NgaySinh        = oldRecord.NgaySinh,
                    Email           = oldRecord.Email,
                    QueQuan         = oldRecord.QueQuan,
                    DiaChi          = oldRecord.DiaChi,
                    SoDienThoai     = oldRecord.SoDienThoai,
                    ThoiGianTao     = oldRecord.ThoiGianTao,
                    ThoiGianCapNhat = DateTime.Now,
                    TrangThai       = oldRecord.TrangThai,
                    MaDoAn          = maDoAn
                };

                _context.DanhSachSinhVien.Update(sinhVienToUpdate);
                await _context.SaveChangesAsync();
            }

            return(newDoAn);
        }