public static Stream GetInventioPageStream(string path) { Stream ret = null; InventioPage page = PageWorker.SelectByPath(path, PageWorker.RepositoryWebConfig); if (page != null) { InventioLayout layout = LayoutWorker.SelectById(page.IdLayout, LayoutWorker.RepositoryWebConfig); if (layout != null) { string raw = System.Text.Encoding.UTF8.GetString(layout.Body); string parsed = string.Empty; // BEGIN RazorEngine Template // TODO igual hay que meterlo en global asax var config = new RazorEngine.Configuration.TemplateServiceConfiguration { //BaseTemplateType = typeof(InventioTemplateBase<>) BaseTemplateType = typeof(InventioTemplateBase <>), Resolver = new InventioTemplateResolver() }; using (var service = new TemplateService(config)) { RazorEngine.Razor.SetTemplateService(service); parsed = Razor.Parse(raw); } // END RazorEngine ret = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(parsed), false); } } return(ret); }
public Nullable <int> Create(InventioLayout layout) { DataTable dt = new DataTable(); // Check if file exists if (File.Exists(XmlFile)) { //dt.ReadXml(XmlFile); File.Delete(XmlFile); } //else //{ dt.TableName = "Layouts"; //dt.Columns.Add("Id", typeof(int64)); dt.Columns.Add("Title", typeof(String)); dt.Columns.Add("Description", typeof(String)); dt.Columns.Add("Body", typeof(String)); dt.Columns.Add("PreviewUrl", typeof(String)); //} DataRow NewRow = dt.NewRow(); NewRow["Title"] = layout.Title; NewRow["Description"] = layout.Description; NewRow["Body"] = Convert.ToBase64String(layout.Body); NewRow["PreviewUrl"] = layout.PreviewUrl; dt.Rows.Add(NewRow); dt.WriteXml(XmlFile); return(1); }
public InventioLayout Read(int id) { //// TODO InventioLayout ret = new InventioLayout(); //ret.Title = "Este es el título de la página"; //ret.Body = BytesHelper.GetBytes("hola"); return(ret); }
public static Nullable <int> Add(InventioLayout layout, ILayoutRepository Repository) { Nullable <int> ret = null; if (layout != null) { ret = Repository.Create(layout); } return(ret); }
public void Update(InventioLayout layout) { // TODO REVISAR NO TESTEADO Layouts data = EFAdapter(layout); using (InventioEntities context = new InventioEntities()) { context.Layouts.Attach(data); context.Entry(data).State = EntityState.Modified; context.SaveChanges(); } }
public Layouts EFAdapter(InventioLayout layout) { Layouts ret = null; ret = new Layouts(); ret.Id = layout.Id; ret.Title = layout.Title; ret.Description = layout.Description; ret.Body = Convert.ToBase64String(layout.Body); ret.PreviewUrl = layout.PreviewUrl; return(ret); }
public string Resolve(string name) { string ret = "MASTER NOT FOUND"; InventioLayout layout = LayoutWorker.SelectByTitle(name, LayoutWorker.RepositoryWebConfig); if (layout != null) { ret = System.Text.Encoding.UTF8.GetString(layout.Body); } return(ret); }
public InventioLayout SelectById(int id) { InventioLayout ret = null; ret = Read(id); if (ret == null) { ret = new InventioLayout(); ret.Title = "Not found"; ret.Body = Encoding.UTF8.GetBytes("<h1>Página no encontrada</h1><p>Hola @ViewBag.Name</p>"); } return(ret); }
public Nullable <int> Create(InventioLayout layout) { Nullable <int> ret = null; Layouts data = EFAdapter(layout); using (InventioEntities context = new InventioEntities()) { context.Layouts.Add(data); context.SaveChanges(); ret = data.Id; } return(ret); }
public ActionResult Layouts(HttpPostedFileBase file) { // Verify that the user selected a file if (file != null && file.ContentLength > 0) { InventioLayout layout = new InventioLayout(); layout.Title = Path.GetFileName(file.FileName); layout.PreviewUrl = string.Empty; layout.Body = BytesHelper.StreamToByteArray(file.InputStream); PagesManager.AddLayout(layout); } return(RedirectToAction("Layouts")); }
public InventioLayout Read(int id) { InventioLayout ret = new InventioLayout(); using (InventioEntities context = new InventioEntities()) { Layouts selected = context.Layouts.Where <Layouts>(s => s.Id == id).FirstOrDefault <Layouts>(); if (selected != null) { ret = InventioAdapter(selected); } } return(ret); }
public InventioLayout InventioAdapter(Layouts eflayout) { InventioLayout ret = null; if (eflayout != null) { ret = new InventioLayout(); ret.Id = eflayout.Id; ret.Title = eflayout.Title; ret.Description = eflayout.Description; ret.Body = Convert.FromBase64String(eflayout.Body); ret.PreviewUrl = eflayout.PreviewUrl; } return(ret); }
public InventioLayout SelectByTitle(string title) { InventioLayout ret = null; if (!string.IsNullOrWhiteSpace(title)) { using (InventioEntities context = new InventioEntities()) { Layouts selected = context.Layouts.Where <Layouts>(s => s.Title.ToLower() == title.ToLower()).FirstOrDefault <Layouts>(); if (selected != null) { ret = InventioAdapter(selected); } } } return(ret); }
public static Nullable <int> AddLayout(InventioLayout layout) { Nullable <int> ret = null; if (layout != null) { InventioLayout hit = LayoutWorker.SelectByTitle(layout.Title, LayoutWorker.RepositoryWebConfig); if (hit == null) { ret = LayoutWorker.Add(layout, LayoutWorker.RepositoryWebConfig); } else { layout.Id = hit.Id; LayoutWorker.Update(layout, LayoutWorker.RepositoryWebConfig); ret = layout.Id; } } return(ret); }
public InventioLayout SelectById(int id) { // TODO InventioLayout ret = new InventioLayout(); if (File.Exists(XmlFile)) { DataSet ds = new DataSet(); ds.ReadXml(XmlFile); ret.Title = ds.Tables[0].Rows[0]["Title"] as string ?? string.Empty; ret.Body = Convert.FromBase64String(ds.Tables[0].Rows[0]["Body"].ToString()); ret.PreviewUrl = ds.Tables[0].Rows[0]["PreviewUrl"].ToString(); } else { ret.Title = "Not found"; ret.Body = Encoding.UTF8.GetBytes("<h1>Página no encontrada</h1><p>Hola @ViewBag.Name</p>"); } return(ret); }
public List <InventioLayout> SelectAll() { List <InventioLayout> ret = null; using (InventioEntities context = new InventioEntities()) { if (context.Layouts != null && context.Layouts.Count() > 0) { ret = new List <InventioLayout>(); foreach (Layouts layout in context.Layouts) { InventioLayout newlayout = InventioAdapter(layout); if (newlayout != null) { ret.Add(newlayout); } } } } return(ret); }
public void Update(InventioLayout layout) { throw new NotImplementedException(); }
public static void Update(InventioLayout layout, ILayoutRepository Repository) { Repository.Update(layout); }