public async Task <ActionResult> PutHomeAdminLazy(Guid componentId, [FromBody] LazyComponent exchangeComponent) { if (componentId != exchangeComponent.ComponentId) { throw new ArgumentException($"componentId != component.Id"); } var configComponent = await _mongoComponentStrategy.GetAsync(_componentHome); var linkVisitor = _visitorFactory.GetBuilder <LinkComponentRelationVisitorBuilder>().Build(); exchangeComponent.Accept(linkVisitor); var flatVisitor = _visitorFactory.GetBuilder <FlatComponentVisitorBuilder>().Build(); configComponent.Accept(flatVisitor); var targetComponent = flatVisitor.FlatElements[componentId]; var exchangeVisitor = _visitorFactory.GetBuilder <ExchangeComponentVisitorBuilder>().SetExchangeComponent(targetComponent, exchangeComponent).Build(); configComponent.Accept(exchangeVisitor); await _mongoComponentStrategy.SetAsync(_componentHome, configComponent); return(Ok()); }
public async Task <ActionResult> PutHomeAdminSubComponentsLazy(Guid componentId, [FromBody] LazyComponent component) { if (componentId == component.ComponentId) { throw new ArgumentException($"componentId == component.Id"); } var configComponent = await _mongoComponentStrategy.GetAsync(_componentHome); var flatVisitor = _visitorFactory.GetBuilder <FlatComponentVisitorBuilder>().Build(); configComponent.Accept(flatVisitor); var targetComponent = flatVisitor.FlatElements[componentId]; if (!(targetComponent is CompositeComponent)) { throw new InvalidOperationException("只有 Composite 支援增加 SubComponent。"); } if (flatVisitor.FlatElements.ContainsKey(component.ComponentId)) { throw new InvalidOperationException("ConfigComponent 已具備 component.ComponentId 請使用新的 component.ComponentId。"); } var linkVisitor = _visitorFactory.GetBuilder <LinkComponentRelationVisitorBuilder>().Build(); component.Accept(linkVisitor); (targetComponent as CompositeComponent).AddLowerLayer(component); await _mongoComponentStrategy.SetAsync(_componentHome, configComponent); return(Ok()); }