using System;
using System.Collections.Generic;
namespace VberAdmin.Models
{
public class TemplateViewModel : CopyRightUserInfo
{
#region Data
public TemplateViewModel()
{
IdType = "int";
ParentPath = "";
ExtFilePath = "";
}
///
/// 页面标题
///
public string HtmlPageTitle { get; set; }
///
/// 模态框标题
///
public string HtmlModalTitle { get; set; }
///
/// 项目名称
///
public string ProjectName { get; set; }
///
/// 表名即类名
///
private string _className;
///
/// 如果有s或者es则去掉
///
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;
///
/// 命名空间
///
public string ClassNamespace { get; set; }
///
/// 是否多条件查询
///
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;
}
///
/// 父路径(不包含Pages)
///
public string ParentPath { get; set; }
///
/// Application命名空间
///
public string ApplicationNamespace => ClassNamespace?.Replace(".Core", "") +
(string.IsNullOrEmpty(ExtFilePath)
? ""
: $".{ExtFilePath.Replace("\\", ".")}");
///
/// id的类型
///
public string IdType { get; set; }
///
/// 首字母小写
///
public string CamelClassName => ClassName.Substring(0, 1).ToLower() + ClassName.Substring(1, ClassName.Length - 1);
private string _baseFolder;
///
/// 基础代码路径
///
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 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\\";
///
/// 生成Service文件的路径
///
public string ServiceFolder
{
get => string.IsNullOrEmpty(_serviceFolder)
? $"{BaseFolder.Replace(".Core", ".Application")}{(string.IsNullOrEmpty(ExtFilePath) ? "" : $"{ExtFilePath}\\")}"
: _serviceFolder;
set => _serviceFolder = value;
}
private string _dtoFolder;
///
/// 生成DTO的路径
///
public string DtoFolder
{
get => string.IsNullOrEmpty(_dtoFolder)
? $"{ServiceFolder}Dto\\"
: _dtoFolder;
set => _dtoFolder = value;
}
///
/// 项目路径
///
public string ProjectFolder => BaseFolder.Substring(0, BaseFolder.IndexOf(ProjectName + ".Core", StringComparison.Ordinal));
///
/// Web项目路径
///
public string WebFolder => $"{ProjectFolder}{WebName}\\";
private string _controllerFolder;
///
/// 控制器路径
///
public string ControllerFolder
{
get => string.IsNullOrEmpty(_controllerFolder)
? $"{WebFolder}Controllers\\"
: _controllerFolder;
set => _controllerFolder = value;
}
private string _viewsFolder;
///
/// 视图路径
///
public string ViewsFolder
{
get => string.IsNullOrEmpty(_viewsFolder)
? $"{WebFolder}Views\\{ParentFileName}\\"
: _viewsFolder;
set => _viewsFolder = value;
}
///
/// 模板路径
///
public string TemplateFolder { get; set; } = @"..\..\Templates";
///
/// 模板文件相对位置
///
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
}
}