public PageCreateOrEditModel(Page page,
            bool isHomePage,
            IEnumerable<SelectListItem> availableCategories)
        {
            this.IsHomePage = isHomePage;

            this.LargeSlideshowImages = new List<Image>();
            this.SmallSlideshowImages = new List<Image>();

            this.Id = page.Id;
            this.Title = page.Title;
            this.Url = page.Url;
            this.ContentsMarkup = page.ContentsMarkup;
            this.AvailableCategories = new List<SelectListItem>
                                            {
                                                new SelectListItem
                                                    {
                                                        Selected = true,
                                                        Text = "NONE",
                                                        Value = "-1"
                                                    }
                                            };
            this.AvailableCategories.AddRange(availableCategories);
            this.IsDisplayedInLatestPosts = page.IsDisplayedInLatestPosts;
            this.IsPublic = page.IsPublic;
            this.Description = page.Description;
            this.CategoryId = page.CategoryId;
            this.IsLargeSlideshowEnabled = page.IsLargeSlideshowEnabled;
            this.LargeSlideshowImages = page.PageLargeSlideshowImages.
                    Select(pi => pi.Image).ToList();
            this.IsSmallSlideshowEnabled = page.IsSmallSlideshowEnabled;
            this.SmallSlideshowImages = page.PageSmallSlideshowImages.
                Select(pi => pi.Image).ToList();
        }
 public ContentsPageModel(Page page, PagesCommonPart commonPart)
 {
     if (page != null)
     {
         this.Title = page.Title;
         this.Description = page.Description;
         this.ContentsMarkup = page.ContentsMarkup;
         if (page.Category != null)
         {
             ((IPage) this).CurrentCategoryUrl = page.Category.Url;
         }
         if (page.IsLargeSlideshowEnabled)
         {
             this.IsLargeSlideshowEnabled = page.IsLargeSlideshowEnabled;
             this.LargeSlideshowImages = page.PageLargeSlideshowImages.
                 Select(pi => pi.Image).ToList();
         }
         if (page.IsSmallSlideshowEnabled)
         {
             this.IsSmallSlideshowEnabled = page.IsSmallSlideshowEnabled;
             this.SmallSlideshowImages = page.PageSmallSlideshowImages.
                 Select(pi => pi.Image).ToList();
         }
     }
     else
     {
         this.Title = Config.DefaultPageName;
         this.ContentsMarkup = String.Empty;
     }
     ((IPage)this).CommonPart = commonPart ?? new PagesCommonPart();
     if (((IPage)this).CommonPart.Subscriber == null)
     {
         ((IPage)this).CommonPart.Subscriber = new Subscriber();
     }
 }
        private static EntityUpdateTask<Page> CreateEntityUpdateTask(Page page)
        {
            FileSystemIndexLocation indexLocation = new FileSystemIndexLocation(IndexDirectoryInfo);
            PageIndexDefinition definition = new PageIndexDefinition();
            EntityUpdateTask<Page> entityUpdateTask = new EntityUpdateTask<Page>(page, definition, indexLocation);

            IndexQueue.Instance.Queue(entityUpdateTask);
            return entityUpdateTask;
        }
 public static void AddOrUpdate(Page page)
 {
     EntityUpdateTask<Page> entityUpdateTask = CreateEntityUpdateTask(page);
     using (IndexService indexService = new IndexService(
                                              new DirectoryIndexWriter(IndexDirectoryInfo)))
     {
         entityUpdateTask.Execute(indexService);
     }
 }
        private void UpdatePage(Page page, PageCreateOrEditModel model)
        {
            foreach (Image image in model.LargeSlideshowImages)
            {
                if (Context.Images.Local.All(i => i.Id != image.Id))
                {
                    Context.Images.Attach(image);
                }
            }
            foreach (Image image in model.SmallSlideshowImages)
            {
                if (Context.Images.Local.All(i => i.Id != image.Id))
                {
                    Context.Images.Attach(image);
                }
            }
            page.Title = model.Title;
            page.IsDisplayedInLatestPosts = model.IsDisplayedInLatestPosts;
            page.IsPublic = model.IsPublic;
            page.Description = model.Description;
            page.ContentsMarkup = model.ContentsMarkup;
            page.CreateDate = DateTime.Now;
            page.CategoryId = model.CategoryId > 0 ?
                model.CategoryId :
                default(int?);
            page.IsLargeSlideshowEnabled = model.IsLargeSlideshowEnabled;
            page.IsSmallSlideshowEnabled = model.IsSmallSlideshowEnabled;

            List<PageLargeSlideshowImage> largeSlideshowImages = page.
                PageLargeSlideshowImages.ToList();
            foreach (PageLargeSlideshowImage largeSlideshowImage in largeSlideshowImages)
            {
                Context.PageLargeSlideshowImages.Remove(largeSlideshowImage);
            }
            List<PageSmallSlideshowImage> smallSlideshowImages = page.
                PageSmallSlideshowImages.ToList();
            foreach (PageSmallSlideshowImage smallSlideshowImage in smallSlideshowImages)
            {
                Context.PageSmallSlideshowImages.Remove(smallSlideshowImage);
            }

            foreach (Image image in model.LargeSlideshowImages)
            {
                page.PageLargeSlideshowImages.Add(new PageLargeSlideshowImage
                    {
                        Image = Context.Images.
                            Local.Single(li => li.Id == image.Id),
                        Page = page
                    });
            }
            foreach (Image image in model.SmallSlideshowImages)
            {
                page.PageSmallSlideshowImages.Add(new PageSmallSlideshowImage
                    {
                        Image = Context.Images.
                            Local.Single(li => li.Id == image.Id),
                        Page = page
                    });
            }
            Context.SaveChanges();
        }
        private Page CreatePageByModel(PageCreateOrEditModel model)
        {
            foreach (Image image in model.LargeSlideshowImages)
            {
                if (Context.Images.Local.All(i => i.Id != image.Id))
                {
                    Context.Images.Attach(image);
                }
            }
            foreach (Image image in model.SmallSlideshowImages)
            {
                if (Context.Images.Local.All(i => i.Id != image.Id))
                {
                    Context.Images.Attach(image);
                }
            }
            Page newPage = new Page
                    {
                        Title = model.Title,
                        Url = model.Url,
                        IsPublic = model.IsPublic,
                        IsDisplayedInLatestPosts = model.IsDisplayedInLatestPosts,
                        Description = model.Description,
                        ContentsMarkup = model.ContentsMarkup,
                        CreateDate = DateTime.Now,
                        CategoryId = model.CategoryId > 0 ? model.CategoryId : default(int?),
                        IsLargeSlideshowEnabled = model.IsLargeSlideshowEnabled,
                        IsSmallSlideshowEnabled = model.IsSmallSlideshowEnabled
                    };
            foreach (Image image in model.LargeSlideshowImages)
            {
                newPage.PageLargeSlideshowImages.Add(new PageLargeSlideshowImage
                    {
                        Image = Context.Images.
                            Local.Single(li => li.Id == image.Id),
                        Page = newPage
                    });
            }
            foreach (Image image in model.SmallSlideshowImages)
            {
                newPage.PageSmallSlideshowImages.Add(new PageSmallSlideshowImage
                    {
                        Image = Context.Images.
                            Local.Single(li => li.Id == image.Id),
                        Page = newPage
                    });
            }

            return newPage;
        }