Exemplo n.º 1
0
        public IEnumerable <IConceptInfo> CreateNewConcepts(MonitoredRecordInfo conceptInfo, IDslModel existingConcepts)
        {
            var createdAtPropertyInfo = new DateTimePropertyInfo
            {
                DataStructure = conceptInfo.Entity,
                Name          = "CreatedAt"
            };

            var creationTimePropertyInfo = new CreationTimeInfo {
                Property = createdAtPropertyInfo
            };
            var denyUserEditPropertyInfo = new DenyUserEditPropertyInfo {
                Property = createdAtPropertyInfo
            };

            var loggingPropertyInfo = new EntityLoggingInfo
            {
                Entity = conceptInfo.Entity
            };

            var allPropertiesLoggingInfo = new AllPropertiesLoggingInfo {
                EntityLogging = loggingPropertyInfo
            };

            return(new IConceptInfo[]
            {
                createdAtPropertyInfo, creationTimePropertyInfo, denyUserEditPropertyInfo, loggingPropertyInfo, allPropertiesLoggingInfo
            });
        }
Exemplo n.º 2
0
 private static string ThrowExceptionSnippet(DenyUserEditPropertyInfo info)
 {
     return($@"if (invalidItem != null)
             throw new Rhetos.UserException(
                 ""It is not allowed to directly enter {{0}} property of {{1}}."",
                 new[] {{ ""{info.Property.Name}"", ""{info.Property.DataStructure.Module.Name}.{info.Property.DataStructure.Name}"" }},
                 ""DataStructure:{info.Property.DataStructure.Module.Name}.{info.Property.DataStructure.Name},ID:"" + invalidItem.ID + "",Property:{info.Property.Name}"",
                 null);
     ");
 }
Exemplo n.º 3
0
        private static string CheckChangesOnInsertSnippet(DenyUserEditPropertyInfo info)
        {
            return($@"if (checkUserPermissions)
            {{
                var invalidItem = insertedNew.Where(newItem => newItem.{GetComparedPropertyName(info.Property)} != null).FirstOrDefault();

                {ThrowExceptionSnippet(info)}
            }}

            ");
        }
 private static string ThrowExceptionSnippet(DenyUserEditPropertyInfo info)
 {
     return(string.Format(
                @"if (invalidItem != null)
             throw new Rhetos.UserException(
                 ""It is not allowed to directly enter {{0}} property of {{1}}."",
                 new[] {{ ""{2}"", ""{0}.{1}"" }},
                 ""DataStructure:{0}.{1},ID:"" + invalidItem.ID + "",Property:{2}"",
                 null);
     ",
                info.Property.DataStructure.Module.Name,
                info.Property.DataStructure.Name,
                info.Property.Name,
                GetComparedPropertyName(info.Property)));
 }
        private static string CheckChangesOnInsertSnippet(DenyUserEditPropertyInfo info)
        {
            return(string.Format(
                       @"if (checkUserPermissions)
            {{
                var invalidItem = insertedNew.Where(newItem => newItem.{3} != null).FirstOrDefault();

                {4}
            }}

            ",
                       info.Property.DataStructure.Module.Name,
                       info.Property.DataStructure.Name,
                       info.Property.Name,
                       GetComparedPropertyName(info.Property),
                       ThrowExceptionSnippet(info)));
        }
Exemplo n.º 6
0
        private static string CheckChangesOnUpdateSnippet(DenyUserEditPropertyInfo info)
        {
            return($@"if (checkUserPermissions)
            {{
                var changes = updatedNew.Zip(updated, (newItem, oldItem) => new {{ newItem, oldItem }});
                foreach (var change in changes)
                    if (change.newItem.{GetComparedPropertyName(info.Property)} == null && change.oldItem.{GetComparedPropertyName(info.Property)} != null)
                        change.newItem.{GetComparedPropertyName(info.Property)} = change.oldItem.{GetComparedPropertyName(info.Property)};
                var invalidItem = changes
                    .Where(change => change.newItem.{GetComparedPropertyName(info.Property)} != null && !change.newItem.{GetComparedPropertyName(info.Property)}.Equals(change.oldItem.{GetComparedPropertyName(info.Property)}) || change.newItem.{GetComparedPropertyName(info.Property)} == null && change.oldItem.{GetComparedPropertyName(info.Property)} != null)
                    .Select(change => change.newItem)
                    .FirstOrDefault();

                {ThrowExceptionSnippet(info)}
            }}

            ");
        }
        private static string CheckChangesOnUpdateSnippet(DenyUserEditPropertyInfo info)
        {
            return(string.Format(
                       @"if (checkUserPermissions)
            {{
                var changes = updatedNew.Zip(updated, (newItem, oldItem) => new {{ newItem, oldItem }});
                foreach (var change in changes)
                    if (change.newItem.{3} == null && change.oldItem.{3} != null)
                        change.newItem.{3} = change.oldItem.{3};
                var invalidItem = changes
                    .Where(change => change.newItem.{3} != null && !change.newItem.{3}.Equals(change.oldItem.{3}) || change.newItem.{3} == null && change.oldItem.{3} != null)
                    .Select(change => change.newItem)
                    .FirstOrDefault();

                {4}
            }}

            ",
                       info.Property.DataStructure.Module.Name,
                       info.Property.DataStructure.Name,
                       info.Property.Name,
                       GetComparedPropertyName(info.Property),
                       ThrowExceptionSnippet(info)));
        }