예제 #1
0
        protected TemplateParameter GetSaveParameters()
        {
            var parameters = new TemplateParameter();

            parameters.Add(RepositoryBuilderConstants.SaveChild, GetSaveableChilds());
            parameters.Add(RepositoryBuilderConstants.SaveChildCollections, GetSaveableChildCollection());
            parameters.Add(RepositoryBuilderConstants.EntityName, GetEntityName);
            parameters.Add(RepositoryBuilderConstants.EntityNameLowerCase, GetEntityName.ToLower());

            return(parameters);
        }
예제 #2
0
        private List <string> GetSaveableChildCollection()
        {
            var list = new List <string>();

            foreach (var itemToSave in GetChildCollectionProperties)
            {
                var builder = new StringBuilder();
                builder.AppendLineWithTabs($"foreach(var toSaveItem in {GetEntityName.ToLower()}.{itemToSave.Name})", 0);
                builder.AppendLineWithTabs("{", 0);
                builder.AppendLineWithTabs($"toSaveItem.{GetChildReferenceProperty(itemToSave).Name} = {GetEntityName.ToLower()}.Id;", 1);
                builder.AppendLineWithTabs($"_{Entity.GetRepositoryInterface(itemToSave.DataType.Type).FirstCharToLower()}.Save(toSaveItem);", 1);
                builder.AppendLineWithTabs("}", 0);
                list.Add(builder.ToString());
            }

            return(list);
        }
예제 #3
0
        private List <string> GetSaveableChilds()
        {
            var list = new List <string>();

            foreach (var itemToSave in GetChildProperties)
            {
                if (itemToSave.Required)
                {
                    list.Add($"{GetEntityName.ToLower()}.{itemToSave.Name} = _{Entity.GetRepositoryInterface(itemToSave.DataType.Type).FirstCharToLower()}.Save({GetEntityName.ToLower()}.{itemToSave.Name});");
                }
                else
                {
                    var builder = new StringBuilder();
                    builder.AppendLine($"if ({GetEntityName.ToLower()}.{itemToSave.Name} != null)");
                    builder.AppendLine("{");
                    builder.AppendLine($"{GetEntityName.ToLower()}.{itemToSave.Name} = _{Entity.GetRepositoryInterface(itemToSave.DataType.Type).FirstCharToLower()}.Save({GetEntityName.ToLower()}.{itemToSave.Name});");
                    builder.AppendLine("}");
                    list.Add(builder.ToString());
                }
            }
            return(list);
        }
예제 #4
0
        protected virtual InterfaceFile GetInterfaceFile()
        {
            var interfaceFile = FileManager.StartNewInterfaceFile(GetRepositoryInterfaceName, Repository.InterfaceLocation.Project, Repository.InterfaceLocation.Folder);

            interfaceFile.Namespaces.Add(Repository.InterfaceLocation.GetProjectLocation);
            interfaceFile.Namespaces.Add("static Dapper.SqlMapper");
            interfaceFile.Namespaces.Add("Dapper");
            interfaceFile.Namespaces.Add("System.Linq");
            interfaceFile.Namespaces.AddRange(GetRepositoryNamespaces);
            interfaceFile.OwnNamespace = Repository.InterfaceLocation.GetNamespace;
            interfaceFile.Methods.Add($"{GetEntityName} Save({GetEntityName} {GetEntityName.ToLower()});");
            interfaceFile.Methods.Add($"{GetEntityName} GetById(long id);");
            if (Entity.GetDatabase.StoredProcedures.GenerateGetById.Generate)
            {
                interfaceFile.Methods.Add($"{GetEntityName} GetFullObjectById(long id);");
                if (Entity.Entity.GenerateReadonlyGuid)
                {
                    interfaceFile.Methods.Add($"{GetEntityName} GetFullObjectByUId(Guid uid);");
                }
            }
            return(interfaceFile);
        }