Esempio n. 1
0
        public bool addNewFilmd(Phim p)
        {
            try
            {
                if (p.MS_NuocSX == null)
                {
                    DanhMucNuocSanXuat diffCountry = db.DanhMucNuocSanXuat.Where(x => x.TenNuoc.Equals("Khác")).FirstOrDefault();
                    p.MS_NuocSX = diffCountry.MaSo;
                }
                if (p.MS_TheLoai == null)
                {
                    DanhMucTheLoai diffGenre = db.DanhMucTheLoai.Where(x => x.TenTheLoai.Equals("Khác")).FirstOrDefault();
                    p.MS_TheLoai = diffGenre.MaSo;
                }

                db.Phim.Add(p);



                db.SaveChanges();
                return(true);
            }
            catch (Exception e)
            {
                Debug.Print(e.Message);
                return(false);
            }
        }
Esempio n. 2
0
        public bool deleteGenre(int id)
        {
            try
            {
                DanhMucTheLoai genre = db.DanhMucTheLoai.Find(id);
                genre.TinhTrang = false;

                //Đổi thể loại của các bộ phim liên quan thành "khác"

                List <DanhMucTheLoai> diffGenre = db.DanhMucTheLoai.Where(x => x.TenTheLoai.Equals("Khác")).ToList();

                List <Phim> lstFilms = db.Phim.Where(x => x.MS_TheLoai == id).ToList();
                foreach (Phim item in lstFilms)
                {
                    item.MS_TheLoai = diffGenre[0].MaSo;
                }


                db.SaveChanges();



                return(true);
            }
            catch (Exception e)
            {
                Debug.Print(e.Message);
                return(false);
            }
        }
Esempio n. 3
0
        //Thống kê phần trăm thể loại phim được quan tâm nhiều nhất (Dựa vào số lượng bài nhận xét của từng thể loại phim)
        public Dictionary <string, int> statisticPhimForGenre()
        {
            try
            {
                Dictionary <string, int> result = new Dictionary <string, int>();


                Dictionary <int, int> total         = new Dictionary <int, int>();
                List <BaiNhanXet>     lstBaiNhanXet = db.BaiNhanXet.ToList();


                FilmBus filmBus = new FilmBus();
                foreach (BaiNhanXet baiNhanXet in lstBaiNhanXet)
                {
                    int  MSPhim     = (int)baiNhanXet.MS_Phim;
                    Phim phim       = filmBus.getFilmByID(MSPhim.ToString());
                    int  MS_TheLoai = (int)phim.MS_TheLoai;
                    if (total.ContainsKey(MS_TheLoai))
                    {
                        total[MS_TheLoai]++;
                    }
                    else
                    {
                        total.Add(MS_TheLoai, 1);
                    }
                }
                List <DanhMucTheLoai> lstTheLoai = db.DanhMucTheLoai.Where(x => x.TinhTrang == true).ToList();


                int totalCount = db.BaiNhanXet.ToList().Count();
                foreach (DanhMucTheLoai theLoai in lstTheLoai)
                {
                    DanhMucTheLoai theLoai1 = db.DanhMucTheLoai.Where(x => x.TinhTrang == true && x.MaSo == theLoai.MaSo).FirstOrDefault();

                    if (total.ContainsKey(theLoai.MaSo))
                    {
                        result.Add(theLoai1.TenTheLoai, total[theLoai.MaSo]);
                    }

                    else
                    {
                        result.Add(theLoai1.TenTheLoai, 0);
                    }
                }

                return(result);
            }
            catch (Exception e)
            {
                return(null);
            }
        }
Esempio n. 4
0
 public bool editGenre(int p, string newName)
 {
     try
     {
         DanhMucTheLoai genre = db.DanhMucTheLoai.Find(p);
         genre.TenTheLoai = newName;
         db.SaveChanges();
         return(true);
     }
     catch (Exception e)
     {
         Debug.Print(e.Message);
         return(false);
     }
 }
Esempio n. 5
0
 public bool createNewGenre(string name)
 {
     try
     {
         DanhMucTheLoai genre = new DanhMucTheLoai();
         genre.TenTheLoai = name;
         genre.TinhTrang  = true;
         db.DanhMucTheLoai.Add(genre);
         db.SaveChanges();
         return(true);
     }
     catch (Exception e)
     {
         Debug.Print(e.Message);
         return(false);
     }
 }
Esempio n. 6
0
        public bool createNewGenre(string name)
        {
            try
            {
                DanhMucTheLoai genre = new DanhMucTheLoai();
                genre.TenTheLoai = name;
                genre.TinhTrang = true;
                db.DanhMucTheLoai.Add(genre);
                db.SaveChanges();
                return true;
            }
            catch (Exception e)
            {
                Debug.Print(e.Message);
                return false;
            }

        }