public async Task <HuongDanDoAn> UpdateById(string maGiangVien, int maDoAn, HuongDanDoAnForUpdateDto huongDanDoAn) { var huongDanDoAnToUpdate = new HuongDanDoAn { MaGiangVien = maGiangVien, MaDoAn = maDoAn, //Diem = huongDanDoAn.Diem, NhanXet = huongDanDoAn.NhanXet, ThoiGianCapNhat = DateTime.Now, TrangThai = huongDanDoAn.TrangThai }; _context.DanhSachHuongDanDoAn.Update(huongDanDoAnToUpdate); await _context.SaveChangesAsync(); return(huongDanDoAnToUpdate); }
public async Task <HuongDanDoAn> Create(HuongDanDoAnForCreateDto huongDanDoAn) { var newHuongDanDoAn = new HuongDanDoAn { MaDoAn = huongDanDoAn.MaDoAn, MaGiangVien = huongDanDoAn.MaGiangVien, //Diem = huongDanDoAn.Diem, NhanXet = huongDanDoAn.NhanXet, ThoiGianTao = DateTime.Now, ThoiGianCapNhat = DateTime.Now, TrangThai = 1 }; await _context.DanhSachHuongDanDoAn.AddAsync(newHuongDanDoAn); await _context.SaveChangesAsync(); return(newHuongDanDoAn); }
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); }