Пример #1
0
        public bool Insert(int matheloai, int maproject)
        {
            ChiTietTruyen ct = new ChiTietTruyen();


            ct.MaTheLoai = matheloai;
            ct.MaProject = maproject;

            data.ChiTietTruyens.Add(ct);
            data.SaveChanges();
            return(true);
        }
Пример #2
0
        public bool Update(int[] text, int maproject)
        {
            var ChiTiet = data.ChiTietTruyens.Where(m => m.MaProject == maproject).ToList();

            //thêm vào
            foreach (int s in text)
            {
                int them      = 0;
                int matheloai = s;
                foreach (var chitiet in ChiTiet)
                {
                    if (chitiet.MaTheLoai == matheloai)
                    {
                        them++;
                    }
                }
                if (them == 0)
                {
                    ChiTietTruyen chitiet1 = new ChiTietTruyen();
                    chitiet1.MaTheLoai = matheloai;
                    chitiet1.MaProject = maproject;
                    data.ChiTietTruyens.Add(chitiet1);
                    data.SaveChanges();
                }
            }
            //
            //Xoá đi
            foreach (var chitiet in ChiTiet)
            {
                int xoa = 0;
                foreach (int s in text)
                {
                    int matheloai = s;
                    if (chitiet.MaTheLoai == matheloai)
                    {
                        xoa++;
                    }
                }
                if (xoa == 0)
                {
                    data.ChiTietTruyens.Remove(chitiet);
                    data.SaveChanges();
                }
            }
            return(true);
        }