Beispiel #1
0
        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 = "" });
            }
        }
Beispiel #2
0
        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 = "" });
            }
        }
Beispiel #3
0
        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 = ""});
            }
        }
Beispiel #4
0
        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 = "" });
            }
        }