Exemplo n.º 1
0
 public ActionResult EditTextBlock(int id)
 {
     using (var context = new SiteContainer())
     {
         var contentItem = context.ContentItem.First(c => c.Id == id);
         return View(contentItem);
     }
 }
Exemplo n.º 2
0
 public ActionResult AddTextBlock()
 {
     using (var context = new SiteContainer())
     {
         int maxSortOrder = context.ContentItem.Max(c => (int?) c.SortOrder) ?? 0;
         return View(new ContentItem { SortOrder = maxSortOrder + 1 });
     }
 }
Exemplo n.º 3
0
 public ActionResult Edit(int id)
 {
     using (var context = new SiteContainer())
     {
         var content = context.Content.First(c => c.Id == id);
         return View(content);
     }
 }
Exemplo n.º 4
0
 public ActionResult DeleteTextBlock(int id)
 {
     using (var context = new SiteContainer())
     {
         var contentItem = context.ContentItem.First(c => c.Id == id);
         context.DeleteObject(contentItem);
         context.SaveChanges();
         return RedirectToAction("Index", "Home", new { area = "", id = "look" });
     }
 }
Exemplo n.º 5
0
 public ActionResult EditTextBlock(int id, FormCollection form)
 {
     using (var context = new SiteContainer())
     {
         var contentItem = context.ContentItem.First(c => c.Id == id);
         TryUpdateModel(contentItem, new[] { "SortOrder" });
         contentItem.Text = HttpUtility.HtmlDecode(form["Text"]);
         context.SaveChanges();
         return RedirectToAction("Index", "Home", new { area = "", id = "look" });
     }
 }
Exemplo n.º 6
0
 public ActionResult Edit(int id, FormCollection form)
 {
     using (var context = new SiteContainer())
     {
         var content = context.Content.First(c => c.Id == id);
         TryUpdateModel(content, new[] { "Title", "SortOrder", "SeoDescription", "SeoKeywords" });
         content.Text = HttpUtility.HtmlDecode(form["Text"]);
         context.SaveChanges();
         return RedirectToAction("Index", "Home", new { area = "", id = content.Name });
     }
 }
Exemplo n.º 7
0
        public ActionResult Index(string id)
        {
            using (var context = new SiteContainer())
            {

                var model = new SiteModel(context, id, id == "look");
                this.SetSeoContent(model);
                ViewBag.isHomePage = model.IsHomePage;
                ViewBag.PageTitle = model.PageTitle;
                return View(model);
            }
        }
Exemplo n.º 8
0
 public ActionResult AddTextBlock(FormCollection form)
 {
     using (var context = new SiteContainer())
     {
         var contentItem = new ContentItem
                               {
                                   ContentType = 1,
                                   Text = HttpUtility.HtmlDecode(form["Text"])
                               };
         TryUpdateModel(contentItem, new[] { "SortOrder" });
         context.AddToContentItem(contentItem);
         context.SaveChanges();
         return RedirectToAction("Index", "Home", new { area = "", id = "look" });
     }
 }
Exemplo n.º 9
0
        public SiteModel(SiteContainer context, string contentName, bool showContentItems = false)
        {
            Title = "Ольга Шитова";
            PageTitle = "Ольга Шитова";
            if (contentName == null)
            {
                Content = context.Content.First(c => c.MainPage);
            }
            else
            {
                Content = context.Content.FirstOrDefault(c => c.Name == contentName);
                if (Content == null)
                {
                    throw new HttpNotFoundException();
                }
            }

            if (!string.IsNullOrEmpty(Content.Title))
            {
                if (Content.Title != PageTitle)
                    PageTitle += " » " + Content.Title;
                Title = Content.Title;
            }

            SeoDescription = Content.SeoDescription;
            SeoKeywords = Content.SeoKeywords;

            if (Content.MainPage)
            {
                IsHomePage = true;
            }


            
            if (showContentItems)
            {
                HasContentItems = true;
                ContentItems = context.ContentItem.Include("ContentItemImages").OrderBy(ci => ci.SortOrder).ToList();
            }

            var contents = context.Content.Where(c => !c.MainPage).ToList();

            Menu = new Menu();
            Menu.AddRange(contents.Select(content => new MenuItem {ContentId = content.Id, ContentName = content.Name, Current = content.Name == contentName, SortOrder = content.SortOrder, Title = content.Title}));
        }
Exemplo n.º 10
0
        public ActionResult DeleteImage(int id)
        {
            using (var context = new SiteContainer())
            {
                var image = context.ContentItemImage.First(c => c.Id == id);
                var contentItemId = image.ContentItemId;

                ImageHelper.DeleteImage(image.ImageSource);
                context.DeleteObject(image);
                context.SaveChanges();
                
                
                var contentItem = context.ContentItem.Include("ContentItemImages").First(c => c.Id == contentItemId);
                if (!contentItem.ContentItemImages.Any())
                {
                    context.DeleteObject(contentItem);
                    context.SaveChanges();
                }


            }
            return RedirectToAction("Index", "Home", new { area = "", id = "look" });
        }
Exemplo n.º 11
0
        public ActionResult DeleteImagesBlock(int id)
        {
            using (var context = new SiteContainer())
            {
                var contentItem = context.ContentItem.Include("ContentItemImages").First(c => c.Id == id);

                while (contentItem.ContentItemImages.Any())
                {
                    var ci = contentItem.ContentItemImages.First();
                    ImageHelper.DeleteImage(ci.ImageSource);
                    context.DeleteObject(ci);
                }

                context.DeleteObject(contentItem);

                context.SaveChanges();



                return RedirectToAction("Index", "Home", new { area = "", id = "look" });
            }
        }
Exemplo n.º 12
0
        public ActionResult EditImagesBlock(int id, FormCollection form)
        {
            using (var context = new SiteContainer())
            {
                var contentItem = context.ContentItem.First(c => c.Id == id);
                TryUpdateModel(contentItem, new[] { "SortOrder" });
                for (int i = 0; i < Request.Files.Count; i++)
                {
                    var file = Request.Files[i];

                    if (file == null) continue;
                    if (string.IsNullOrEmpty(file.FileName)) continue;

                    var ci = new ContentItemImage();
                    string fileName = IOHelper.GetUniqueFileName("~/Content/Images", file.FileName);
                    string filePath = Server.MapPath("~/Content/Images");

                    filePath = Path.Combine(filePath, fileName);
                    GraphicsHelper.SaveOriginalImage(filePath, fileName, file, 1500);

                    ci.ImageSource = fileName;
                    contentItem.ContentItemImages.Add(ci);
                }

                context.SaveChanges();

                return RedirectToAction("Index", "Home", new { area = "", id = "look" });
            }
        }