コード例 #1
0
ファイル: ContentController.cs プロジェクト: fathurxzz/aleqx
        public ActionResult Add(FormCollection form)
        {
            using (var context = new StructureContainer())
            {
                var content = new Content { MainPage = false, ContentLevel = 1 };

                if (!string.IsNullOrEmpty(form["parentId"]))
                {
                    int parentId = Convert.ToInt32(form["parentId"]);
                    var parent = context.Content.Where(c => c.Id == parentId).First();
                    content.Parent = parent;
                    content.ContentLevel = parent.ContentLevel + 1;
                }

                TryUpdateModel(content, new[]
                                            {
                                                "Name",
                                                "Title",
                                                "MenuTitle",
                                                "PageTitle",
                                                "SortOrder",
                                                "SeoDescription",
                                                "SeoKeywords"
                                            });
                content.Text = HttpUtility.HtmlDecode(form["Text"]);
                
                context.AddToContent(content);

                context.SaveChanges();

                return RedirectToAction("Index", "Home", new { id = content.Name, area = "" });
            }
        }
コード例 #2
0
ファイル: HomeController.cs プロジェクト: fathurxzz/aleqx
        public ActionResult Index(string id)
        {

            using (var context = new StructureContainer())
            {
                var menuList = Menu.GetMenuList(id, context);
                ViewBag.MenuList = menuList;


                var content = context.Content.Include("ContentImages")
                    .Include("Parent").Include("Children")
                    .Where(c => c.Name == id)
                    .FirstOrDefault();

                if (content == null)
                    content = context.Content.Include("ContentImages")
                        .Include("Parent").Include("Children")
                        .Where(c => c.MainPage)
                        .First();



                ViewBag.Title = content.Title;
                ViewBag.PageTitle = content.PageTitle;
                ViewBag.SeoDescription = content.SeoDescription;
                ViewBag.SeoKeywords = content.SeoKeywords;
                ViewBag.isHomePage = content.MainPage;
                
                ViewBag.showSubMenu = content.ContentLevel == 2;

                return View(content);
            }
        }
コード例 #3
0
ファイル: ContentController.cs プロジェクト: fathurxzz/aleqx
 public ActionResult Edit(int id)
 {
     using (var context = new StructureContainer())
     {
         var content = context.Content.Where(c => c.Id == id).First();
         return View(content);
     }
 }
コード例 #4
0
ファイル: ContentController.cs プロジェクト: fathurxzz/aleqx
        public ActionResult Edit(Content model, FormCollection form)
        {
            using (var context = new StructureContainer())
            {
                var content = context.Content.Where(c => c.Id == model.Id).First();

                TryUpdateModel(content, new[]
                                            {
                                                "Name",
                                                "Title",
                                                "PageTitle",
                                                "SortOrder",
                                                "SeoDescription",
                                                "SeoKeywords",
                                            });
                content.Text = HttpUtility.HtmlDecode(form["Text"]);


                context.SaveChanges();

                return RedirectToAction("Index", "Home", new { id = content.Name, area = "" });
            }
        }
コード例 #5
0
ファイル: ContentController.cs プロジェクト: fathurxzz/aleqx
        public ActionResult Delete(int id)
        {
            using (var context = new StructureContainer())
            {
                var content = context.Content.Include("ContentImages").First(c => c.Id == id);
                while (content.ContentImages.Any())
                {
                    var image = content.ContentImages.First();
                    if (!string.IsNullOrEmpty(image.ImageSource))
                    {
                        IOHelper.DeleteFile("~/Content/Images", image.ImageSource);
                        IOHelper.DeleteFile("~/ImageCache/galleryThumbnail", image.ImageSource);

                    }
                    context.DeleteObject(image);
                }

                context.DeleteObject(content);

                context.SaveChanges();

                return RedirectToAction("Index", "Home", new {id = "", area = ""});
            }
        }
コード例 #6
0
ファイル: ContentController.cs プロジェクト: fathurxzz/aleqx
        public ActionResult AddImage(int parentId, IEnumerable<HttpPostedFileBase> fileUpload, IList<string> fileTitles)
        {
            using (var context = new StructureContainer())
            {
                var content = context.Content.Where(a => a.Id == parentId).First();


                foreach (var file in fileUpload)
                {

                    if (file == null) continue;

                    string fileName = IOHelper.GetUniqueFileName("~/Content/Images", file.FileName);
                    string filePath = Server.MapPath("~/Content/Images");
                    filePath = Path.Combine(filePath, fileName);
                    file.SaveAs(filePath);

                    content.ContentImages.Add(new ContentImage
                    {
                        ImageSource = fileName,
                    });
                    context.SaveChanges();
                }


                return RedirectToAction("Index", "Home", new { id = content.Name, area = "" });
            }
        }
コード例 #7
0
ファイル: ContentController.cs プロジェクト: fathurxzz/aleqx
 public ActionResult AddImage(int id)
 {
     using (var context = new StructureContainer())
     {
         ViewBag.ContentName = context.Content.First(c => c.Id == id).Name;
         ViewBag.parentId = id;
         return View();
     }
 }