예제 #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});
            }
        }
예제 #2
0
        public ActionResult AddDetailsItem(int id, FormCollection form)
        {
            using (var context = new ContentStorage())
            {
                var parent = context.Content.Where(c => c.Id == id).First();
                string parentName = parent.Name;
                var content = new Content {Parent = parent, Name = "", ContentLevel = 3};

                TryUpdateModel(content, new[] { "SortOrder"});
                content.Description = HttpUtility.HtmlDecode(form["Description"]);

                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("Content", "Home", new {area = "", id = parentName});
            }
        }