public string CreateOrUpdate(TemplateFile model) { string name = model.Name; string relativePath = model.RelativePath; if (relativePath.IsNullOrWhiteSpace()) { return("文件相对路径错误"); } if (name.EndsWith(_cshtml.Substring(1)) || name.EndsWith(_fluid.Substring(1))) { relativePath = relativePath.TrimStart('~'); model.Path = _env.MapWebRootPath(relativePath.Split('/')); if (model.Id > 0) { var old = Get(model.Id); if (!old.Name.Equals(model.Name, StringComparison.InvariantCultureIgnoreCase)) { //model.Path = _env.MapWebRootPath(_themeName, model.ThemeName, _viewName, model.Name); //model.RelativePath = GetRelativePath(model.Path, _env.WebRootPath.Length); ExtFile.DeleteFile(old.Path); } } ExtFile.WriteFile(model.Path, model.Content); _cacheMgr.Remove(_templateFilesCacheKey); return(string.Empty); } return("文件名称格式错误"); }
public void Delete(int id) { var model = Get(id); ExtFile.DeleteFile(model.Path); _cacheMgr.Remove(_templateFilesCacheKey); }
public virtual ServiceResult <TemplateFile> CreateOrUpdate(TemplateFile model) { string name = model.Name; string relativePath = model.RelativePath; ServiceResult <TemplateFile> result = new ServiceResult <TemplateFile>(); string ext = Path.GetExtension(name); if (GetSupportFileExtensions().Contains(ext)) { relativePath = relativePath.TrimStart('~'); model.Path = _webHostEnvironment.MapWebRootPath(relativePath.Split('/')); if (model.Id > 0) { var old = Get(model.Id); if (!old.Name.Equals(model.Name, StringComparison.InvariantCultureIgnoreCase)) { ExtFile.DeleteFile(old.Path); } } ExtFile.WriteFile(model.Path, model.Content); EnsureHasViewImports(model.Path); _cacheMgr.Remove(_templateFilesCacheKey); result.Result = GetTemplateFiles().First(m => m.RelativePath == model.RelativePath); } else { result.RuleViolations.Add(new RuleViolation("Name", "File not support")); } return(result); }
public ServiceResult <TemplateFile> CreateOrUpdate(TemplateFile model) { string name = model.Name; string relativePath = model.RelativePath; ServiceResult <TemplateFile> result = new ServiceResult <TemplateFile>(); if (name.EndsWith(_cshtml.Substring(1))) { relativePath = relativePath.TrimStart('~'); model.Path = _webHostEnvironment.MapWebRootPath(relativePath.Split('/')); if (model.Id > 0) { var old = Get(model.Id); if (!old.Name.Equals(model.Name, StringComparison.InvariantCultureIgnoreCase)) { ExtFile.DeleteFile(old.Path); } } ExtFile.WriteFile(model.Path, model.Content); _cacheMgr.Remove(_templateFilesCacheKey); result.Result = GetTemplateFiles().First(m => m.Name == name); } else { result.RuleViolations.Add(new RuleViolation("Name", "文件名称格式错误")); } return(result); }
public void Delete(int id) { var model = Get(id); if (model.Name != _viewImportsFileName) { ExtFile.DeleteFile(model.Path); _cacheMgr.Remove(_templateFilesCacheKey); } }