TemplateViewModel.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. using System;
  2. using System.Collections.Generic;
  3. namespace VberAdmin.Models
  4. {
  5. public class TemplateViewModel : CopyRightUserInfo
  6. {
  7. #region Data
  8. public TemplateViewModel()
  9. {
  10. IdType = "int";
  11. ParentPath = "";
  12. ExtFilePath = "";
  13. }
  14. /// <summary>
  15. /// 页面标题
  16. /// </summary>
  17. public string HtmlPageTitle { get; set; }
  18. /// <summary>
  19. /// 模态框标题
  20. /// </summary>
  21. public string HtmlModalTitle { get; set; }
  22. /// <summary>
  23. /// 项目名称
  24. /// </summary>
  25. public string ProjectName { get; set; }
  26. /// <summary>
  27. /// 表名即类名
  28. /// </summary>
  29. private string _className;
  30. /// <summary>
  31. /// 如果有s或者es则去掉
  32. /// </summary>
  33. public string ClassName
  34. {
  35. get
  36. {
  37. if (_className.EndsWith("ies"))
  38. {
  39. _className = _className.Substring(0, _className.Length - 3) + "y";
  40. }
  41. else if (_className.EndsWith("es"))
  42. {
  43. _className = _className.Substring(0, _className.Length - 2);
  44. }
  45. else if (_className.EndsWith("s"))
  46. {
  47. _className = _className.Substring(0, _className.Length - 1);
  48. }
  49. return _className;
  50. }
  51. set => _className = value;
  52. }
  53. public string FileName => ClassName.EndsWith("Info") ? ClassName.Substring(0, ClassName.Length - 4) : ClassName;
  54. /// <summary>
  55. /// 命名空间
  56. /// </summary>
  57. public string ClassNamespace { get; set; }
  58. /// <summary>
  59. /// 是否多条件查询
  60. /// </summary>
  61. public bool IsMultipleSearch { get; set; }
  62. private string _extFilePath;
  63. public string ExtFilePath
  64. {
  65. get
  66. {
  67. if (_extFilePath == null)
  68. {
  69. return FileName + "s";
  70. }
  71. if (string.IsNullOrEmpty(_extFilePath))
  72. {
  73. return "";
  74. }
  75. _extFilePath = _extFilePath.Replace("/", "\\");
  76. var arr = _extFilePath.Split(new[] { '\\' }, StringSplitOptions.RemoveEmptyEntries);
  77. return string.Join("\\", arr);
  78. }
  79. set => _extFilePath = value;
  80. }
  81. /// <summary>
  82. /// 父路径(不包含Pages)
  83. /// </summary>
  84. public string ParentPath { get; set; }
  85. /// <summary>
  86. /// Application命名空间
  87. /// </summary>
  88. public string ApplicationNamespace => ClassNamespace?.Replace(".Core", "") +
  89. (string.IsNullOrEmpty(ExtFilePath)
  90. ? ""
  91. : $".{ExtFilePath.Replace("\\", ".")}");
  92. /// <summary>
  93. /// id的类型
  94. /// </summary>
  95. public string IdType { get; set; }
  96. /// <summary>
  97. /// 首字母小写
  98. /// </summary>
  99. public string CamelClassName => ClassName.Substring(0, 1).ToLower() + ClassName.Substring(1, ClassName.Length - 1);
  100. private string _baseFolder;
  101. /// <summary>
  102. /// 基础代码路径
  103. /// </summary>
  104. public string BaseFolder
  105. {
  106. get => _baseFolder.EndsWith("\\") ? _baseFolder : _baseFolder + "\\";
  107. set => _baseFolder = value;
  108. }
  109. public string ParentFileName
  110. {
  111. get
  112. {
  113. var arr = BaseFolder.Split(new[] { '\\' }, StringSplitOptions.RemoveEmptyEntries);
  114. return arr[arr.Length - 1];
  115. }
  116. }
  117. public string ColumnPrimaryKey { get; set; }
  118. public List<ColumnViewModel> Columns { get; set; }
  119. #endregion Data
  120. #region FileControl
  121. public bool IsCreateDto { get; set; }
  122. public bool IsUpdateDto { get; set; }
  123. public bool IsListDto { get; set; }
  124. public bool IsApplicationService { get; set; }
  125. public bool IsIApplicationService { get; set; }
  126. public bool IsController { get; set; }
  127. public bool IsView { get; set; }
  128. public bool IsReplace { get; set; }
  129. #endregion FileControl
  130. #region Path
  131. private string _serviceFolder;
  132. //public string DefaultServiceFolder => BaseFolder.Replace(".Core", ".Application");
  133. //public string DefaultDtoFolder => $"{DefaultServiceFolder}Dto\\";
  134. /// <summary>
  135. /// 生成Service文件的路径
  136. /// </summary>
  137. public string ServiceFolder
  138. {
  139. get => string.IsNullOrEmpty(_serviceFolder)
  140. ? $"{BaseFolder.Replace(".Core", ".Application")}{(string.IsNullOrEmpty(ExtFilePath) ? "" : $"{ExtFilePath}\\")}"
  141. : _serviceFolder;
  142. set => _serviceFolder = value;
  143. }
  144. private string _dtoFolder;
  145. /// <summary>
  146. /// 生成DTO的路径
  147. /// </summary>
  148. public string DtoFolder
  149. {
  150. get => string.IsNullOrEmpty(_dtoFolder)
  151. ? $"{ServiceFolder}Dto\\"
  152. : _dtoFolder;
  153. set => _dtoFolder = value;
  154. }
  155. /// <summary>
  156. /// 项目路径
  157. /// </summary>
  158. public string ProjectFolder => BaseFolder.Substring(0, BaseFolder.IndexOf(ProjectName + ".Core", StringComparison.Ordinal));
  159. /// <summary>
  160. /// Web项目路径
  161. /// </summary>
  162. public string WebFolder => $"{ProjectFolder}{WebName}\\";
  163. private string _controllerFolder;
  164. /// <summary>
  165. /// 控制器路径
  166. /// </summary>
  167. public string ControllerFolder
  168. {
  169. get => string.IsNullOrEmpty(_controllerFolder)
  170. ? $"{WebFolder}Controllers\\"
  171. : _controllerFolder;
  172. set => _controllerFolder = value;
  173. }
  174. private string _viewsFolder;
  175. /// <summary>
  176. /// 视图路径
  177. /// </summary>
  178. public string ViewsFolder
  179. {
  180. get => string.IsNullOrEmpty(_viewsFolder)
  181. ? $"{WebFolder}Views\\{ParentFileName}\\"
  182. : _viewsFolder;
  183. set => _viewsFolder = value;
  184. }
  185. /// <summary>
  186. /// 模板路径
  187. /// </summary>
  188. public string TemplateFolder { get; set; } = @"..\..\Templates";
  189. /// <summary>
  190. /// 模板文件相对位置
  191. /// </summary>
  192. public string TemplateFolderNames { get; set; }
  193. #endregion Path
  194. #region Name
  195. private string _webName;
  196. public string WebName
  197. {
  198. get => string.IsNullOrEmpty(_webName) ? $"{ProjectName}.Web.Mvc" : _webName;
  199. set => _webName = value;
  200. }
  201. public string ApplicationName => $"{ProjectName}.Application";
  202. public string ServiceInterfaceName => $"I{FileName}ApplicationService.cs";
  203. public string ServiceName => $"{FileName}ApplicationService.cs";
  204. public string CreateDtoName => $"{FileName}CreateDto.cs";
  205. public string UpdateDtoName => $"{FileName}UpdateDto.cs";
  206. public string ListDtoName => $"{FileName}Dto.cs";
  207. public string ControllerName => $"{FileName}Controller.cs";
  208. public string ViewsName => $"{FileName}.cshtml";
  209. #endregion Name
  210. }
  211. }