예제 #1
0
 public List<Module> Get(int id)
 {
     string pageFile = System.Web.HttpContext.Current.Server.MapPath(String.Format("~/App_Data/page{0}.js", id));
     if (!File.Exists(pageFile))
     {
         StreamWriter sw = null;
         try
         {
             sw = new StreamWriter(pageFile);
             var page = new Page
             {
                 Modules = new List<Module>
                               {
                                   new Module
                                       {
                                           Id = 1,
                                           Title = "Module 1",
                                           DateCreated = DateTime.Now,
                                           DateModified = DateTime.Now
                                       }
                               }
             };
             var serializer = new JavaScriptSerializer();
             var str = serializer.Serialize(page.Modules);
             sw.Write(str);
             sw.Flush();
         }
         finally
         {
             sw.Close();
             sw.Dispose();
             sw = null;
         }
     }
     Module[] modules = null;
     StreamReader sr = null;
     try
     {
         sr = new StreamReader(pageFile);
         var str = sr.ReadToEnd();
         var serializer = new JavaScriptSerializer();
         modules = serializer.Deserialize<Module[]>(str);
     }
     finally
     {
         sr.Close();
         sr.Dispose();
         sr = null;
     }
     return modules.ToList();
 }
예제 #2
0
        public void Save(Page page)
        {
            string pageFile = System.Web.HttpContext.Current.Server.MapPath(String.Format("~/App_Data/page{0}.js", page.PageNavigation.Id));

                StreamWriter sw = null;
                try
                {
                    sw = new StreamWriter(pageFile);
                    var serializer = new JavaScriptSerializer();
                    var str = serializer.Serialize(page.Modules);
                    sw.Write(str);
                    sw.Flush();
                }
                finally
                {
                    sw.Close();
                    sw.Dispose();
                    sw = null;
                }
        }
예제 #3
0
        public Page MovePageToChildPage(int pageId)
        {
            var pages = GetNavigation();
            var page = new Page { PageNavigation = pages.Single(p => p.Id == pageId) };
            var modules = GetPage(pageId).Modules;
            foreach (Module m in modules)
                m.Content = m.Content.OrderBy(c => c.Priority).ThenByDescending(c => c.DateCreated).ToList();
            var newPage = page.Clone();
            newPage.Modules = modules;
            page.Modules = new List<Module>();
            //page.Title = "Change Title";

            newPage.PageNavigation.Id = pages.Max(p => p.Id) + 1;
            newPage.PageNavigation.Title = modules.SelectMany(m=>m.Content).First().Title;
            pages.Add(newPage.PageNavigation);
            _dataProvider.Save(newPage);
            _dataProvider.Save(page);
            SaveNavigation(pages);
            return newPage;
        }
예제 #4
0
 public void SavePage(Page page)
 {
     foreach (Module m in page.Modules)
         m.Content = m.Content.OrderBy(c => c.Priority).ThenByDescending(c => c.DateCreated).ToList();
     _dataProvider.Save(page);
 }
예제 #5
0
        public Page GetPage(int id)
        {
            var page = new Page {PageNavigation = _navigationProvider.GetNavigation().Where(p => p.Id == id).Single()};

            page.Modules = _dataProvider.Get(page.PageNavigation.Id);
            foreach(var module in page.Modules)
                foreach (var item in module.Content)
                {
                    if (item.ImageId != 0)
                    {
                        var image = _imageProvider.Get().SingleOrDefault(i => i.Id == item.ImageId);
                        item.Image = image;
                    }
                    if (item.FileId != 0)
                    {
                        var file = this.Dal.FileProvider.Get().SingleOrDefault(i => i.Id == item.FileId);
                        item.File = file;
                    }
                }
            return page;
        }