public virtual bool Equals(PageElement obj) { if (obj == null) return false; if (Equals(PageElementid, obj.PageElementid) == false) return false; if (Equals(Pageid, obj.Pageid) == false) return false; if (Equals(Elementid, obj.Elementid) == false) return false; if (Equals(Valore, obj.Valore) == false) return false; return true; }
public PageDTO SavePage(PageDTO pagedto) { using (ISession session = HibernateHelper.GetSession().OpenSession()) { using (ITransaction transaction = session.BeginTransaction()) { try { Page page = new Page(); Mapper.CreateMap<PageDTO, Page>(); Mapper.CreateMap<PageElementDTO, PageElement>(); Mapper.CreateMap<ElementDTO, Element>(); //Mappo la PageDTO in Page page = Mapper.Map<PageDTO, Page>(pagedto); Regex punt = new Regex(@"[\t\r\n\e\a._%+-/]"); page.Title = punt.Replace(page.Title.Replace(" ", "").Trim().Replace(" ", "_"), "_"); if (page.Publictitle != null && page.Contentid > 0 && page.Position > 0) { page.Publictitle = EditorServices.ReplaceCharacters(page.Publictitle); if (page.IsNew) { // Salvo la Nuova pagina HibernateHelper.Persist(page, session); if (page.PageelementsList.Count == 0) { //Creo Le Page Elements in base alla struttura //Ricavo la lista degli elementi della struttura per generare i PageElement List<Element> structList = new List<Element>(); structList = HibernateHelper.SelectCommand<Element>(session, " STRUCTUREID =" + page.Structureid); ISet<PageElement> PaElements = new HashedSet<PageElement>(); foreach (Element el in structList) { PageElement PaElement = new PageElement(); PaElement.Element = el; PaElement.Elementid = el.Elementid; PaElement.Page = page; PaElement.Pageid = page.Pageid; PaElement.Valore = EditorServices.ReplaceCharacters(el.Description); PaElement.IsNew = true; if (el.Elementtypeid == (int)ElementTypeEnum.RawHtml) { //solo RawHtml RawHtml raw = new RawHtml(); raw.Value = EditorServices.ReplaceCharacters(el.Description); raw.IsNew = true; HibernateHelper.Persist(raw, session); PaElement.Rawhtmlid = raw.Rawhtmlid; } HibernateHelper.Persist(PaElement, session); PaElements.Add(PaElement); } page.PageElements = PaElements; PaElements = page.PageElements; } // Setto il padre al pageid se è zero if (page.Parentpageid == 0) { page.Parentpageid = page.Pageid; } else { page.Parentpageid = page.Parentpageid; } // Setto skinID a null se è zero if (page.Skinid == 0) { page.Skinid = null; } page.Dirty = true; HibernateHelper.Persist(page, session); } else if (page.Dirty) { //Update della Pagina Esistente HibernateHelper.Persist(page, session); //Foreach delle pageelements foreach (PageElement el in page.PageelementsList) { el.Pageid = page.Pageid; if (el.Deleted) { page.PageElements.Remove(el); HibernateHelper.Persist(el, session); } else { el.Valore = EditorServices.ReplaceCharacters(el.Valore); HibernateHelper.Persist(el, session); } } } } //Rimappo l'oggetto da restituire Mapper.CreateMap<Page, PageDTO>(); Mapper.CreateMap<PageElement, PageElementDTO>(); Mapper.CreateMap<Element, ElementDTO>(); //Mappo la PageDTO in Page pagedto = Mapper.Map<Page, PageDTO>(page); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); throw ex; } finally { session.Flush(); session.Close(); } } } //Setto lo stato del content a non allineato ContentServices contSvc = new ContentServices(); contSvc.SetStateContent(pagedto.Contentid, (int)ContentStateEnum.NonAllineato); return pagedto; }
public PageDTO ClonePage(PageDTO pagedto, int idItemAmm, string FolderToSave) { using (ISession session = HibernateHelper.GetSession().OpenSession()) { using (ITransaction transaction = session.BeginTransaction()) { try { Page page = new Page(); Mapper.CreateMap<PageDTO, Page>(); Mapper.CreateMap<PageElementDTO, PageElement>(); //Mappo la PageDTO in Page page = Mapper.Map<PageDTO, Page>(pagedto); //Tengo in memoria il pageid da clonare int pageId = page.Pageid; //Salvo la nuova Pagina HibernateHelper.Persist(page, session); //Ricavo i PageElements del padre List<PageElement> CloneElements = HibernateHelper.SelectCommand<PageElement>(session, new string[] { "Pageid" }, new object[] { pageId }, new Operators[] { Operators.Eq }); //Ciclo sui CloneElements ISet<PageElement> ChildElements = new HashedSet<PageElement>(); foreach (PageElement el in CloneElements) { PageElement child = new PageElement(); child.IsNew = true; child.Page = page; child.Pageid = page.Pageid; child.Valore = EditorServices.ReplaceCharacters(el.Valore); child.Filename = el.Filename; child.Element = el.Element; child.Elementid = el.Elementid; if (el.Element.ElementType.Elementtypeid == (int)ElementTypeEnum.RawHtml) { //Get RawHtml Clone RawHtml cloneraw = new RawHtml(); cloneraw = HibernateHelper.SelectIstance<RawHtml>(session, new string[] { "Rawhtmlid" }, new object[] { el.Rawhtmlid }, new Operators[] { Operators.Eq }); RawHtml childraw = new RawHtml(); childraw.IsNew = true; childraw.Value = EditorServices.ReplaceCharacters(cloneraw.Value); SaveRawHtml(childraw, FolderToSave); child.Rawhtmlid = childraw.Rawhtmlid; } HibernateHelper.Persist(child, session); ChildElements.Add(child); } page.PageElements = ChildElements; ChildElements = page.PageElements; // Setto il padre al pageid se è zero if (page.Parentpageid == 0) { page.Parentpageid = page.Pageid; } else { page.Parentpageid = page.Parentpageid; } // Setto skinID a null se è zero if (page.Skinid == 0) { page.Skinid = null; } page.Dirty = true; HibernateHelper.Persist(page, session); //Rimappo l'oggetto da restituire Mapper.CreateMap<Page, PageDTO>(); Mapper.CreateMap<PageElement, PageElementDTO>(); Mapper.CreateMap<Element, ElementDTO>(); //Mappo la PageDTO in Page pagedto = Mapper.Map<Page, PageDTO>(page); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); throw ex; } finally { session.Flush(); session.Close(); } } } //Setto lo stato del content a non allineato ContentServices contSvc = new ContentServices(); contSvc.SetStateContent(pagedto.Contentid, (int)ContentStateEnum.NonAllineato); return pagedto; }
public PageElementDTO GetPageelementByPageelementID(int PageelementID) { using (ISession session = HibernateHelper.GetSession().OpenSession()) { using (ITransaction transaction = session.BeginTransaction()) { try { PageElement pel = new PageElement(); pel = HibernateHelper.SelectIstance<PageElement>(session, new string[] { "PageElementid" }, new object[] { PageelementID }, new Operators[] { Operators.Eq }); Mapper.CreateMap<PageElement, PageElementDTO>(); Mapper.CreateMap<Element, ElementDTO>(); return Mapper.Map<PageElement, PageElementDTO>(pel); } catch (Exception ex) { throw ex; } finally { session.Flush(); session.Close(); } } } }