public int Insert(Bang_DK_DeTai entity)
        {
            //var dao2 = new NhomDaTtDao();
            //var dao3 = new GiangVienDao();
            //var dao4 = new LoaiDaDao();

            db.Bang_DK_DeTai.Add(entity);
            db.SaveChanges();
            return(entity.MaDetai);

            //if (manhom == null)
            //{
            //    return -2;
            //}
            //else
            //{
            //    var magv = dao2.TimTheoMa(manhom.MaNhom);
            //    int maloai = magv.MaLoaiDA;
            //    var maloaida = dao4.GetById(maloai);
            //    int ma = maloaida.MaLoaiDA;
            //    entity.MaLoaiDA = ma;

            //    ThongTinNhom kt1 = db.ThongTinNhoms.SingleOrDefault(x => x.ThanhVien2 == entity.MaDetai && x.Bang_DK_DeTai.MaLoaiDA == maloaida.MaLoaiDA);
            //    ThongTinNhom kt2 = db.ThongTinNhoms.SingleOrDefault(x => x.ThanhVien3 == entity.MaDetai && x.Bang_DK_DeTai.MaLoaiDA == maloaida.MaLoaiDA);
            //    ThongTinNhom kt3 = db.ThongTinNhoms.SingleOrDefault(x => x.NguoiDangKy == entity.MaDetai && x.Bang_DK_DeTai.MaLoaiDA == maloaida.MaLoaiDA);

            //    if (kt1 != null || kt2 != null || kt3 != null)
            //    {
            //        return -1;
            //    }
            //    else
            //    {
            //        entity.MaDetai = 0;

            //    }
            //}
        }
        public int Insert(ThongTinNhom entity)
        {
            var dao  = new NhomDaTtDao();
            var magv = dao.TimMagvTheoMaNhom(entity.MaNhom);
            var mada = magv.MaLoaiDA;

            ////kiem tra ma nhom tung thanh vien
            if (entity.SoLuongThanhVien == 1)
            {
                db.ThongTinNhoms.Add(entity);
                db.SaveChanges();
                return(entity.STT);
            }

            else
            {
                if (entity.SoLuongThanhVien == 2)
                {
                    var nhomtv2 = dao.TimMagv(entity.ThanhVien2, mada);
                    var ttb     = nhomtv2.MaGV;

                    if (magv.MaGV != ttb)
                    {
                        return(-1);
                    }
                    else
                    {
                        ThongTinNhom bien1 = db.ThongTinNhoms.SingleOrDefault(x => x.ThanhVien2 == entity.ThanhVien2);
                        ThongTinNhom bien2 = db.ThongTinNhoms.SingleOrDefault(x => x.ThanhVien3 == entity.ThanhVien2);
                        ThongTinNhom bien3 = db.ThongTinNhoms.SingleOrDefault(x => x.NguoiDangKy == entity.ThanhVien2);


                        if (bien1 != null || bien2 != null)
                        {
                            return(0);
                        }
                        else
                        {
                            db.ThongTinNhoms.Add(entity);
                            db.SaveChanges();
                            return(entity.STT);
                        }
                    }
                }
                else
                {
                    var nhomtv2 = dao.TimMagv(entity.ThanhVien2, mada);
                    var nhomtv3 = dao.TimMagv(entity.ThanhVien3, mada);

                    if (magv.MaGV != nhomtv2.MaGV || magv.MaGV != nhomtv3.MaGV)
                    {
                        return(-1);
                    }
                    else
                    {
                        ThongTinNhom bien1 = db.ThongTinNhoms.SingleOrDefault(x => x.ThanhVien2 == entity.ThanhVien2);
                        ThongTinNhom bien2 = db.ThongTinNhoms.SingleOrDefault(x => x.ThanhVien2 == entity.ThanhVien3);
                        ThongTinNhom bien3 = db.ThongTinNhoms.SingleOrDefault(x => x.ThanhVien3 == entity.ThanhVien2);
                        ThongTinNhom bien4 = db.ThongTinNhoms.SingleOrDefault(x => x.ThanhVien3 == entity.ThanhVien3);

                        if (bien1 != null || bien2 != null || bien3 != null || bien4 != null)
                        {
                            return(0);
                        }
                        else
                        {
                            db.ThongTinNhoms.Add(entity);
                            db.SaveChanges();
                            return(entity.STT);
                        }
                    }
                }
            }
        }
        //==============================================

        public int Insert(Nhom_DA_TT entity)
        {
            db.Nhom_DA_TT.Add(entity);
            db.SaveChanges();
            return(entity.MaNhom);
        }
Exemplo n.º 4
0
 //phương thức thêm mới sinh viên
 public int Insert(SinhVien entity)
 {
     db.SinhViens.Add(entity);
     db.SaveChanges();
     return(entity.MaSV);
 }
Exemplo n.º 5
0
        //==============================================

        public int Insert(GiangVien entity)
        {
            db.GiangViens.Add(entity);
            db.SaveChanges();
            return(1);
        }