예제 #1
0
        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;
        }
예제 #2
0
        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++);
            }
        }
예제 #3
0
 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;
 }
예제 #4
0
 private void DeleteChilds(PlanObject plan, PlansDc context)
 {
     foreach (var child in plan.PlanObjects)
     {
         DeleteChilds(child, context);
         context.PlanObjects.DeleteOnSubmit(child);
     }
 }
예제 #5
0
 partial void DeletePlanObject(PlanObject instance);
예제 #6
0
 partial void UpdatePlanObject(PlanObject instance);
예제 #7
0
 partial void InsertPlanObject(PlanObject instance);
예제 #8
0
		private void detach_PlanObjects(PlanObject entity)
		{
			this.SendPropertyChanging();
			entity.Parent = null;
		}
예제 #9
0
		private void attach_PlanObjects(PlanObject entity)
		{
			this.SendPropertyChanging();
			entity.Parent = this;
		}