public ActionResult <ApiResult <string> > Copy([FromForm] ProjectViewModel2 model) { var result = new ApiResult <string>(); var tables = model.Tables; var project = ProjectDb.GetSingle(it => it.Id == model.ProjectId); base.Check(project == null, "请选择方案,没有方案可以在手动生成里面创建"); model.Tables = tables; var template = TemplateDb.GetById(project.TemplateId1).Content; var tableids = Newtonsoft.Json.JsonConvert.DeserializeObject <List <CodeTypeGridViewModel> >(model.Tables).Select(it => it.Id).ToList(); var tableList = CodeTableDb.GetList(it => tableids.Contains(it.Id)); int dbId = tableList.First().DbId; var connection = base.GetTryDb(dbId); List <EntitiesGen> genList = GetGenList(tableList, CodeTypeDb.GetList(), connection.CurrentConnectionConfig.DbType); string key = TemplateHelper.EntityKey + template.GetHashCode(); foreach (var item in genList.Take(1)) { item.name_space = GetNameSpace(project.FileModel, item.name_space); result.Data = TemplateHelper.GetTemplateValue(key, template, item); } ProjectController_Common.CreateProject(project.Id, model.DbId.Value); result.IsSuccess = true; return(result); }
public ActionResult <ApiResult <bool> > CreateFileByProjectId([FromForm] ProjectViewModel2 model, bool disOpen = true) { var result = new ApiResult <bool>(); var tables = model.Tables; var project = ProjectDb.GetSingle(it => it.Id == model.ProjectId); base.Check(project == null, "请选择方案"); model.Tables = tables; var template = TemplateDb.GetById(project.TemplateId1).Content; var tableids = Newtonsoft.Json.JsonConvert.DeserializeObject <List <CodeTypeGridViewModel> >(model.Tables).Select(it => it.Id).ToList(); var tableList = CodeTableDb.GetList(it => tableids.Contains(it.Id)); int dbId = tableList.First().DbId; var connection = base.GetTryDb(dbId); List <EntitiesGen> genList = GetGenList(tableList, CodeTypeDb.GetList(), connection.CurrentConnectionConfig.DbType); string key = TemplateHelper.EntityKey + template.GetHashCode(); foreach (var item in genList) { item.name_space = GetNameSpace(project.FileModel, item.name_space); var html = TemplateHelper.GetTemplateValue(key, template, item); var fileName = GetFileName(project, item); FileSugar.CreateFileReplace(fileName, html, Encoding.UTF8); } OpenPath(disOpen, project); ProjectController_Common.CreateProject(project.Id, model.DbId.Value); result.IsSuccess = true; result.Message = "生成生功"; return(result); }