public async Task <PhanBienDoAn> UpdateById(int maDoAn, string maGiangVien, PhanBienDoAnForUpdateDto phanBienDoAn) { var phanBienDoAnToUpdate = new PhanBienDoAn { MaDoAn = phanBienDoAn.MaDoAn, MaGiangVien = phanBienDoAn.MaGiangVien, ThoiGianCapNhat = DateTime.Now, TrangThai = phanBienDoAn.TrangThai }; _context.DanhSachPhanBienDoAn.Update(phanBienDoAnToUpdate); await _context.SaveChangesAsync(); return(phanBienDoAnToUpdate); }
public async Task <PhanBienDoAn> Create(PhanBienDoAnForCreateDto phanBienDoAn) { var newPhanBienDoAn = new PhanBienDoAn { MaDoAn = phanBienDoAn.MaDoAn, MaGiangVien = phanBienDoAn.MaGiangVien, ThoiGianTao = DateTime.Now, ThoiGianCapNhat = DateTime.Now, TrangThai = 1 }; await _context.DanhSachPhanBienDoAn.AddAsync(newPhanBienDoAn); await _context.SaveChangesAsync(); return(newPhanBienDoAn); }
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); }