//------------------------------------------------------------------------------------------
        public void DuplicateBoard(int boardId)
        {
            // scoatem entitatea si ii copiem valorile
            var res = (from d in this._em.Boards
                       where d.Id == boardId
                       select d).ToList();

            if (res.Count() < 1)
                return;

            Board b = res[0];
            Board newBoard = new Board();
            newBoard.Name = b.Name + " Copy";
            newBoard.Owner = b.Owner;
            newBoard.Seed = b.Seed;
            this._em.AddToBoards(newBoard);
            /*salvam modificarile sa generam un id nou*/
            this._em.SaveChanges();

            //scoatem fiecare layer continut si generam entitati duplicate
            var res1 = (from d in this._em.Layers
                        where d.BoardId == boardId
                        select d).ToList();

            foreach (Layer l in res1)
            {
                Layer newLayer = new Layer();
                newLayer.BoardId = newBoard.Id;
                newLayer.LayerId = l.LayerId;
                newLayer.Name = l.Name;
                newLayer.Order = l.Order;

                this._em.AddToLayers(newLayer);
                this._em.SaveChanges();

                /* duplicam widgeturile pentru fiecare layer in bd*/
                var res2 = (from d in this._em.Widgets
                            where d.LayerId == l.LayerId
                            select d).ToList();

                foreach (Widget w in res2)
                {
                    Widget newWidget = new Widget();
                    newWidget.LayerId = newLayer.Id;
                    newWidget.WidgetId = w.WidgetId;
                    newWidget.Type = w.Type;
                    newWidget.Data = w.Data;
                    newWidget.Name = w.Name;
                    newWidget.Order = w.Order;

                    this._em.AddToWidgets(newWidget);
                }
            }

            /* duplicam drepturile userilor asupra boardului*/
            var res3 = (from d in this._em.UserRights
                        where d.BoardId == boardId
                        select d).ToList();

            foreach (UserRight ur in res3)
            {
                UserRight u = new UserRight();
                u.BoardId = ur.BoardId;
                u.Right = ur.Right;
                u.User = ur.User;
                this._em.AddToUserRights(u);
            }
            this._em.SaveChanges();
        }
 /// <summary>
 /// Create a new Layer object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="boardId">Initial value of the BoardId property.</param>
 /// <param name="layerId">Initial value of the LayerId property.</param>
 /// <param name="order">Initial value of the Order property.</param>
 /// <param name="name">Initial value of the Name property.</param>
 public static Layer CreateLayer(global::System.Int32 id, global::System.Int32 boardId, global::System.Int32 layerId, global::System.Int32 order, global::System.String name)
 {
     Layer layer = new Layer();
     layer.Id = id;
     layer.BoardId = boardId;
     layer.LayerId = layerId;
     layer.Order = order;
     layer.Name = name;
     return layer;
 }
        //------------------------------------------------------------------------------------------
        //------------------------------------------------------------------------------------------
        private void _AddLayer(ActiveBoard b, Change change)
        {
            ActiveLayer newActiveLayer = new ActiveLayer();
            var jss = new JavaScriptSerializer();
            ChangeDataLayer cd = jss.Deserialize<ChangeDataLayer>(change.ChangeString);
            newActiveLayer.Id = cd.Id;
            newActiveLayer.Name = cd.Name;

            /*creem si o entitate in bd*/
            Layer newLayer = new Layer();
            newActiveLayer.LayerEntity = newLayer;
            newLayer.LayerId = cd.Id;
            newLayer.Order = cd.Order;
            newLayer.BoardId = b.BoardEntity.Id;
            newLayer.Name = cd.Name;

            /*inseram in stackul de layere din board*/
            lock (b.Layers) {
                b.Layers.Add(cd.Id, newActiveLayer);
            }
            lock (b.LayerStack) {
                b.LayerStack.Insert(cd.Order, newActiveLayer);
            }

            this._em.AddToLayers(newLayer);
        }
 /// <summary>
 /// Deprecated Method for adding a new object to the Layers EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToLayers(Layer layer)
 {
     base.AddObject("Layers", layer);
 }