コード例 #1
0
        public ActionResult HomePageCategories()
        {
            using (SinemaSitesiEntities db = new SinemaSitesiEntities())
            {
                var data1 = db.Category.Select(x => new CategoryHPModel
                {
                    ID         = x.ID,
                    Name       = x.Name,
                    IsHomePage = x.IsHomePage,
                }).OrderBy(x => x.ID).ToList();


                var data2 = db.Category.Select(x => new CategoryHPModel
                {
                    ID         = x.ID,
                    Name       = x.Name,
                    IsHomePage = x.IsHomePage,
                }).OrderBy(x => x.ID).Where(x => x.IsHomePage == true).ToList();

                var model = new AdminHPCategoryModel
                {
                    AvailableCategories = data1,
                    SelectedCategories  = data2
                };

                return(View(model));
            }
        }
コード例 #2
0
        public ActionResult HomePageCategories(AdminHPCategoryModel model)
        {
            using (SinemaSitesiEntities db = new SinemaSitesiEntities())
            {
                var data1 = db.Category.ToList();
                foreach (var item in data1)
                {
                    item.IsHomePage = false;
                    db.SaveChanges();
                }

                foreach (var item in model.Ids)
                {
                    var data = db.Category.Find(item);
                    data.IsHomePage = true;
                    db.SaveChanges();
                }
            }
            return(RedirectToAction("Index", "Admin"));
        }