private string Create_Batch_Delete_Code(string template)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine("        /// <summary>");
            sb.AppendLine("        /// Delete a(n) " + entity_name);
            sb.AppendLine("        /// </summary>");
            sb.AppendLine("        /// <param name=\"id\"></param>");
            sb.AppendLine("        public void " + NameHelper.Get_MethodName_DataAccess_Domain_BatchDelete(entity_name) + "(" + NameHelper.Get_Identities_Name(entity_name) + "[] ids)");
            sb.AppendLine("        {");

            sb.AppendLine("             var entity_ids = ids.Select(x => (Guid)x.GetPersistId()).ToArray();");
            sb.AppendLine("             var entities = GetDbSet<" + entity_name + ">().Where(x => entity_ids.Contains(x.id));");
            sb.AppendLine("             GetDbSet<" + entity_name + ">().RemoveRange(entities);");
            //sb.AppendLine("             foreach (var item in entities)");
            //sb.AppendLine("             {");
            //sb.AppendLine("                 GetDbSet<" + entity_name + ">().Remove(item);");
            //sb.AppendLine("             }");

            sb.Append("        }");

            template = template.Replace("{{Batch-Delete-Method}}", sb.ToString());

            return(template);
        }
Пример #2
0
        public void Create_Batch_DeleteCommand_Command()
        {
            #region folders

            string template_folder = context.Server.MapPath(settings.folder_templates + settings.template_folder_command_handlers);
            string template_file   = template_folder + "BatchDeleteCommandHander.cs";

            string target_folder = template_folder.Replace(context.Server.MapPath(settings.folder_templates), context.Server.MapPath(settings.folder_result));
            string target_file   = template_file.Replace(context.Server.MapPath(settings.folder_templates), context.Server.MapPath(settings.folder_result));

            target_folder = target_folder.Replace("{{namespace}}", settings.code_namespace);
            target_folder = target_folder.Replace("{{entity_sub_namespace}}", entity_sub_namespace);

            target_file = target_file.Replace("{{namespace}}", settings.code_namespace);
            target_file = target_file.Replace("{{entity_sub_namespace}}", entity_sub_namespace);

            #endregion

            string template = FileHelper.ReadAll(template_file);

            template = template.Replace("{{namespace}}", settings.code_namespace);
            template = template.Replace("{{entity_name}}", entity_name);
            template = template.Replace("{{entity_sub_namespace}}", entity_sub_namespace);

            template = template.Replace("{{domain_model_id_name}}", NameHelper.Get_Identities_Name(entity_name));
            template = template.Replace("{{batch_delete_method_name}}", NameHelper.Get_MethodName_DataAccess_Domain_BatchDelete(entity_name));

            FileHelper.CheckAndCreateFolder(target_folder);
            FileHelper.WriteAll(target_file, template);
        }
        /// <summary>
        /// 创建代码
        /// </summary>
        public void Create_Code()
        {
            #region folders

            string template_folder = context.Server.MapPath(settings.folder_templates + settings.template_folder_data_access_domain_interface);
            string template_file   = template_folder + "I{{entity_sub_namespace}}DataAccessor.cs";

            string target_folder = template_folder.Replace(context.Server.MapPath(settings.folder_templates), context.Server.MapPath(settings.folder_result));
            string target_file   = template_file.Replace(context.Server.MapPath(settings.folder_templates), context.Server.MapPath(settings.folder_result));

            target_folder = target_folder.Replace("{{namespace}}", settings.code_namespace);
            target_folder = target_folder.Replace("{{entity_sub_namespace}}", entity_sub_namespace);

            target_file = target_file.Replace("{{namespace}}", settings.code_namespace);
            target_file = target_file.Replace("{{entity_sub_namespace}}", entity_sub_namespace);

            #endregion

            string template = FileHelper.ReadAll(template_file);

            template = template.Replace("{{namespace}}", settings.code_namespace);
            template = template.Replace("{{entity_name}}", entity_name);
            template = template.Replace("{{entity_sub_namespace}}", entity_sub_namespace);
            template = template.Replace("{{domain_model_name}}", NameHelper.Get_Domain_Model_Name(entity_name));
            template = template.Replace("{{domain_model_id_name}}", NameHelper.Get_Identities_Name(entity_name));


            template = template.Replace("{{add_return_name}}", entity_name);
            template = template.Replace("{{add_method_name}}", NameHelper.Get_MethodName_DataAccess_Domain_Add(entity_name));
            template = template.Replace("{{upate_method_name}}", NameHelper.Get_MethodName_DataAccess_Domain_Update(entity_name));
            template = template.Replace("{{delete_method_name}}", NameHelper.Get_MethodName_DataAccess_Domain_Delete(entity_name));
            template = template.Replace("{{batch_delete_method_name}}", NameHelper.Get_MethodName_DataAccess_Domain_BatchDelete(entity_name));

            FileHelper.CheckAndCreateFolder(target_folder);
            FileHelper.WriteAll(target_file, template);
        }