public WidgetElementDTO SaveWidgetElement(WidgetElementDTO wid) { using (ISession session = HibernateHelper.GetSession().OpenSession()) { using (ITransaction transaction = session.BeginTransaction()) { try { WidgetElement widget = new WidgetElement(); Mapper.CreateMap<WidgetElementDTO, WidgetElement>(); Mapper.CreateMap<ElementDTO, Element>(); WidgetElementDTO widgetDTO = new WidgetElementDTO(); if (wid.IsNew || wid.Deleted) { widget = Mapper.Map<WidgetElementDTO, WidgetElement>(wid); } else { widgetDTO = GetWidgetElement(wid.Widgetelementid); widget = Mapper.Map<WidgetElementDTO, WidgetElement>(widgetDTO); } if (widget.Type == 0) { widget.Type = 1; } if (widget.Name != null && widget.Widgetid > 0 && widget.Position > 0) { if (wid.Dirty) { if (widget.Name != wid.Name) { //Sto rinominando il link widget.Name = EditorServices.ReplaceCharacters(wid.Name); } else { if (widget.Valore != wid.Valore) { widget.Valore = wid.Valore; } } } widget.Dirty = wid.Dirty; widget.Deleted = wid.Deleted; widget.IsNew = wid.IsNew; HibernateHelper.Persist(widget, session); } Mapper.CreateMap<WidgetElement, WidgetElementDTO>(); Mapper.CreateMap<Element, ElementDTO>(); //Mappo la PageDTO in Page wid = Mapper.Map<WidgetElement, WidgetElementDTO>(widget); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); throw ex; } finally { session.Flush(); session.Close(); } } //Setto lo stato del content a non allineato WidgetDTO widg = new WidgetDTO(); widg = GetWidget(wid.Widgetid); ContentServices contSvc = new ContentServices(); contSvc.SetStateContent(widg.Contentid, (int)ContentStateEnum.NonAllineato); return wid; } }
public WidgetElementDTO MoveWidgetElement(WidgetElementDTO wid) { using (ISession session = HibernateHelper.GetSession().OpenSession()) { ITransaction transaction = session.BeginTransaction(); try { if (wid.Position > 0) { Widget Padre = EditorServices.GetWidgetById(wid.Widgetid, session); int oldpos = 0; var con = (from f in Padre.WidgetElements where f.Widgetelementid == wid.Widgetelementid select f).FirstOrDefault<WidgetElement>(); if (con != null) { oldpos = con.Position; } foreach (WidgetElement pg in Padre.WidgetElements) { if (pg.Widgetelementid == wid.Widgetelementid) { oldpos = pg.Position; pg.Position = wid.Position; pg.Dirty = true; HibernateHelper.Persist(pg, session); } else if (pg.Position > wid.Position) { pg.Position = pg.Position + 1; pg.Dirty = true; HibernateHelper.Persist(pg, session); } else if (pg.Position <= wid.Position // && pg.Position != 1 && con != null) { if (pg.Position == wid.Position && oldpos > wid.Position) { pg.Position = pg.Position + 1; } else { pg.Position = pg.Position - 1; } pg.Dirty = true; HibernateHelper.Persist(pg, session); } } } } catch (Exception ex) { transaction.Rollback(); throw ex; } finally { session.Flush(); session.Close(); transaction.Dispose(); } } return wid; }