| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260 |
- using System;
- using System.Collections.Generic;
- namespace VberAdmin.Models
- {
- public class TemplateViewModel : CopyRightUserInfo
- {
- #region Data
- public TemplateViewModel()
- {
- IdType = "int";
- ParentPath = "";
- ExtFilePath = "";
- }
- /// <summary>
- /// 页面标题
- /// </summary>
- public string HtmlPageTitle { get; set; }
- /// <summary>
- /// 模态框标题
- /// </summary>
- public string HtmlModalTitle { get; set; }
- /// <summary>
- /// 项目名称
- /// </summary>
- public string ProjectName { get; set; }
- /// <summary>
- /// 表名即类名
- /// </summary>
- private string _className;
- /// <summary>
- /// 如果有s或者es则去掉
- /// </summary>
- public string ClassName
- {
- get
- {
- if (_className.EndsWith("ies"))
- {
- _className = _className.Substring(0, _className.Length - 3) + "y";
- }
- else if (_className.EndsWith("es"))
- {
- _className = _className.Substring(0, _className.Length - 2);
- }
- else if (_className.EndsWith("s"))
- {
- _className = _className.Substring(0, _className.Length - 1);
- }
- return _className;
- }
- set => _className = value;
- }
- public string FileName => ClassName.EndsWith("Info") ? ClassName.Substring(0, ClassName.Length - 4) : ClassName;
- /// <summary>
- /// 命名空间
- /// </summary>
- public string ClassNamespace { get; set; }
- /// <summary>
- /// 是否多条件查询
- /// </summary>
- public bool IsMultipleSearch { get; set; }
- private string _extFilePath;
- public string ExtFilePath
- {
- get
- {
- if (_extFilePath == null)
- {
- return FileName + "s";
- }
- if (string.IsNullOrEmpty(_extFilePath))
- {
- return "";
- }
- _extFilePath = _extFilePath.Replace("/", "\\");
- var arr = _extFilePath.Split(new[] { '\\' }, StringSplitOptions.RemoveEmptyEntries);
- return string.Join("\\", arr);
- }
- set => _extFilePath = value;
- }
- /// <summary>
- /// 父路径(不包含Pages)
- /// </summary>
- public string ParentPath { get; set; }
- /// <summary>
- /// Application命名空间
- /// </summary>
- public string ApplicationNamespace => ClassNamespace?.Replace(".Core", "") +
- (string.IsNullOrEmpty(ExtFilePath)
- ? ""
- : $".{ExtFilePath.Replace("\\", ".")}");
- /// <summary>
- /// id的类型
- /// </summary>
- public string IdType { get; set; }
- /// <summary>
- /// 首字母小写
- /// </summary>
- public string CamelClassName => ClassName.Substring(0, 1).ToLower() + ClassName.Substring(1, ClassName.Length - 1);
- private string _baseFolder;
- /// <summary>
- /// 基础代码路径
- /// </summary>
- public string BaseFolder
- {
- get => _baseFolder.EndsWith("\\") ? _baseFolder : _baseFolder + "\\";
- set => _baseFolder = value;
- }
- public string ParentFileName
- {
- get
- {
- var arr = BaseFolder.Split(new[] { '\\' }, StringSplitOptions.RemoveEmptyEntries);
- return arr[arr.Length - 1];
- }
- }
- public string ColumnPrimaryKey { get; set; }
- public List<ColumnViewModel> Columns { get; set; }
- #endregion Data
- #region FileControl
- public bool IsCreateDto { get; set; }
- public bool IsUpdateDto { get; set; }
- public bool IsListDto { get; set; }
- public bool IsApplicationService { get; set; }
- public bool IsIApplicationService { get; set; }
- public bool IsController { get; set; }
- public bool IsView { get; set; }
- public bool IsReplace { get; set; }
- #endregion FileControl
- #region Path
- private string _serviceFolder;
- //public string DefaultServiceFolder => BaseFolder.Replace(".Core", ".Application");
- //public string DefaultDtoFolder => $"{DefaultServiceFolder}Dto\\";
- /// <summary>
- /// 生成Service文件的路径
- /// </summary>
- public string ServiceFolder
- {
- get => string.IsNullOrEmpty(_serviceFolder)
- ? $"{BaseFolder.Replace(".Core", ".Application")}{(string.IsNullOrEmpty(ExtFilePath) ? "" : $"{ExtFilePath}\\")}"
- : _serviceFolder;
- set => _serviceFolder = value;
- }
- private string _dtoFolder;
- /// <summary>
- /// 生成DTO的路径
- /// </summary>
- public string DtoFolder
- {
- get => string.IsNullOrEmpty(_dtoFolder)
- ? $"{ServiceFolder}Dto\\"
- : _dtoFolder;
- set => _dtoFolder = value;
- }
- /// <summary>
- /// 项目路径
- /// </summary>
- public string ProjectFolder => BaseFolder.Substring(0, BaseFolder.IndexOf(ProjectName + ".Core", StringComparison.Ordinal));
- /// <summary>
- /// Web项目路径
- /// </summary>
- public string WebFolder => $"{ProjectFolder}{WebName}\\";
- private string _controllerFolder;
- /// <summary>
- /// 控制器路径
- /// </summary>
- public string ControllerFolder
- {
- get => string.IsNullOrEmpty(_controllerFolder)
- ? $"{WebFolder}Controllers\\"
- : _controllerFolder;
- set => _controllerFolder = value;
- }
- private string _viewsFolder;
- /// <summary>
- /// 视图路径
- /// </summary>
- public string ViewsFolder
- {
- get => string.IsNullOrEmpty(_viewsFolder)
- ? $"{WebFolder}Views\\{ParentFileName}\\"
- : _viewsFolder;
- set => _viewsFolder = value;
- }
- /// <summary>
- /// 模板路径
- /// </summary>
- public string TemplateFolder { get; set; } = @"..\..\Templates";
- /// <summary>
- /// 模板文件相对位置
- /// </summary>
- public string TemplateFolderNames { get; set; }
- #endregion Path
- #region Name
- private string _webName;
- public string WebName
- {
- get => string.IsNullOrEmpty(_webName) ? $"{ProjectName}.Web.Mvc" : _webName;
- set => _webName = value;
- }
- public string ApplicationName => $"{ProjectName}.Application";
- public string ServiceInterfaceName => $"I{FileName}ApplicationService.cs";
- public string ServiceName => $"{FileName}ApplicationService.cs";
- public string CreateDtoName => $"{FileName}CreateDto.cs";
- public string UpdateDtoName => $"{FileName}UpdateDto.cs";
- public string ListDtoName => $"{FileName}Dto.cs";
- public string ControllerName => $"{FileName}Controller.cs";
- public string ViewsName => $"{FileName}.cshtml";
- #endregion Name
- }
- }
|