public async Task <IActionResult> AddItem( [FromBody] AConMvcClass systemHtml) { systemHtml.Addtime = DateTime.Now; if (string.IsNullOrEmpty(systemHtml.Guid)) { systemHtml.Guid = Guid.NewGuid().ToString("D"); } var oldmvc = await DbFactory.Queryable <AConMvcClass>().Where(p => p.ClassName.ToLower() == systemHtml.ClassName.ToLower()).FirstAsync(); if (oldmvc != null) { return(Json(new { isok = false, err = $"has the same class {systemHtml.ClassName }" })); } var reint = await DbFactory.Insertable(systemHtml).ExecuteCommandAsync(); if (systemHtml.IsEanable.ToBool() == true) { try { var aConMvcCompileClass = AConMvcCompileClass.ToCompileClass(systemHtml); _actionProvider.AddControllers(aConMvcCompileClass); _dynamicChangeTokenProvider.NotifyChanges(); return(Json(new { isok = true })); } catch (Exception ex) { return(Json(new { isok = false, err = ex.Message })); } } return(Json(new { isok = reint > 0 })); }
public async Task <IActionResult> UpdateItem([FromBody] AConMvcClass systemHtml) { if (string.IsNullOrEmpty(systemHtml.Guid)) { systemHtml.Guid = Guid.NewGuid().ToString("D"); } var aConMvcCompileClass = AConMvcCompileClass.ToCompileClass(systemHtml); var result = await DbFactory.Queryable <AConMvcClass>().Where(p => p.Id == systemHtml.Id).FirstAsync(); if (result != null) { _actionProvider.RemoveController(aConMvcCompileClass); _dynamicChangeTokenProvider.NotifyChanges(); result = systemHtml; } var reint = await DbFactory.Updateable(result).ExecuteCommandAsync(); if (systemHtml.IsEanable.ToBool() == true) { try { _actionProvider.AddControllers(aConMvcCompileClass); _dynamicChangeTokenProvider.NotifyChanges(); return(Json(new { isok = true })); } catch (Exception ex) { return(Json(new { isok = false, err = ex.Message })); } } return(Json(new { isok = reint >= 0 })); }
private static AConMvcCompileClass ToCompileClass(AConMvcClass systemHtml, string source) { return(new AConMvcCompileClass() { Guid = systemHtml.Guid, ActionCode = systemHtml.ActionCode , AllSourceCode = source , Addtime = systemHtml.Addtime , ClassAttrs = systemHtml.ClassAttrs , ClassName = systemHtml.ClassName , ExReferenceName = systemHtml.ExReferenceName , IsEanable = systemHtml.IsEanable , Name = systemHtml.Name , Id = systemHtml.Id , UrlRule = systemHtml.UrlRule , UsingNameSpance = systemHtml.UsingNameSpance , VersionNum = systemHtml.VersionNum }); }
public static string ToSourceCode(AConMvcClass systemHtml) { var nameSpace = GetDefaultNamespace() + systemHtml.UsingNameSpance; var strinbuilder = nameSpace + "\r\n" + systemHtml.ClassAttrs + "\r\n" + " public partial class "; if (systemHtml.IsSelfDefine == true) { strinbuilder += systemHtml.ClassName; } else { strinbuilder += systemHtml.ClassName + "Controller"; if (!string.IsNullOrEmpty(systemHtml.InhiredClass)) { strinbuilder += ":" + systemHtml.InhiredClass; } else if (systemHtml.IsController == true) { strinbuilder += ": Microsoft.AspNetCore.Mvc.Controller"; } } return(strinbuilder += "\r\n{ \r\n" + systemHtml.ActionCode + "\r\n}"); }
public static AConMvcCompileClass ToCompileClass(AConMvcClass systemHtml) { var newclass = new AConMvcCompileClass() { Guid = systemHtml.Guid, ActionCode = systemHtml.ActionCode, Addtime = systemHtml.Addtime, ClassAttrs = systemHtml.ClassAttrs, ClassName = systemHtml.ClassName, ExReferenceName = systemHtml.ExReferenceName, IsEanable = systemHtml.IsEanable, Name = systemHtml.Name, Id = systemHtml.Id, UrlRule = systemHtml.UrlRule, UsingNameSpance = systemHtml.UsingNameSpance, VersionNum = systemHtml.VersionNum }; newclass.AllSourceCode = APPCommon.ToSourceCode(systemHtml); return(newclass); }