public ActionResult EditSuatChieu(string id, suat_chieu _suatchieu)
        {
            if (!AuthCheck("admin"))
            {
                return(RedirectToAction("Index"));
            }
            try
            {
                phim _phim = new phim();
                _phim = db.phim.Where(s => s.id == _suatchieu.phim_id).FirstOrDefault();

                if (_suatchieu.ngay_chieu < _phim.ngay_cong_chieu)
                {
                    ViewBag.Error = "Error Date";
                    return(View("~/Views/QLHome/Error.cshtml"));
                }

                TimeSpan time      = (TimeSpan)_suatchieu.gio_bat_dau;
                TimeSpan thoiLuong = TimeSpan.FromMinutes(Convert.ToDouble(_phim.thoi_luong));
                TimeSpan t         = time.Add(thoiLuong);
                if (t.Days > 0)
                {
                    t = t.Subtract(TimeSpan.FromDays(t.Days));
                }
                _suatchieu.gio_ket_thuc    = t;
                db.Entry(_suatchieu).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("QLSuatChieu"));
            }
            catch (Exception e)
            {
                ViewBag.Error = e.ToString();
                return(View("~/Views/QLHome/Error.cshtml"));
            }
        }
        public ActionResult EditPhim(string id)
        {
            if (!AuthCheck("admin"))
            {
                return(RedirectToAction("Index", "QLHome"));
            }
            var loaiphimList = db.loai_phim.ToList();

            ViewBag.LoaiPhimList  = new SelectList(loaiphimList, "id", "ten");
            ViewBag.TrangThaiList = new SelectList(new List <SelectListItem> {
                new SelectListItem {
                    Selected = false, Text = "Chưa Chiếu", Value = "Chưa Chiếu"
                },
                new SelectListItem {
                    Selected = false, Text = "Đang Chiếu", Value = "Đang Chiếu"
                },
                new SelectListItem {
                    Selected = false, Text = "Ngưng Chiếu", Value = "Ngưng Chiếu"
                },
            }, "Value", "Text");
            phim _phim = new phim();

            _phim = db.phim.Where(s => s.id.Equals(id)).FirstOrDefault();
            return(View(_phim));
        }
        public ActionResult EditMovie(int?id)
        {
            movieEntities      db         = new movieEntities();
            UnitOfWork         unitOfWork = new UnitOfWork(db);
            phim               a          = unitOfWork.Phim.SearchFor(x => x.id == id).FirstOrDefault();
            EditMovieViewModel viewModel  = new EditMovieViewModel();

            viewModel.ID                = a.id;
            viewModel.TenPhim           = a.tenphim;
            viewModel.GioiThieu         = a.gioithieuphim;
            viewModel.NgayCongChieu     = a.ngaycongchieu;
            viewModel.DaoDien           = a.daodien;
            viewModel.NamSanXuat        = a.namsanxuat;
            viewModel.TongSoTap         = (a.tongsotap ?? 0);
            viewModel.TheLoaiPhims      = unitOfWork.Theloaiphim.GetAll().ToList();
            viewModel.QuocGias          = unitOfWork.Quocgia.GetAll().ToList();
            viewModel.DienViens         = unitOfWork.Dienvien.GetAll().ToList();
            viewModel.UploadFiles       = null;
            viewModel.SelectedTheLoais  = a.phim_theloaiphim.Select(x => x.idtheloaiphim).ToList().ToArray();
            viewModel.SelectedQuocGias  = a.phim_quocgia.Select(x => x.idquocgia).ToList().ToArray();
            viewModel.SelectedDienViens = a.phim_dienvien.Select(x => x.iddienvien).ToList().ToArray();
            viewModel.AnhBia            = a.anhbiaphim;

            return(View(viewModel));
        }
        public ActionResult AddMovie(AddMovieViewModel movie)
        {
            movieEntities      db         = new movieEntities();
            UnitOfWork         unitOfWork = new UnitOfWork(db);
            HttpPostedFileBase file       = movie.UploadFiles[0];
            string             fileName   = Path.GetFileName(file.FileName);
            string             path       = Path.Combine(Server.MapPath("~/Uploads"), fileName);

            // insert phim entity
            phim newPhim = new phim
            {
                tenphim       = movie.TenPhim,
                gioithieuphim = movie.GioiThieu,
                ngaycongchieu = movie.NgayCongChieu,
                daodien       = movie.DaoDien,
                namsanxuat    = movie.NamSanXuat,
                luotxem       = 0,
                danhgiaphim   = 0,
                tongsotap     = movie.TongSoTap,
                anhbiaphim    = fileName
            };

            unitOfWork.Phim.Insert(newPhim);

            // insert theloaiphim
            for (int i = 0; i < movie.SelectedTheLoais.Length; i++)
            {
                unitOfWork.PhimTheloaiphim.Insert(new phim_theloaiphim
                {
                    idphim        = newPhim.id,
                    idtheloaiphim = movie.SelectedTheLoais[i]
                });
            }

            // insert quocgia
            for (int i = 0; i < movie.SelectedQuocGias.Length; i++)
            {
                unitOfWork.PhimQuocgia.Insert(new phim_quocgia
                {
                    idphim    = newPhim.id,
                    idquocgia = movie.SelectedQuocGias[i]
                });
            }

            // insert dienvien
            for (int i = 0; i < movie.SelectedDienViens.Length; i++)
            {
                unitOfWork.PhimDienvien.Insert(new phim_dienvien
                {
                    idphim     = newPhim.id,
                    iddienvien = movie.SelectedDienViens[i]
                });
            }

            file.SaveAs(path);
            unitOfWork.Save();

            return(RedirectToAction("AddMovie"));
        }
 public ActionResult EditPhim(string id, phim phim)
 {
     if (!AuthCheck("admin"))
     {
         return(RedirectToAction("Index", "QLHome"));
     }
     db.Entry(phim).State = System.Data.Entity.EntityState.Modified;
     db.SaveChanges();
     return(RedirectToAction("QLPhim"));
 }
        public ActionResult UploadMovie(int?id)
        {
            movieEntities        db           = new movieEntities();
            UnitOfWork           unitOfWork   = new UnitOfWork(db);
            phim                 a            = unitOfWork.Phim.SearchFor(x => x.id == id).FirstOrDefault();
            List <phimitem>      phimItemList = unitOfWork.Phimitem.SearchFor(x => x.idphim == a.id).ToList();
            UploadMovieViewModel viewModel    = new UploadMovieViewModel();

            viewModel.IdPhim    = a.id;
            viewModel.TenPhim   = a.tenphim;
            viewModel.TongSoTap = phimItemList.Count;
            if (phimItemList.Count > 0)
            {
                viewModel.TenTapPhimGanDayNhat = phimItemList[phimItemList.Count - 1].tentapphim;
            }

            return(View(viewModel));
        }
        public ActionResult DeleteMovie(int?id)
        {
            movieEntities           db              = new movieEntities();
            UnitOfWork              unitOfWork      = new UnitOfWork(db);
            phim                    phim            = unitOfWork.Phim.SearchFor(x => x.id == id).FirstOrDefault();
            List <phim_theloaiphim> theLoaiPhimList = phim.phim_theloaiphim.ToList();
            List <phim_quocgia>     quocGiaList     = phim.phim_quocgia.ToList();
            List <phim_dienvien>    dienVienList    = phim.phim_dienvien.ToList();
            List <phimitem>         phimItemList    = phim.phimitems.ToList();


            // delete phim entity
            unitOfWork.Phim.Delete(phim);

            // delete theloaiphim entity
            for (int i = 0; i < theLoaiPhimList.Count; i++)
            {
                unitOfWork.PhimTheloaiphim.Delete(theLoaiPhimList[i]);
            }

            // delete quocgia entity
            for (int i = 0; i < quocGiaList.Count; i++)
            {
                unitOfWork.PhimQuocgia.Delete(quocGiaList[i]);
            }

            // delete dienvien entity
            for (int i = 0; i < dienVienList.Count; i++)
            {
                unitOfWork.PhimDienvien.Delete(dienVienList[i]);
            }

            // delete itemphim entity
            for (int i = 0; i < phimItemList.Count; i++)
            {
                unitOfWork.Phimitem.Delete(phimItemList[i]);
            }

            // save
            unitOfWork.Save();

            return(RedirectToAction("MovieList"));
        }
 public ActionResult AddPhim(phim _phim)
 {
     if (!AuthCheck("admin"))
     {
         return(RedirectToAction("Index", "QLHome"));
     }
     try
     {
         _phim.da_xoa = false;
         db.phim.Add(_phim);
         db.SaveChanges();
         return(RedirectToAction("QLPhim"));
     }
     catch (Exception e)
     {
         ViewBag.Error = e.ToString();
         return(View("~/Views/QLHome/Error.cshtml"));
     }
 }
 public ActionResult DeletePhim(string id, phim phim)
 {
     if (!AuthCheck("admin"))
     {
         return(RedirectToAction("Index", "QLHome"));
     }
     try
     {
         phim = db.phim.Where(item => item.id == id).FirstOrDefault();
         db.phim.Remove(phim);
         db.SaveChanges();
         return(RedirectToAction("QLPhim"));
     }
     catch (Exception e)
     {
         ViewBag.Error = e.ToString();
         return(View("~/Views/QLHome/Error.cshtml"));
     }
 }
        public ActionResult Index(string name, string tap)
        {
            if (TempData["model"] == null)
            {
                string     name2      = name.Replace('-', ' ');
                string[]   tap2       = tap.Split('-');
                UnitOfWork unitOfWork = new UnitOfWork(new movieEntities());
                phim       a          = unitOfWork.Phim.SearchFor(x => x.tenphim == name2).FirstOrDefault();
                if (a == null)
                {
                    return(Redirect("/timkiem"));
                }
                else
                {
                    return(Redirect("/Xemphim/IdPhim?id=" + a.id + "&tap=" + tap2[1]));
                }
            }
            WatchMovieViewModel viewModel = TempData["model"] as WatchMovieViewModel;

            return(View(viewModel));
        }
        //
        // GET: /XemPhim/
        public ActionResult IdPhim(int id, int?tap)
        {
            UnitOfWork          unitOfWork = new UnitOfWork(new movieEntities());
            phim                a          = unitOfWork.Phim.SearchFor(x => x.id == id).FirstOrDefault();
            WatchMovieViewModel viewModel  = new WatchMovieViewModel();
            string              url        = string.Empty;

            viewModel.ID            = a.id;
            viewModel.TenPhim       = a.tenphim;
            viewModel.GioiThieu     = a.gioithieuphim;
            viewModel.NgayCongChieu = a.ngaycongchieu;
            viewModel.DaoDien       = a.daodien;
            viewModel.NamSanXuat    = a.namsanxuat;
            viewModel.TheLoaiPhims  = unitOfWork.Theloaiphim.GetAll().ToList();
            viewModel.QuocGias      = unitOfWork.Quocgia.GetAll().ToList();
            viewModel.PhimItems     = a.phimitems.OrderBy(x => x.tap).ToList();

            if (tap == null)
            {
                viewModel.PhimItemSelected = 0;
                url = a.tenphim.Replace(' ', '-') + "/Tap-1";
            }
            else
            {
                viewModel.PhimItemSelected = viewModel.PhimItems.FindIndex(delegate(phimitem myPhimItem)
                {
                    return(myPhimItem.tap.Equals(tap));
                });
                url = a.tenphim.Replace(' ', '-') + "/Tap-" + tap;
            }



            TempData["model"] = viewModel;



            return(Redirect("/XemPhim/" + url));
        }
        public ActionResult EditMovie(EditMovieViewModel movie)
        {
            UnitOfWork         unitOfWork = new UnitOfWork(new movieEntities());
            HttpPostedFileBase file       = null;
            string             fileName   = "";
            string             path       = "";

            if (movie.UploadFiles[0] != null)
            {
                file     = movie.UploadFiles[0];
                fileName = Path.GetFileName(file.FileName);
                path     = Path.Combine(Server.MapPath("~/Uploads"), fileName);
            }
            phim phim = unitOfWork.Phim.SearchFor(x => x.id == movie.ID).FirstOrDefault();
            List <phim_theloaiphim> theLoaiPhimList = phim.phim_theloaiphim.ToList();
            List <phim_quocgia>     quocGiaList     = phim.phim_quocgia.ToList();
            List <phim_dienvien>    dienVienList    = phim.phim_dienvien.ToList();

            if (phim != null)
            {
                // update phim entity
                phim.tenphim       = movie.TenPhim;
                phim.gioithieuphim = movie.GioiThieu;
                phim.ngaycongchieu = movie.NgayCongChieu;
                phim.daodien       = movie.DaoDien;
                phim.namsanxuat    = movie.NamSanXuat;
                phim.tongsotap     = movie.TongSoTap;
                if (file != null)
                {
                    phim.anhbiaphim = fileName;
                }

                //update theloaiphim entity
                for (int i = 0; i < theLoaiPhimList.Count; i++)
                {
                    unitOfWork.PhimTheloaiphim.Delete(theLoaiPhimList[i]);
                }
                for (int i = 0; i < movie.SelectedTheLoais.Length; i++)
                {
                    unitOfWork.PhimTheloaiphim.Insert(new phim_theloaiphim
                    {
                        idphim        = movie.ID,
                        idtheloaiphim = movie.SelectedTheLoais[i]
                    });
                }

                // update quocgia entity
                for (int i = 0; i < quocGiaList.Count; i++)
                {
                    unitOfWork.PhimQuocgia.Delete(quocGiaList[i]);
                }
                for (int i = 0; i < movie.SelectedQuocGias.Length; i++)
                {
                    unitOfWork.PhimQuocgia.Insert(new phim_quocgia
                    {
                        idphim    = movie.ID,
                        idquocgia = movie.SelectedQuocGias[i]
                    });
                }

                // update dienvien entity
                for (int i = 0; i < dienVienList.Count; i++)
                {
                    unitOfWork.PhimDienvien.Delete(dienVienList[i]);
                }
                for (int i = 0; i < movie.SelectedDienViens.Length; i++)
                {
                    unitOfWork.PhimDienvien.Insert(new phim_dienvien
                    {
                        idphim     = movie.ID,
                        iddienvien = movie.SelectedDienViens[i]
                    });
                }

                if (file != null)
                {
                    file.SaveAs(path);
                }
                unitOfWork.Save();
            }

            return(RedirectToAction("MovieList"));
        }