public ActionResult <ApiResult <bool> > SaveCodetableImport([FromForm] int dbid, [FromForm] string model) { ApiResult <bool> result = new ApiResult <bool>(); var list = Newtonsoft.Json.JsonConvert.DeserializeObject <List <DbTableGridViewModel> >(model); var tableDb = base.GetTryDb(dbid); var systemDb = Db; var type = CodeTypeDb.GetList(); var entityList = CodeTableDb.GetList(it => it.DbId == dbid); systemDb.BeginTran(); try { List <CodeTable> Inserts = new List <CodeTable>(); foreach (var item in list) { CodeTableViewModel code = new CodeTableViewModel() { ClassName = PubMehtod.GetCsharpName(item.Name), TableName = item.Name, DbId = dbid, Description = item.Description, ColumnInfoList = new List <CodeColumnsViewModel>() }; var entity = entityList.FirstOrDefault(it => it.TableName.Equals(item.Name, StringComparison.OrdinalIgnoreCase)); if (entity == null) { entity = new CodeTable(); } foreach (var columnInfo in tableDb.DbMaintenance.GetColumnInfosByTableName(item.Name, false)) { var typeInfo = GetEntityType(type, columnInfo, this, tableDb.CurrentConnectionConfig.DbType); CodeColumnsViewModel column = new CodeColumnsViewModel() { ClassProperName = PubMehtod.GetCsharpName(columnInfo.DbColumnName), DbColumnName = columnInfo.DbColumnName, Description = columnInfo.ColumnDescription, IsIdentity = columnInfo.IsIdentity, IsPrimaryKey = columnInfo.IsPrimarykey, Required = columnInfo.IsNullable == false, CodeTableId = entity.Id, CodeType = typeInfo.CodeType.Name, Length = typeInfo.DbTypeInfo.Length, DecimalDigits = typeInfo.DbTypeInfo.DecimalDigits, DefaultValue = columnInfo.DefaultValue }; code.ColumnInfoList.Add(column); } SaveCodeTableToDb(code); } ; systemDb.CommitTran(); result.IsSuccess = true; } catch (Exception ex) { systemDb.RollbackTran(); throw ex; } return(result); }
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); }