public void RequestExtension (TComponentExtension componentExtension) { if (componentExtension.NotNull ()) { // request CategoryRelation (Extension) var categoryValue = TCategoryType.ToValue (CategoryType.Category); var categoryRelationList = CollectionAction.CategoryRelationCollection .Where (p => p.Category.Equals (categoryValue)) .ToList () ; if (categoryRelationList.Count.Equals (1)) { var categoryRelation = categoryRelationList [0]; // get extension using TComponentExtension var extension = TComponentExtension.Create (categoryRelation.Extension); extension.Request (); componentExtension.CopyFrom (extension); } } }
// TODO: serve para que???? public override void SelectItem (TEntityAction action) { if (action.NotNull ()) { var categoryValue = TCategoryType.ToValue (action.CategoryType.Category); // Extension (CategoryRelationCollection) var categoryRelationList = action.CollectionAction.CategoryRelationCollection .Where (p => p.Category.Equals (categoryValue)) .ToList () ; if (categoryRelationList.Count.Equals (1)) { var categoryRelation = categoryRelationList [0]; // get extension using TComponentExtension var extension = TComponentExtension.Create (categoryRelation.Extension); extension.Request (); foreach (var item in action.CollectionAction.ModelCollection) { var modelStyle = TContentStyle.NONE; switch (StyleInfo.StyleMode) { case TContentStyle.Mode.Horizontal: modelStyle = item.Value.ExtensionLayoutModel.StyleHorizontal; break; case TContentStyle.Mode.Vertical: modelStyle = item.Value.ExtensionLayoutModel.StyleVertical; break; } if (modelStyle.Equals (StyleInfo.StyleString, StringComparison.InvariantCulture)) { } } } } }
void SelectSummary (TModelContext context, TEntityAction action) { /* DATA IN - action.Summary DATA OUT - action.Summary - action.CollectionAction.ComponentInfoCollection - action.CollectionAction.ComponentStatusCollection */ try { action.CollectionAction.ComponentInfoCollection.Clear (); action.CollectionAction.ComponentStatusCollection.Clear (); var categoryValue = TCategoryType.ToValue (action.SupportAction.SummaryInfo.Category); // search Id by category var descriptors = context.ComponentDescriptor.AsQueryable() .Where (p => p.Category.Equals (categoryValue)) .ToList () ; foreach (var descriptor in descriptors) { // Info var infoList = context.ComponentInfo.AsQueryable() .Where (p => p.Id.Equals (descriptor.Id)) .ToList () ; // info found if (infoList.Count.Equals (1)) { var infoModel = infoList [0]; action.CollectionAction.ComponentInfoCollection.Add (infoModel); } // Status var statusList = context.ComponentStatus.AsQueryable() .Where (p => p.Id.Equals (descriptor.Id)) .ToList () ; // status found if (statusList.Count.Equals (1)) { var statusModel = statusList [0]; action.CollectionAction.ComponentStatusCollection.Add (statusModel); } } // apply zap var enabledZap = new Collection<Guid> (); var busyZap = new Collection<Guid> (); // zap Enabled = false (disable) if (action.SupportAction.SummaryInfo.ZapDisable) { foreach (var itemInfo in action.CollectionAction.ComponentInfoCollection) { // only Enabled if (itemInfo.Enabled.IsFalse ()) { enabledZap.Add (itemInfo.Id); } } } // zap Busy = true if (action.SupportAction.SummaryInfo.ZapBusy) { foreach (var itemStatus in action.CollectionAction.ComponentStatusCollection) { // only not busy if (itemStatus.Busy) { busyZap.Add (itemStatus.Id); } } } foreach (var id in enabledZap) { var list = action.CollectionAction.ComponentInfoCollection .Where (p => p.Id.Equals (id)) .ToList () ; if (list.Count.Equals (1)) { action.CollectionAction.ComponentInfoCollection.Remove (list [0]); } } foreach (var id in busyZap) { var list = action.CollectionAction.ComponentInfoCollection .Where (p => p.Id.Equals (id)) .ToList () ; if (list.Count.Equals (1)) { action.CollectionAction.ComponentInfoCollection.Remove (list [0]); } } // Extension (CategoryRelationCollection) var categoryRelationList = action.CollectionAction.CategoryRelationCollection .Where (p => p.Category.Equals (categoryValue)) .ToList () ; // found if (categoryRelationList.Count.Equals (1)) { var categoryRelation = categoryRelationList [0]; // get extension using TComponentExtension var extension = TComponentExtension.Create (categoryRelation.Extension); extension.Request (); foreach (var item in action.CollectionAction.ComponentInfoCollection) { var id = item.Id; action.CollectionAction.ExtensionLayoutCollection.Clear (); // check for style only foreach (var extensionName in extension.ExtensionList) { switch (extensionName) { case TComponentExtensionNames.Layout: { var list = context.ExtensionLayout.AsQueryable() .Where (p => p.Id.Equals (id)) .ToList () ; if (list.Count.Equals (1)) { action.CollectionAction.ExtensionLayoutCollection.Add (list [0]); } } break; } } foreach (var layout in action.CollectionAction.ExtensionLayoutCollection) { action.SupportAction.SummaryInfo.Select (layout.StyleHorizontal, layout.StyleVertical); } } } action.Result = TValidationResult.Success; } catch (Exception exception) { Server.Models.Infrastructure.THelper.FormatException ("Select Summary", exception, action); } }
void SelectZap (TModelContext context, TEntityAction action) { /* DATA IN: action.IdCollection {id to zap} action.CategoryType DATA OUT: action.CollectionAction.ModelCollection [id] {Model} */ try { action.CollectionAction.ModelCollection.Clear (); var categoryValue = TCategoryType.ToValue (action.CategoryType.Category); // search Id by category var descriptors = context.ComponentDescriptor.AsQueryable() .Where (p => p.Category.Equals (categoryValue)) .ToList () ; // zap foreach (var idToZap in action.IdCollection) { var zapList = descriptors .Where (p => p.Id.Equals (idToZap)) .ToList () ; // found if (zapList.Count.Equals (1)) { // update descriptors descriptors.Remove (zapList [0]); } } // Component Info, Status action.CollectionAction.ComponentInfoCollection.Clear (); action.CollectionAction.ComponentStatusCollection.Clear (); foreach (var descriptor in descriptors) { // Info var infoList = context.ComponentInfo.AsQueryable() .Where (p => p.Id.Equals (descriptor.Id)) .ToList () ; // Status var statusList = context.ComponentStatus.AsQueryable() .Where (p => p.Id.Equals (descriptor.Id)) .ToList () ; // info found if (infoList.Count.Equals (1)) { var infoModel = infoList [0]; action.CollectionAction.ComponentInfoCollection.Add (infoModel); } // status found if (statusList.Count.Equals (1)) { var statusModel = statusList [0]; action.CollectionAction.ComponentStatusCollection.Add (statusModel); } } // Extension (CategoryRelationCollection) var categoryRelationList = action.CollectionAction.CategoryRelationCollection .Where (p => p.Category.Equals (categoryValue)) .ToList () ; // found if (categoryRelationList.Count.Equals (1)) { var categoryRelation = categoryRelationList [0]; // get extension using TComponentExtension var extension = TComponentExtension.Create (categoryRelation.Extension); extension.Request (); foreach (var item in action.CollectionAction.ComponentInfoCollection) { var id = item.Id; foreach (var extensionName in extension.ExtensionList) { switch (extensionName) { //case TComponentExtensionNames.Document: { // var list = context.ExtensionDocument // .Where (p => p.Id.Equals (id)) // .ToList () // ; // if (list.Count.Equals (1)) { // action.CollectionAction.ExtensionDocumentCollection.Add (list [0]); // } // } // break; case TComponentExtensionNames.Geometry: { var list = context.ExtensionGeometry.AsQueryable() .Where (p => p.Id.Equals (id)) .ToList () ; if (list.Count.Equals (1)) { action.CollectionAction.ExtensionGeometryCollection.Add (list [0]); } } break; case TComponentExtensionNames.Image: { var list = context.ExtensionImage.AsQueryable().Where (p => p.Id.Equals (id)).ToList (); if (list.Count.Equals (1)) { action.CollectionAction.ExtensionImageCollection.Add (list [0]); } } break; case TComponentExtensionNames.Layout: { var list = context.ExtensionLayout.AsQueryable() .Where (p => p.Id.Equals (id)) .ToList () ; if (list.Count.Equals (1)) { action.CollectionAction.ExtensionLayoutCollection.Add (list [0]); } } break; case TComponentExtensionNames.Node: { // child first var childList = context.ExtensionNode.AsQueryable() .Where (p => p.ChildId.Equals (id)) .ToList () ; if (childList.Count.Equals (1)) { action.ModelAction.ExtensionNodeModel.CopyFrom (childList [0]); action.CollectionAction.ExtensionNodeCollection.Add (childList [0]); } else { // parent next var parentList = context.ExtensionNode.AsQueryable() .Where (p => p.ParentId.Equals (id)) .ToList () ; foreach (var model in parentList) { action.CollectionAction.ExtensionNodeCollection.Add (model); } } } break; case TComponentExtensionNames.Text: { var list = context.ExtensionText.AsQueryable() .Where (p => p.Id.Equals (id)) .ToList () ; if (list.Count.Equals (1)) { action.CollectionAction.ExtensionTextCollection.Add (list [0]); } } break; case TComponentExtensionNames.Content: { var list = context.ExtensionContent.AsQueryable() .Where (p => p.Id.Equals (id)) .ToList () ; if (list.Count.Equals (1)) { action.CollectionAction.ExtensionContentCollection.Add (list [0]); } } break; } } } } // populate ModelCollection action.CollectionAction.ModelCollection.Clear (); var componentExtension = TComponentExtension.CreateDefault; action.RequestExtension (componentExtension); foreach (var item in action.CollectionAction.ComponentInfoCollection) { // component // Info var id = item.Id; var models = TModelAction.CreateDefault; models.ComponentInfoModel.CopyFrom (item); // Status var statusList = action.CollectionAction.ComponentStatusCollection .Where (p => p.Id.Equals (id)) .ToList () ; // found if (statusList.Count.Equals (1)) { models.ComponentStatusModel.CopyFrom (statusList [0]); } // extension foreach (var extensionName in componentExtension.ExtensionList) { switch (extensionName) { case TComponentExtensionNames.Document: { //var list = action.CollectionAction.ExtensionDocumentCollection // .Where (p => p.Id.Equals (id)) // .ToList () //; //if (list.Count.Equals (1)) { // models.ExtensionDocumentModel.CopyFrom (list [0]); //} } break; case TComponentExtensionNames.Geometry: { var list = action.CollectionAction.ExtensionGeometryCollection .Where (p => p.Id.Equals (id)) .ToList () ; if (list.Count.Equals (1)) { models.ExtensionGeometryModel.CopyFrom (list [0]); } } break; case TComponentExtensionNames.Image: { var list = action.CollectionAction.ExtensionImageCollection .Where (p => p.Id.Equals (id)) .ToList () ; if (list.Count.Equals (1)) { models.ExtensionImageModel.CopyFrom (list [0]); } } break; case TComponentExtensionNames.Layout: { var list = action.CollectionAction.ExtensionLayoutCollection .Where (p => p.Id.Equals (id)) .ToList () ; if (list.Count.Equals (1)) { models.ExtensionLayoutModel.CopyFrom (list [0]); } } break; case TComponentExtensionNames.Node: { // child var list = action.CollectionAction.ExtensionNodeCollection .Where (p => p.ChildId.Equals (id)) .ToList () ; if (list.Count.Equals (1)) { models.ExtensionNodeModel.CopyFrom (list [0]); } } break; case TComponentExtensionNames.Text: { var list = action.CollectionAction.ExtensionTextCollection .Where (p => p.Id.Equals (id)) .ToList () ; if (list.Count.Equals (1)) { models.ExtensionTextModel.CopyFrom (list [0]); } } break; case TComponentExtensionNames.Content: { var list = action.CollectionAction.ExtensionContentCollection .Where (p => p.Id.Equals (id)) .ToList () ; if (list.Count.Equals (1)) { models.ExtensionContentModel.CopyFrom (list [0]); } } break; } } action.CollectionAction.ModelCollection.Add (id, models); } action.Result = TValidationResult.Success; } catch (Exception exception) { Server.Models.Infrastructure.THelper.FormatException ("Select Zap", exception, action); } }
void CollectionFull (TModelContext context, TEntityAction action) { /* DATA IN: action.Operation.CategoryType.Category action.CollectionAction.CategoryRelationCollection */ try { // select Id by Category var categoryValue = TCategoryType.ToValue (action.Operation.CategoryType.Category); var descriptors = context.ComponentDescriptor.AsQueryable() .Where (p => p.Category.Equals (categoryValue)) .ToList () ; // found if (descriptors.Any ()) { // Component Info, Status action.CollectionAction.ComponentInfoCollection.Clear (); action.CollectionAction.ComponentStatusCollection.Clear (); foreach (var descriptor in descriptors) { // Info var infoList = context.ComponentInfo.AsQueryable() .Where (p => p.Id.Equals (descriptor.Id)) .ToList () ; // Status var statusList = context.ComponentStatus.AsQueryable() .Where (p => p.Id.Equals (descriptor.Id)) .ToList () ; // info found if (infoList.Count.Equals (1)) { var infoModel = infoList [0]; action.CollectionAction.ComponentInfoCollection.Add (infoModel); } // status found if (statusList.Count.Equals (1)) { var statusModel = statusList [0]; action.CollectionAction.ComponentStatusCollection.Add (statusModel); } } // Component Relation // by Category action.CollectionAction.ComponentOperation.Clear (); action.CollectionAction.SelectComponentOperation (TComponentOperation.TInternalOperation.Category); action.CollectionAction.ComponentOperation.SelectByCategory (categoryValue); var componentRelationFullList = context.ComponentRelation .ToList () ; foreach (var itemCategory in action.CollectionAction.ComponentOperation.CategoryCollection) { // parent var parentList = componentRelationFullList .Where (p => p.ParentCategory.Equals (itemCategory)) .ToList () ; action.CollectionAction.ComponentOperation.SelectParent (itemCategory, parentList); // child var childList = componentRelationFullList .Where (p => p.ChildCategory.Equals (itemCategory)) .ToList () ; action.CollectionAction.ComponentOperation.SelectChild (itemCategory, childList); } // Extension (CategoryRelationCollection) var categoryRelationList = action.CollectionAction.CategoryRelationCollection .Where (p => p.Category.Equals (categoryValue)) .ToList () ; // found if (categoryRelationList.Count.Equals (1)) { var categoryRelation = categoryRelationList [0]; // get extension using TComponentExtension var extension = TComponentExtension.Create (categoryRelation.Extension); extension.Request (); foreach (var item in action.CollectionAction.ComponentInfoCollection) { var id = item.Id; // Status var compStatus = Models.Component.ComponentStatus.CreateDefault; var statusList = action.CollectionAction.ComponentStatusCollection .Where (p => p.Id.Equals (id)) .ToList () ; if (statusList.Count.Equals (1)) { compStatus.CopyFrom (statusList [0]); } foreach (var extensionName in extension.ExtensionList) { switch (extensionName) { case TComponentExtensionNames.Document: { //var list = context.ExtensionDocument // .Where (p => p.Id.Equals (id)) // .ToList () //; //if (list.Count.Equals (1)) { // action.CollectionAction.ExtensionDocumentCollection.Add (list [0]); //} } break; case TComponentExtensionNames.Geometry: { var list = context.ExtensionGeometry.AsQueryable() .Where (p => p.Id.Equals (id)) .ToList () ; if (list.Count.Equals (1)) { action.CollectionAction.ExtensionGeometryCollection.Add (list [0]); } } break; case TComponentExtensionNames.Image: { var list = context.ExtensionImage.AsQueryable() .Where (p => p.Id.Equals (id)) .ToList () ; if (list.Count.Equals (1)) { action.CollectionAction.ExtensionImageCollection.Add (list [0]); } } break; case TComponentExtensionNames.Layout: { var list = context.ExtensionLayout.AsQueryable() .Where (p => p.Id.Equals (id)) .ToList () ; if (list.Count.Equals (1)) { action.CollectionAction.ExtensionLayoutCollection.Add (list [0]); } } break; case TComponentExtensionNames.Node: { var nodeModeldList = context.ExtensionNode.AsQueryable() .Where (p => p.ParentId.Equals (id)) .ToList () ; // Node Reverse if (compStatus.NodeReverse) { nodeModeldList = context.ExtensionNode.AsQueryable() .Where (p => p.ChildId.Equals (id)) .ToList () ; } // Node Model if (compStatus.UseNodeModel) { if (nodeModeldList.Count.Equals (1)) { action.ModelAction.ExtensionNodeModel.CopyFrom (nodeModeldList [0]); action.CollectionAction.ExtensionNodeCollection.Add (nodeModeldList [0]); } } // Node Collection if (compStatus.UseNodeCollection) { foreach (var nodeModel in nodeModeldList) { action.CollectionAction.ExtensionNodeCollection.Add (nodeModel); } } } break; case TComponentExtensionNames.Text: { var list = context.ExtensionText.AsQueryable() .Where (p => p.Id.Equals (id)) .ToList () ; if (list.Count.Equals (1)) { action.CollectionAction.ExtensionTextCollection.Add (list [0]); } } break; case TComponentExtensionNames.Content: { var list = context.ExtensionContent.AsQueryable() .Where (p => p.Id.Equals (id)) .ToList () ; if (list.Count.Equals (1)) { action.CollectionAction.ExtensionContentCollection.Add (list [0]); } } break; } } } } // populate ModelCollection action.CollectionAction.ModelCollection.Clear (); var componentExtension = TComponentExtension.CreateDefault; action.RequestExtension (componentExtension); foreach (var item in action.CollectionAction.ComponentInfoCollection) { // component // Info var id = item.Id; var models = TModelAction.CreateDefault; models.ComponentInfoModel.CopyFrom (item); // Status var compStatus = ComponentStatus.CreateDefault; var statusList = action.CollectionAction.ComponentStatusCollection .Where (p => p.Id.Equals (id)) .ToList () ; // found if (statusList.Count.Equals (1)) { models.ComponentStatusModel.CopyFrom (statusList [0]); compStatus.CopyFrom (statusList [0]); } // extension foreach (var extensionName in componentExtension.ExtensionList) { switch (extensionName) { case TComponentExtensionNames.Document: { //var list = action.CollectionAction.ExtensionDocumentCollection // .Where (p => p.Id.Equals (id)) // .ToList () //; //if (list.Count.Equals (1)) { // models.ExtensionDocumentModel.CopyFrom (list [0]); //} } break; case TComponentExtensionNames.Geometry: { var list = action.CollectionAction.ExtensionGeometryCollection .Where (p => p.Id.Equals (id)) .ToList () ; if (list.Count.Equals (1)) { models.ExtensionGeometryModel.CopyFrom (list [0]); } } break; case TComponentExtensionNames.Image: { var list = action.CollectionAction.ExtensionImageCollection .Where (p => p.Id.Equals (id)) .ToList () ; if (list.Count.Equals (1)) { models.ExtensionImageModel.CopyFrom (list [0]); } } break; case TComponentExtensionNames.Layout: { var list = action.CollectionAction.ExtensionLayoutCollection .Where (p => p.Id.Equals (id)) .ToList () ; if (list.Count.Equals (1)) { models.ExtensionLayoutModel.CopyFrom (list [0]); } } break; case TComponentExtensionNames.Node: { var nodeModellist = action.CollectionAction.ExtensionNodeCollection .Where (p => p.ParentId.Equals (id)) .ToList () ; if (compStatus.NodeReverse) { nodeModellist = action.CollectionAction.ExtensionNodeCollection .Where (p => p.ChildId.Equals (id)) .ToList () ; } if (compStatus.UseNodeModel) { if (nodeModellist.Count.Equals (1)) { models.ExtensionNodeModel.CopyFrom (nodeModellist [0]); } } } break; case TComponentExtensionNames.Text: { var list = action.CollectionAction.ExtensionTextCollection .Where (p => p.Id.Equals (id)) .ToList () ; if (list.Count.Equals (1)) { models.ExtensionTextModel.CopyFrom (list [0]); } } break; case TComponentExtensionNames.Content: { var list = action.CollectionAction.ExtensionContentCollection .Where (p => p.Id.Equals (id)) .ToList () ; if (list.Count.Equals (1)) { models.ExtensionContentModel.CopyFrom (list [0]); } } break; } } action.CollectionAction.ModelCollection.Add (id, models); } } // ComponentOperation - Operation.Category if (action.CollectionAction.ComponentOperation.IsComponentOperation (TComponentOperation.TInternalOperation.Category)) { action.IdCollection.Clear (); var list = new Collection<ComponentRelation> (action.CollectionAction.ComponentOperation.RequestParentCategoryCollection ()); foreach (var relation in list) { if (relation.ChildId.NotEmpty ()) { action.IdCollection.Add (relation.ChildId); } } } action.Result = TValidationResult.Success; } catch (Exception exception) { Models.Infrastructure.THelper.FormatException ("Collection Full", exception, action); } }
void CollectionMinimum (TModelContext context, TEntityAction action) { /* DATA IN: action.Operation.CategoryType.Category action.CollectionAction.CategoryRelationCollection */ try { // select Id by Category var categoryValue = TCategoryType.ToValue (action.Operation.CategoryType.Category); var descriptors = context.ComponentDescriptor.AsQueryable() .Where (p => p.Category.Equals (categoryValue)) .ToList () ; // found if (descriptors.Any ()) { // Component Info, Status action.CollectionAction.ComponentInfoCollection.Clear (); action.CollectionAction.ComponentStatusCollection.Clear (); foreach (var descriptor in descriptors) { // Info var infoList = context.ComponentInfo.AsQueryable() .Where (p => p.Id.Equals (descriptor.Id)) .ToList () ; // Status var statusList = context.ComponentStatus.AsQueryable() .Where (p => p.Id.Equals (descriptor.Id)) .ToList () ; // info found if (infoList.Count.Equals (1)) { var infoModel = infoList [0]; action.CollectionAction.ComponentInfoCollection.Add (infoModel); } // status found if (statusList.Count.Equals (1)) { var statusModel = statusList [0]; action.CollectionAction.ComponentStatusCollection.Add (statusModel); } } // Extension (CategoryRelationCollection) var categoryRelationList = action.CollectionAction.CategoryRelationCollection .Where (p => p.Category.Equals (categoryValue)) .ToList () ; // found if (categoryRelationList.Count.Equals (1)) { var categoryRelation = categoryRelationList [0]; // get extension using TComponentExtension var extension = TComponentExtension.Create (categoryRelation.Extension); extension.Request (); foreach (var item in action.CollectionAction.ComponentInfoCollection) { var id = item.Id; foreach (var extensionName in extension.ExtensionList) { switch (extensionName) { case TComponentExtensionNames.Layout: { var list = context.ExtensionLayout.AsQueryable() .Where (p => p.Id.Equals (id)) .ToList () ; if (list.Count.Equals (1)) { action.CollectionAction.ExtensionLayoutCollection.Add (list [0]); } } break; } } } } // populate ModelCollection action.CollectionAction.ModelCollection.Clear (); var componentExtension = TComponentExtension.CreateDefault; action.RequestExtension (componentExtension); foreach (var item in action.CollectionAction.ComponentInfoCollection) { // component // Info var id = item.Id; var models = TModelAction.CreateDefault; models.ComponentInfoModel.CopyFrom (item); // Status var statusList = action.CollectionAction.ComponentStatusCollection .Where (p => p.Id.Equals (id)) .ToList () ; // found if (statusList.Count.Equals (1)) { models.ComponentStatusModel.CopyFrom (statusList [0]); } // extension foreach (var extensionName in componentExtension.ExtensionList) { switch (extensionName) { case TComponentExtensionNames.Layout: { var list = action.CollectionAction.ExtensionLayoutCollection .Where (p => p.Id.Equals (id)) .ToList () ; if (list.Count.Equals (1)) { models.ExtensionLayoutModel.CopyFrom (list [0]); } } break; } } action.CollectionAction.ModelCollection.Add (id, models); } } action.Result = TValidationResult.Success; } catch (Exception exception) { Models.Infrastructure.THelper.FormatException ("Collection Full", exception, action); } }
static void ModifyContent (TModelContext context, TEntityAction action) { /* DATA IN - action.Id (Component id to change) - action.ModelAction (Component model) (only Content extension) */ var id = action.Id; try { //Component Id must exist if (id.IsEmpty ()) { action.Result = new TValidationResult ($"[{action.Operation.CategoryType.Category} - Modify] Component Id can NOT be NULL or EMPTY!"); } else { // search Id var descriptors = context.ComponentDescriptor.AsQueryable () .Where (p => p.Id.Equals (id)) .ToList () ; // Descriptor found if (descriptors.Count.Equals (1)) { var descriptor = descriptors [0]; var categoryValue = descriptor.Category; // extensions // search for extensions var categoryRelationList = action.CollectionAction.CategoryRelationCollection .Where (p => p.Category.Equals (categoryValue)) .ToList () ; // found if (categoryRelationList.Count.Equals (1)) { var categoryRelation = categoryRelationList [0]; // get extension using TComponentExtension var extension = TComponentExtension.Create (categoryRelation.Extension); extension.Request (); foreach (var extensionName in extension.ExtensionList) { switch (extensionName) { case TComponentExtensionNames.Content: { var list = context.ExtensionContent.AsQueryable () .Where (p => p.Id.Equals (id)) .ToList () ; if (list.Count.Equals (1)) { var model = list [0]; model.Change (action.ModelAction.ExtensionContentModel); context.ExtensionContent.Update (model); // change model } } break; } } } context.SaveChanges (); // update action.Result = TValidationResult.Success; } } } catch (Exception exception) { Models.Infrastructure.THelper.FormatException ("Modify", exception, action); } }
static void ChangeFull (TModelContext context, TEntityAction action) { /* DATA IN - action.Id (Component id to change) - action.ModelAction (Component model) */ //validate Name if (ValidateString (action)) { var id = action.Id; try { //Component Id must exist if (id.IsEmpty ()) { action.Result = new TValidationResult ($"[{action.Operation.CategoryType.Category} - Change Full] Component Id can NOT be NULL or EMPTY!"); } else { // search Id var descriptors = context.ComponentDescriptor.AsQueryable().AsQueryable() .Where (p => p.Id.Equals (id)) .ToList () ; // Descriptor found if (descriptors.Count.Equals (1)) { var descriptor = descriptors [0]; var categoryValue = descriptor.Category; // Info var infoList = context.ComponentInfo.AsQueryable () .Where (p => p.Id.Equals (id)) .ToList () ; // Info found if (infoList.Count.Equals (1)) { var model = infoList [0]; model.Change (action.ModelAction.ComponentInfoModel); context.ComponentInfo.Update (model);// change Info model } // Status var compStatus = ComponentStatus.CreateDefault; var statusList = context.ComponentStatus.AsQueryable () .Where (p => p.Id.Equals (id)) .ToList () ; // Status found if (statusList.Count.Equals (1)) { var model = statusList [0]; model.Change (action.ModelAction.ComponentStatusModel); context.ComponentStatus.Update (model);// change Status model compStatus.CopyFrom (model); } // status collection foreach (var item in action.CollectionAction.ComponentStatusCollection) { var list = context.ComponentStatus.AsQueryable () .Where (p => p.Id.Equals (item.Id)) .ToList () ; // Status found if (list.Count.Equals (1)) { var model = list [0]; model.Change (item); context.ComponentStatus.Update (model);// change Status model } } context.SaveChanges (); // save here // Component Relation Collection //remove old first (Parent) var relationList = context.ComponentRelation.AsQueryable () .Where (p => p.ParentId.Equals (id)) .ToList () ; foreach (var relation in relationList) { // change old child status busy to false var childList = context.ComponentStatus.AsQueryable () .Where (p => p.Id.Equals (relation.ChildId)) .ToList () ; // found if (childList.Count.Equals (1)) { var child = childList [0]; child.Busy = false; context.ComponentStatus.Update (child); // update } context.ComponentRelation.Remove (relation); // remove old } // insert new foreach (var item in action.CollectionAction.ComponentRelationCollection) { // change child status busy to true var childList = context.ComponentStatus.AsQueryable () .Where (p => p.Id.Equals (item.ChildId)) .ToList () ; // found if (childList.Count.Equals (1)) { var child = childList [0]; child.Busy = true; context.ComponentStatus.Update (child); // update } item.ParentId = id; context.ComponentRelation.Add (item); // insert new } // extensions // search for extensions var categoryRelationList = action.CollectionAction.CategoryRelationCollection .Where (p => p.Category.Equals (categoryValue)) .ToList () ; // found if (categoryRelationList.Count.Equals (1)) { var categoryRelation = categoryRelationList [0]; // get extension using TComponentExtension var extension = TComponentExtension.Create (categoryRelation.Extension); extension.Request (); foreach (var extensionName in extension.ExtensionList) { switch (extensionName) { //case TComponentExtensionNames.Document: { // var list = context.ExtensionDocument // .Where (p => p.Id.Equals (id)) // .ToList () // ; // if (list.Count.Equals (1)) { // var model = list [0]; // model.Change (action.ModelAction.ExtensionDocumentModel); // context.ExtensionDocument.Update (model); // change model // } // } // break; case TComponentExtensionNames.Geometry: { var list = context.ExtensionGeometry.AsQueryable () .Where (p => p.Id.Equals (id)) .ToList () ; if (list.Count.Equals (1)) { var model = list [0]; model.Change (action.ModelAction.ExtensionGeometryModel); context.ExtensionGeometry.Update (model); // change model } } break; case TComponentExtensionNames.Image: { var list = context.ExtensionImage.AsQueryable () .Where (p => p.Id.Equals (id)) .ToList () ; if (list.Count.Equals (1)) { var model = list [0]; model.Change (action.ModelAction.ExtensionImageModel); context.ExtensionImage.Update (model); // change model } } break; case TComponentExtensionNames.Layout: { var list = context.ExtensionLayout.AsQueryable () .Where (p => p.Id.Equals (id)) .ToList () ; if (list.Count.Equals (1)) { var model = list [0]; model.Change (action.ModelAction.ExtensionLayoutModel); context.ExtensionLayout.Update (model); // change model } } break; case TComponentExtensionNames.Node: { // Node reverse if (compStatus.NodeReverse) { // remove old first (use ChildId) var nodeList = context.ExtensionNode.AsQueryable () .Where (p => p.ChildId.Equals (id)) .ToList () ; // found if (nodeList.Count.Equals (1)) { var node = nodeList [0]; // remove context.ExtensionNode.Remove (node); context.SaveChanges (); // update var nodeListParent = context.ExtensionNode.AsQueryable() .Where (p => p.ParentId.Equals (node.ParentId)) .ToList () ; // just me if (nodeListParent.Count.Equals (1)) { // status var list = context.ComponentStatus.AsQueryable() .Where (p => p.Id.Equals (node.ParentId)) .ToList () ; // found (just one) if (list.Count.Equals (1)) { var model = list [0]; model.Busy = false; context.ComponentStatus.Update (model); } } } // next insert new foreach (var node in action.CollectionAction.ExtensionNodeCollection) { // validate same if (node.ChildId.Equals (id)) { context.ExtensionNode.Add (node); break; // just one } } context.SaveChanges (); // update // update status nodeList = context.ExtensionNode.AsQueryable() .Where (p => p.ChildId.Equals (id)) .ToList () ; // found (just one) if (nodeList.Count.Equals (1)) { var node = nodeList [0]; var list = context.ComponentStatus.AsQueryable() .Where (p => p.Id.Equals (node.ParentId)) .ToList () ; // found (just one) if (list.Count.Equals (1)) { var model = list [0]; model.Busy = true; context.ComponentStatus.Update (model); } } } else { // remove old first (use ParentId) var nodeList = context.ExtensionNode.AsQueryable() .Where (p => p.ParentId.Equals (id)) .ToList () ; foreach (var node in nodeList) { // status var list = context.ComponentStatus.AsQueryable() .Where (p => p.Id.Equals (node.ChildId)) .ToList () ; // found if (list.Count.Equals (1)) { var model = list [0]; model.Busy = false; context.ComponentStatus.Update (model); } // remove Node context.ExtensionNode.Remove (node); } // next insert new foreach (var node in action.CollectionAction.ExtensionNodeCollection) { // validate same parent if (node.ParentId.Equals (id)) { context.ExtensionNode.Add (node); } } context.SaveChanges (); // update // update status nodeList = context.ExtensionNode.AsQueryable() .Where (p => p.ParentId.Equals (id)) .ToList () ; foreach (var node in nodeList) { var list = context.ComponentStatus.AsQueryable() .Where (p => p.Id.Equals (node.ChildId)) .ToList () ; // found if (list.Count.Equals (1)) { var model = list [0]; model.Busy = true; context.ComponentStatus.Update (model); } } } } break; case TComponentExtensionNames.Text: { var list = context.ExtensionText.AsQueryable() .Where (p => p.Id.Equals (id)) .ToList () ; if (list.Count.Equals (1)) { var model = list [0]; model.Change (action.ModelAction.ExtensionTextModel); context.ExtensionText.Update (model); // change model } } break; case TComponentExtensionNames.Content: { var list = context.ExtensionContent.AsQueryable() .Where (p => p.Id.Equals (id)) .ToList () ; if (list.Count.Equals (1)) { var model = list [0]; model.Change (action.ModelAction.ExtensionContentModel); context.ExtensionContent.Update (model); // change model } } break; } } } context.SaveChanges (); // update action.Result = TValidationResult.Success; } } } catch (Exception exception) { Models.Infrastructure.THelper.FormatException ("Change - Full", exception, action); } } }
static bool RequestExtension (int categoryValue, Guid id, TModelContext context, TEntityAction action, TModelAction modelAction) { /* DATA OUT - action.ModelAction (model) - action.CollectionAction.ExtensionNodeCollection - action.ComponentModel.NodeModelCollection */ var res = false; // Extension (CategoryRelationCollection) var categoryRelationList = action.CollectionAction.CategoryRelationCollection .Where (p => p.Category.Equals (categoryValue)) .ToList () ; // found if (categoryRelationList.Count.Equals (1)) { var categoryRelation = categoryRelationList [0]; // get extension using TComponentExtension var extension = TComponentExtension.Create (categoryRelation.Extension); extension.Request (); try { foreach (var extensionName in extension.ExtensionList) { switch (extensionName) { //case TComponentExtensionNames.Document: { // var list = context.ExtensionDocument // .Where (p => p.Id.Equals (id)) // .ToList () // ; // if (list.Count.Equals (1)) { // modelAction.ExtensionDocumentModel.CopyFrom (list [0]); // } // } // break; case TComponentExtensionNames.Geometry: { var list = context.ExtensionGeometry.AsQueryable() .Where (p => p.Id.Equals (id)) .ToList () ; if (list.Count.Equals (1)) { modelAction.ExtensionGeometryModel.CopyFrom (list [0]); } } break; case TComponentExtensionNames.Image: { var list = context.ExtensionImage.AsQueryable() .Where (p => p.Id.Equals (id)) .ToList () ; if (list.Count.Equals (1)) { modelAction.ExtensionImageModel.CopyFrom (list [0]); } } break; case TComponentExtensionNames.Layout: { var list = context.ExtensionLayout.AsQueryable() .Where (p => p.Id.Equals (id)) .ToList () ; if (list.Count.Equals (1)) { modelAction.ExtensionLayoutModel.CopyFrom (list [0]); } } break; case TComponentExtensionNames.Node: { // child first var childList = context.ExtensionNode.AsQueryable() .Where (p => p.ChildId.Equals (id)) .ToList () ; if (childList.Count.Equals (1)) { var node = childList [0]; modelAction.ExtensionNodeModel.CopyFrom (node); // check duplicated //var list = action.CollectionAction.ExtensionNodeCollection // .Where (p => p.ChildId.Equals (id)) // .ToList () //; //if (list.Count.Equals (0)) { // action.CollectionAction.ExtensionNodeCollection.Add (node); // action.ComponentModel.NodeModelCollection.Add (node); //} } //else { // // parent next // //var parentList = context.ExtensionNode.AsQueryable() // // .Where (p => p.ParentId.Equals (id)) // // .ToList () // //; // //foreach (var node in parentList) { // // // check duplicated // // var list = action.CollectionAction.ExtensionNodeCollection // // .Where (p => p.ChildId.Equals (node.ChildId)) // // .ToList () // // ; // // if (list.Count.Equals (0)) { // // action.CollectionAction.ExtensionNodeCollection.Add (node); // // action.ComponentModel.NodeModelCollection.Add (node); // // } // //} //} } break; case TComponentExtensionNames.Text: { var list = context.ExtensionText.AsQueryable() .Where (p => p.Id.Equals (id)) .ToList () ; if (list.Count.Equals (1)) { modelAction.ExtensionTextModel.CopyFrom (list [0]); } } break; case TComponentExtensionNames.Content: { var list = context.ExtensionContent.AsQueryable() .Where (p => p.Id.Equals (id)) .ToList () ; if (list.Count.Equals (1)) { modelAction.ExtensionContentModel.CopyFrom (list [0]); } } break; } } res = true; } catch (Exception exception) { THelper.FormatException ("RequestExtension - TOperationSupport", exception, action); } } return (res); }
void Insert (TModelContext context, TEntityAction action) { /* DATA IN: - action.Operation.CategoryType.Category - action.CollectionAction.CategoryRelationCollection - action.ModelAction - action.CollectionAction.ExtensionNodeCollection */ try { // Validate Name if (ValidateString (action)) { //Id var id = Guid.NewGuid (); var categoryValue = TCategoryType.ToValue (action.Operation.CategoryType.Category); // Descriptor action.ModelAction.ComponentDescriptorModel.Id = id; action.ModelAction.ComponentDescriptorModel.Category = categoryValue; var compDescriptor = ComponentDescriptor.CreateDefault; compDescriptor.CopyFrom (action.ModelAction.ComponentDescriptorModel); context.ComponentDescriptor.Add (compDescriptor); // Info action.ModelAction.ComponentInfoModel.Id = id; var compInfo = ComponentInfo.CreateDefault; compInfo.CopyFrom (action.ModelAction.ComponentInfoModel); context.ComponentInfo.Add (compInfo); // Status action.ModelAction.ComponentStatusModel.Id = id; var compStatus = ComponentStatus.CreateDefault; compStatus.CopyFrom (action.ModelAction.ComponentStatusModel); context.ComponentStatus.Add (compStatus); // status collection foreach (var item in action.CollectionAction.ComponentStatusCollection) { var list = context.ComponentStatus.AsQueryable() .Where (p => p.Id.Equals (item.Id)) .ToList () ; // already exist (update) if (list.Count.Equals (1)) { var model = list [0]; model.Change (item); context.ComponentStatus.Update (model); } // new (add) else { context.ComponentStatus.Add (item); } } // Component Relation Collection foreach (var item in action.CollectionAction.ComponentRelationCollection) { // change child status busy to true var childList = context.ComponentStatus.AsQueryable() .Where (p => p.Id.Equals (item.ChildId)) .ToList () ; // found if (childList.Count.Equals (1)) { var child = childList [0]; child.Busy = true; context.ComponentStatus.Update (child); // update } item.ParentId = id; context.ComponentRelation.Add (item); // insert new } // extensions // Extension (CategoryRelationCollection) var categoryRelationList = action.CollectionAction.CategoryRelationCollection .Where (p => p.Category.Equals (categoryValue)) .ToList () ; // found if (categoryRelationList.Count.Equals (1)) { var categoryRelation = categoryRelationList [0]; // get extension using TComponentExtension var extension = TComponentExtension.Create (categoryRelation.Extension); extension.Request (); foreach (var extensionName in extension.ExtensionList) { switch (extensionName) { case TComponentExtensionNames.Document: { //action.ModelAction.ExtensionDocumentModel.Id = id; //var extDocument = ExtensionDocument.CreateDefault; //extDocument.CopyFrom (action.ModelAction.ExtensionDocumentModel); //context.ExtensionDocument.Add (extDocument); } break; case TComponentExtensionNames.Geometry: { action.ModelAction.ExtensionGeometryModel.Id = id; var extGeometry = ExtensionGeometry.CreateDefault; extGeometry.CopyFrom (action.ModelAction.ExtensionGeometryModel); context.ExtensionGeometry.Add (extGeometry); } break; case TComponentExtensionNames.Image: { action.ModelAction.ExtensionImageModel.Id = id; var extImage = ExtensionImage.CreateDefault; extImage.CopyFrom (action.ModelAction.ExtensionImageModel); context.ExtensionImage.Add (extImage); } break; case TComponentExtensionNames.Layout: { action.ModelAction.ExtensionLayoutModel.Id = id; var extLayout = ExtensionLayout.CreateDefault; extLayout.CopyFrom (action.ModelAction.ExtensionLayoutModel); context.ExtensionLayout.Add (extLayout); } break; case TComponentExtensionNames.Node: { // Node reverse if (compStatus.NodeReverse) { // use Node from ModelAction (only) if (compStatus.UseNodeModel) { action.ModelAction.ExtensionNodeModel.ChildId = id; // update context.ExtensionNode.Add (action.ModelAction.ExtensionNodeModel); // update status var parentId = action.ModelAction.ExtensionNodeModel.ParentId; var statusList = context.ComponentStatus.AsQueryable() .Where (p => p.Id.Equals (parentId)) .ToList () ; // found if (statusList.Count.Equals (1)) { var model = statusList [0]; model.Busy = true; context.ComponentStatus.Update (model); } context.SaveChanges (); // update all } } else { // use Node from ModelAction if (compStatus.UseNodeModel) { action.ModelAction.ExtensionNodeModel.ParentId = id; // update context.ExtensionNode.Add (action.ModelAction.ExtensionNodeModel); } // Use Node Collection if (compStatus.UseNodeCollection) { foreach (var nodeModel in action.CollectionAction.ExtensionNodeCollection) { nodeModel.ParentId = id; // for sure context.ExtensionNode.Add (nodeModel); } } context.SaveChanges (); // update all // update status var nodeList = context.ExtensionNode.AsQueryable() .Where (p => p.ParentId.Equals (id)) .ToList () ; foreach (var node in nodeList) { var statusList = context.ComponentStatus.AsQueryable() .Where (p => p.Id.Equals (node.ChildId)) .ToList () ; // found if (statusList.Count.Equals (1)) { var model = statusList [0]; model.Busy = true; context.ComponentStatus.Update (model); } } context.SaveChanges (); // update all } } break; case TComponentExtensionNames.Text: { action.ModelAction.ExtensionTextModel.Id = id; var extText = ExtensionText.CreateDefault; extText.CopyFrom (action.ModelAction.ExtensionTextModel); context.ExtensionText.Add (extText); } break; case TComponentExtensionNames.Content: { action.ModelAction.ExtensionContentModel.Id = id; var extContent = ExtensionContent.CreateDefault; extContent.CopyFrom (action.ModelAction.ExtensionContentModel); context.ExtensionContent.Add (extContent); } break; } } } context.SaveChanges (); action.Result = TValidationResult.Success; } } catch (Exception exception) { Server.Models.Infrastructure.THelper.FormatException ("Insert", exception, action); } }
void Remove (TModelContext context, TEntityAction action) { /* DATA IN - action.Id (Component Id to remove) */ var id = action.Id; try { //Id must exist if (id.IsEmpty ()) { action.Result = new TValidationResult ($"[{action.Operation.CategoryType.Category} - Remove] Component Id can NOT be NULL or EMPTY!"); } else { // search Id var descriptors = context.ComponentDescriptor.AsQueryable() .Where (p => p.Id.Equals (id)) .ToList () ; // Descriptor found if (descriptors.Count.Equals (1)) { var descriptor = descriptors [0]; var categoryValue = descriptor.Category; // remove from Info model var infoList = context.ComponentInfo.AsQueryable() .Where (p => p.Id.Equals (id)) .ToList () ; // Info found if (infoList.Count.Equals (1)) { var info = infoList [0]; context.ComponentInfo.Remove (info);// remove from Info model // remove from Status model var statusList = context.ComponentStatus.AsQueryable() .Where (p => p.Id.Equals (id)) .ToList () ; var compStatus = ComponentStatus.CreateDefault; // Status found if (statusList.Count.Equals (1)) { var statusModel = statusList [0]; context.ComponentStatus.Remove (statusModel); // remove from Status model compStatus.CopyFrom (statusModel); } // status collection foreach (var item in action.CollectionAction.ComponentStatusCollection) { var list = context.ComponentStatus.AsQueryable() .Where (p => p.Id.Equals (item.Id)) .ToList () ; // Status found if (list.Count.Equals (1)) { var statusModel = list [0]; context.ComponentStatus.Remove (statusModel); // remove from Status model } } // extensions // remove extensions var categoryRelationList = action.CollectionAction.CategoryRelationCollection .Where (p => p.Category.Equals (categoryValue)) .ToList () ; // found if (categoryRelationList.Count.Equals (1)) { var categoryRelation = categoryRelationList [0]; // get extension using TComponentExtension var extension = TComponentExtension.Create (categoryRelation.Extension); extension.Request (); foreach (var extensionName in extension.ExtensionList) { switch (extensionName) { case TComponentExtensionNames.Document: { //var list = context.ExtensionDocument // .Where (p => p.Id.Equals (id)) // .ToList () //; //if (list.Count.Equals (1)) { // context.ExtensionDocument.Remove (list [0]); //} } break; case TComponentExtensionNames.Geometry: { var list = context.ExtensionGeometry.AsQueryable() .Where (p => p.Id.Equals (id)) .ToList () ; if (list.Count.Equals (1)) { context.ExtensionGeometry.Remove (list [0]); } } break; case TComponentExtensionNames.Image: { var list = context.ExtensionImage.AsQueryable() .Where (p => p.Id.Equals (id)) .ToList () ; if (list.Count.Equals (1)) { context.ExtensionImage.Remove (list [0]); } } break; case TComponentExtensionNames.Layout: { var list = context.ExtensionLayout.AsQueryable() .Where (p => p.Id.Equals (id)) .ToList () ; if (list.Count.Equals (1)) { context.ExtensionLayout.Remove (list [0]); } } break; case TComponentExtensionNames.Node: { // Node reverse if (compStatus.NodeReverse) { // request for ChildId var nodeList = context.ExtensionNode.AsQueryable() .Where (p => p.ChildId.Equals (id)) .ToList () ; // just one if (nodeList.Count.Equals (1)) { var node = nodeList [0]; // status var list = context.ComponentStatus.AsQueryable() .Where (p => p.Id.Equals (node.ParentId)) .ToList () ; // found (just me) if (list.Count.Equals (1)) { var model = list [0]; model.Busy = false; context.ComponentStatus.Update (model); } // remove context.ExtensionNode.Remove (node); } } else { // request for ParentId var nodeList = context.ExtensionNode.AsQueryable() .Where (p => p.ParentId.Equals (id)) .ToList () ; foreach (var node in nodeList) { // status var list = context.ComponentStatus.AsQueryable() .Where (p => p.Id.Equals (node.ChildId)) .ToList () ; // found if (list.Count.Equals (1)) { var model = list [0]; model.Busy = false; context.ComponentStatus.Update (model); } // remove context.ExtensionNode.Remove (node); } } } break; case TComponentExtensionNames.Text: { var list = context.ExtensionText.AsQueryable() .Where (p => p.Id.Equals (id)) .ToList () ; if (list.Count.Equals (1)) { context.ExtensionText.Remove (list [0]); } } break; case TComponentExtensionNames.Content: { var list = context.ExtensionContent.AsQueryable() .Where (p => p.Id.Equals (id)) .ToList () ; if (list.Count.Equals (1)) { context.ExtensionContent.Remove (list [0]); } } break; } } } // remove from Descriptor model context.ComponentDescriptor.Remove (descriptor); context.SaveChanges (); // update action.Result = TValidationResult.Success; } } } } catch (Exception exception) { Server.Models.Infrastructure.THelper.FormatException ("Remove", exception, action); } }