Esempio n. 1
0
        public ActionResult Add(int id, FormCollection form)
        {
            using (var context = new ContentStorage())
            {
                var content = new Content();
                var parent = context.Content.Where(c => c.Id == id).First();
                content.Parent = parent;

                string parentName = parent.Name;

                TryUpdateModel(content,
                               new[]
                                   {
                                       "Name", "Title", "PageTitle", "ContentType", "ContentLevel", "Description",
                                       "SortOrder", "SeoDescription", "SeoKeywords"
                                   });


                if (Request.Files["logo"] != null && !string.IsNullOrEmpty(Request.Files["logo"].FileName))
                {
                    string fileName = IOHelper.GetUniqueFileName("~/Content/Photos", Request.Files["logo"].FileName);
                    string filePath = Server.MapPath("~/Content/Photos");
                    filePath = Path.Combine(filePath, fileName);
                    Request.Files["logo"].SaveAs(filePath);
                    content.ImageSource = fileName;
                }

                context.AddToContent(content);
                context.SaveChanges();

                return RedirectToAction("Index", "Home", new {area = "", id = parentName});
            }
        }
Esempio n. 2
0
        public ActionResult Edit(int id, FormCollection form)
        {
            using (var context = new ContentStorage())
            {
                var content = context.Content.Include("Parent").Where(c => c.Id == id).First();
                string parentName = "";
                if (content.Parent != null)
                    parentName = content.Parent.Name;
                string name = content.Name;
                TryUpdateModel(content, new[]
                                   {
                                       "Name", 
                                       "Title", 
                                       "PageTitle", 
                                       "Description", 
                                       "SortOrder", 
                                       "SeoDescription",
                                       "SeoKeywords"
                                   });
                content.Text = HttpUtility.HtmlDecode(form["Text"]);
                context.SaveChanges();

                return RedirectToAction("Index", "Home", new { area = "", id = parentName!=""?parentName: name });
            }
        }
Esempio n. 3
0
        public ActionResult Delete(int id)
        {
            using (var context = new ContentStorage())
            {
                var content = context.Content.Include("Children").Where(c => c.Id == id).First();

                while (content.Children.Any())
                {
                    var child = content.Children.First();
                    if (!string.IsNullOrEmpty(child.ImageSource))
                    {
                        IOHelper.DeleteFile("~/Content/Photos", child.ImageSource);
                        IOHelper.DeleteFile("~/ImageCache/thumbnail1", child.ImageSource);
                        IOHelper.DeleteFile("~/ImageCache/thumbnail2", child.ImageSource);
                        context.DeleteObject(child);
                    }
                }


                if (!string.IsNullOrEmpty(content.ImageSource))
                {
                    IOHelper.DeleteFile("~/Content/Photos", content.ImageSource);
                    IOHelper.DeleteFile("~/ImageCache/thumbnail1", content.ImageSource);
                    IOHelper.DeleteFile("~/ImageCache/thumbnail2", content.ImageSource);
                }
                context.DeleteObject(content);
                context.SaveChanges();
            }
            return RedirectToAction("Index", "Home", new { area = "", id = "" });
        }
Esempio n. 4
0
        public ActionResult EditDetailsItem(int id, FormCollection form)
        {
            using (var context = new ContentStorage())
            {
                
                var content = context.Content.Include("Parent").Where(c => c.Id == id).First();
                string parentName = content.Parent.Name;
                TryUpdateModel(content, new[] { "SortOrder" });
                content.Description = HttpUtility.HtmlDecode(form["Description"]);

                if (Request.Files["logo"] != null && !string.IsNullOrEmpty(Request.Files["logo"].FileName))
                {
                    if(!string.IsNullOrEmpty(content.ImageSource))
                    {
                        IOHelper.DeleteFile("~/Content/Photos", content.ImageSource);
                        IOHelper.DeleteFile("~/ImageCache/thumbnail1", content.ImageSource);
                        IOHelper.DeleteFile("~/ImageCache/thumbnail2", content.ImageSource);
                    }

                    string fileName = IOHelper.GetUniqueFileName("~/Content/Photos", Request.Files["logo"].FileName);
                    string filePath = Server.MapPath("~/Content/Photos");
                    filePath = Path.Combine(filePath, fileName);
                    Request.Files["logo"].SaveAs(filePath);
                    content.ImageSource = fileName;
                }
                context.SaveChanges();

                return RedirectToAction("Content", "Home", new { area = "", id = parentName });
            }
        }