public void SaveType([Required][FromBody] TypeHelpEntity entity) { HelpPermissions.ViewHelp.AssertAuthorized(); using (var tr = new Transaction()) { foreach (var query in entity.Queries) { query.Columns.RemoveAll(a => !a.Description.HasText()); if (query.Columns.IsEmpty() && !query.Description.HasText()) { if (!query.IsNew) { query.ToLite().DeleteLite(QueryHelpOperation.Delete); } } else { query.Execute(QueryHelpOperation.Save); } } var currentProperties = entity.Properties.Select(p => p.Property.ToPropertyRoute()).ToHashSet(); var hiddenProperties = entity.IsNew ? Enumerable.Empty <PropertyRouteHelpEmbedded>() : entity.ToLite().Retrieve().Properties .Where(p => !currentProperties.Contains(p.Property.ToPropertyRoute())) .ToList(); entity.Properties.AddRange(hiddenProperties); entity.Properties.RemoveAll(a => !a.Description.HasText()); var currentOperations = entity.Operations.Select(p => p.Operation).ToHashSet(); var hiddenOperations = entity.IsNew ? Enumerable.Empty <OperationHelpEmbedded>() : entity.ToLite().Retrieve().Operations .Where(p => !currentOperations.Contains(p.Operation)) .ToList(); entity.Operations.AddRange(hiddenOperations); entity.Operations.RemoveAll(a => !a.Description.HasText()); if (entity.Properties.IsEmpty() && entity.Operations.IsEmpty() && !entity.Description.HasText()) { if (!entity.IsNew) { entity.ToLite().DeleteLite(TypeHelpOperation.Delete); } } else { entity.Execute(TypeHelpOperation.Save); } tr.Commit(); } }
public TypeHelpEntity GetEntity() { var result = new TypeHelpEntity { Culture = this.Culture.ToCultureInfoEntity(), Type = this.Type.ToTypeEntity(), Description = DBEntity?.Description, Info = Info }; result.Properties.AddRange( from pre in PropertyRouteLogic.RetrieveOrGenerateProperties(this.Type.ToTypeEntity()) let pr = pre.ToPropertyRoute() where !(pr.PropertyInfo != null && pr.PropertyInfo.SetMethod == null && ExpressionCleaner.HasExpansions(pr.PropertyInfo.DeclaringType !, pr.PropertyInfo)) let ph = Properties.GetOrThrow(pre.ToPropertyRoute()) where ph.IsAllowed() == null select new PropertyRouteHelpEmbedded { Property = pre, Info = ph.Info, Description = ph.UserDescription, }); result.Operations.AddRange( from oh in Operations.Values where oh.IsAllowed() == null select new OperationHelpEmbedded { Operation = oh.OperationSymbol, Info = oh.Info, Description = oh.UserDescription, }); result.Queries.AddRange( from qn in QueryLogic.Queries.GetTypeQueries(this.Type).Keys let qh = HelpLogic.GetQueryHelp(qn) where qh.IsAllowed() == null select qh.GetEntity()); if (DBEntity != null) { result.SetId(DBEntity.Id); result.SetIsNew(DBEntity.IsNew); result.Ticks = DBEntity.Ticks; } return(result); }
#pragma warning restore 414 public static XDocument ToXDocument(TypeHelpEntity entity) { return(new XDocument( new XDeclaration("1.0", "utf-8", "yes"), new XElement(_Entity, new XAttribute(_FullName, entity.Type.FullClassName), new XAttribute(_Culture, entity.Culture.Name), entity.Description.HasText() ? new XElement(_Description, entity.Description) : null !, entity.Properties.Any() ? new XElement(_Properties, entity.Properties.Select(p => new XElement(_Property, new XAttribute(_Name, p.Property.Path), p.Description !)) ) : null !, entity.Operations.Any() ? new XElement(_Operations, entity.Operations.Select(o => new XElement(_Operation, new XAttribute(_Key, o.Operation.Key), o.Description !)) ) : null ! ) )); }