//------------------------------------------------------------------------------------------ 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 Widget object. /// </summary> /// <param name="id">Initial value of the Id property.</param> /// <param name="layerId">Initial value of the LayerId property.</param> /// <param name="data">Initial value of the Data property.</param> /// <param name="widgetId">Initial value of the WidgetId property.</param> /// <param name="type">Initial value of the Type property.</param> /// <param name="order">Initial value of the Order property.</param> /// <param name="name">Initial value of the Name property.</param> public static Widget CreateWidget(global::System.Int32 id, global::System.Int32 layerId, global::System.String data, global::System.Int32 widgetId, global::System.String type, global::System.Int32 order, global::System.String name) { Widget widget = new Widget(); widget.Id = id; widget.LayerId = layerId; widget.Data = data; widget.WidgetId = widgetId; widget.Type = type; widget.Order = order; widget.Name = name; return widget; }
//------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------ private void _AddWidget(ActiveBoard b, Change change) { ActiveWidget newActiveWidget = new ActiveWidget(); var jss = new JavaScriptSerializer(); ChangeDataWidget cd = jss.Deserialize<ChangeDataWidget>(change.ChangeString); newActiveWidget.WidgetId = cd.Id; newActiveWidget.Name = cd.Name; newActiveWidget.Type = cd.Type; newActiveWidget.Data = cd.Data; /*creem si o entitate in bd*/ Widget newWidget = new Widget(); newActiveWidget.WidgetEntity = newWidget; newWidget.WidgetId = cd.Id; newWidget.Order = cd.Order; newWidget.LayerId = cd.LayerId; newWidget.Name = cd.Name; newWidget.Data = cd.Data; /*inseram in listele de widgeturi din layer*/ try { lock (b.Layers[cd.LayerId].Widgets) { b.Layers[cd.LayerId].Widgets.Add(cd.Id, newActiveWidget); } lock (b.Layers[cd.LayerId].WidgetsStack) { b.Layers[cd.LayerId].WidgetsStack.Insert(cd.Order, newActiveWidget); } } catch (KeyNotFoundException ex) { Console.WriteLine(ex.ToString()); } this._em.AddToWidgets(newWidget); }
/// <summary> /// Deprecated Method for adding a new object to the Widgets EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToWidgets(Widget widget) { base.AddObject("Widgets", widget); }