public static BaseObject FromDbObject(PlanObject plan) { BaseObject result = GetBaseObjectByTypeId(plan.TypeId); if (result == null) return null; result.Id = plan.Id; result.ParentId = plan.ParentId; result.Type = plan.PlanObjectType.Name; result.TypeId = plan.TypeId; result.Name = plan.Name; result.Description = plan.Description; result.Top = plan.Top; result.Left = plan.Left; result.Width = plan.Width ?? 700; result.Height = plan.Height ?? 700; result.IsContainer = plan.PlanObjectType.IsContainer; if (plan.Geometry != null) result.Path = GeometryData.Parse(plan.Geometry); if (!plan.PlanObjectType.IsContainer || !(result is IContainerObject)) return result; var containerObject = result as IContainerObject; foreach (var planObject in plan.PlanObjects.OrderBy(p => p.Order)) containerObject.Children.Add(FromDbObject(planObject)); return result; }
public static void ExportToDbObject(this BaseObject baseObject, PlanObject dbObject, PlansDc context, int order = 0) { dbObject.Id = baseObject.Id >= 0 ? baseObject.Id : GetNewPlanObjectId(context); if (baseObject.ParentId != null && baseObject.ParentId >= 0) dbObject.ParentId = baseObject.ParentId; dbObject.Order = order; dbObject.Name = baseObject.Name; dbObject.Description = baseObject.Description; dbObject.Left = baseObject.Left; dbObject.Top = baseObject.Top; dbObject.Width = baseObject.Width; dbObject.Height = baseObject.Height; dbObject.TypeId = baseObject.TypeId; if (baseObject.Path != null) dbObject.Geometry = baseObject.Path.ToSvg(); if (baseObject.Properties != null) { dbObject.Properties.Clear(); foreach (var baseObjectProperty in baseObject.Properties.Where(p => !string.IsNullOrWhiteSpace(p.Path))) { var newProperty = new Property { AddressTypeId = baseObjectProperty.TypeId, Path = baseObjectProperty.Path }; dbObject.Properties.Add(newProperty); } } if (!baseObject.IsContainer) return; var baseContainer = baseObject as IContainerObject; if (baseContainer == null) throw new BadRequestException("Children cannot be null in ContainerObject"); for (var i = dbObject.PlanObjects.Count - 1; i >= 0; i--) { if (baseContainer.Children.All(s => s.Id != dbObject.PlanObjects[i].Id)) dbObject.PlanObjects.RemoveAt(i); } var childOrder = 0; foreach (var childObject in baseContainer.Children) { var dbChildObject = dbObject.PlanObjects.FirstOrDefault(p => p.Id == childObject.Id); if (dbChildObject == null) { dbChildObject = new PlanObject(); dbObject.PlanObjects.Add(dbChildObject); } childObject.ExportToDbObject(dbChildObject, context, childOrder++); } }
private BaseObject SavePlanObjectToDb(string id, BaseObject planObject) { BaseObject res; var plan = new PlanObject(); using (var context = new PlansDc(_esterConnectionString)) { if (!string.IsNullOrEmpty(id)) plan = GetPlanObjectById(id, context); else context.PlanObjects.InsertOnSubmit(plan); planObject.ExportToDbObject(plan, context); context.SubmitChanges(); res = ServerExtensions.FromDbObject(plan); } if (_eventAggregator != null) _eventAggregator.GetEvent<PlansModifiedEvent>().Publish(planObject); return res; }
private void DeleteChilds(PlanObject plan, PlansDc context) { foreach (var child in plan.PlanObjects) { DeleteChilds(child, context); context.PlanObjects.DeleteOnSubmit(child); } }
partial void DeletePlanObject(PlanObject instance);
partial void UpdatePlanObject(PlanObject instance);
partial void InsertPlanObject(PlanObject instance);
private void detach_PlanObjects(PlanObject entity) { this.SendPropertyChanging(); entity.Parent = null; }
private void attach_PlanObjects(PlanObject entity) { this.SendPropertyChanging(); entity.Parent = this; }