public void GenerateCode(Dsl.IConceptInfo conceptInfo, ICodeBuilder codeBuilder) { var info = (ModificationTimeOfInfo)conceptInfo; string timeProperty = info.Property.GetSimplePropertyName(); string modifiedProperty = info.ModifiedProperty.GetSimplePropertyName(); string snippet = $@"{{ var now = SqlUtility.GetDatabaseTime(_executionContext.SqlExecuter); foreach (var newItem in insertedNew) if(newItem.{timeProperty} == null) newItem.{timeProperty} = now; var modifiedItems = updatedOld .Zip(updatedNew, (oldValue, newValue) => new {{ oldValue, newValue }}) .Where(modified => modified.oldValue.{modifiedProperty} == null && modified.newValue.{modifiedProperty} != null || modified.oldValue.{modifiedProperty} != null && !modified.oldValue.{modifiedProperty}.Equals(modified.newValue.{modifiedProperty})); foreach (var modified in modifiedItems) modified.newValue.{timeProperty} = now; }} "; codeBuilder.InsertCode(snippet, WritableOrmDataStructureCodeGenerator.OldDataLoadedTag, info.Property.DataStructure); }
public void GenerateCode(Dsl.IConceptInfo conceptInfo, ICodeBuilder codeBuilder) { var info = (ModificationTimeOfInfo)conceptInfo; string timeProperty = info.Property.GetSimplePropertyName(); string modifiedProperty = info.ModifiedProperty.GetSimplePropertyName(); string propertyInitialization = $@"if(newItem.{timeProperty} == null) newItem.{timeProperty} = now; "; codeBuilder.InsertCode(propertyInitialization, ModificationTimeOfInfrastructureCodeGenerator.PropertyInitializationTag, info.Dependency_Infrastructure); string updateModified = $@"{{ var modifiedItems = updatedOld .Zip(updatedNew, (oldValue, newValue) => new {{ oldValue, newValue }}) .Where(modified => modified.oldValue.{modifiedProperty} == null && modified.newValue.{modifiedProperty} != null || modified.oldValue.{modifiedProperty} != null && !modified.oldValue.{modifiedProperty}.Equals(modified.newValue.{modifiedProperty})); foreach (var modified in modifiedItems) if (modified.newValue.{timeProperty} != now) {{ modified.newValue.{timeProperty} = now; updateModificationTime = true; }} }} "; codeBuilder.InsertCode(updateModified, ModificationTimeOfInfrastructureCodeGenerator.UpdateModifiedTag, info.Dependency_Infrastructure); }
public void GenerateCode(Dsl.IConceptInfo conceptInfo, ICodeBuilder codeBuilder) { var info = (DataStructureInfo)conceptInfo; if (info.Module.Name == "Common" && info.Name == "Claim") { codeBuilder.InsertCode(DeactivateInsteadOfDelete, ClaimRepositoryCodeGenerator.DeactivateInsteadOfDeleteTag, info); } }
public void GenerateCode(Dsl.IConceptInfo conceptInfo, ICodeBuilder codeBuilder) { var info = (CreationTimeInfo)conceptInfo; string snippet = $@"{{ var now = SqlUtility.GetDatabaseTime(_executionContext.SqlExecuter); foreach (var newItem in insertedNew) if(newItem.{info.Property.Name} == null) newItem.{info.Property.Name} = now; }} "; codeBuilder.InsertCode(snippet, WritableOrmDataStructureCodeGenerator.InitializationTag, info.Property.DataStructure); }
public void GenerateCode(Dsl.IConceptInfo conceptInfo, ICodeBuilder codeBuilder) { var info = (CreatedByInfo)conceptInfo; string createdByValue = @"{ var userName = _executionContext.UserInfo.UserName; var userIds = _domRepository.Common.Principal.Query(p => p.Name == userName).Select(p => p.ID).ToList(); if (userIds.Count > 1) throw new Rhetos.UserException(""The system is not configured properly: There are multiple principals with the same username '{0}'. Please contact your system administrator."", new[] { userName }, null, null); if (userIds.Count == 0) throw new Rhetos.UserException(""The system is not configured properly: There are no principals with username '{0}'. Please contact your system administrator."", new[] { userName }, null, null); Guid userId = userIds.Single(); foreach (var newItem in insertedNew) if(newItem." + info.Property.Name + @"ID == null) newItem." + info.Property.Name + @"ID = userId; } "; codeBuilder.InsertCode(createdByValue, WritableOrmDataStructureCodeGenerator.InitializationTag, info.Property.DataStructure); }
public void GenerateCode(Dsl.IConceptInfo conceptInfo, ICodeBuilder codeBuilder) { var info = (CreationTimeInfo)conceptInfo; codeBuilder.InsertCode(SetCreationTimeValue(info), WritableOrmDataStructureCodeGenerator.InitializationTag, info.Property.DataStructure); }