Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        public ActionResult <ApiResult <bool> > CreateFile([FromForm] ProjectViewModel model)
        {
            base.Check(model.Reference != null && model.Reference.Split(',').Contains(model.Id + ""), "方案不能自已引用自已");
            base.Check(new System.IO.DirectoryInfo(model.Path)?.Parent?.Parent == null, "路径" + model.Path + "错误,正确格式  C:\\解决方案\\项目");
            var result   = new ApiResult <bool>();
            var tempInfo = TemplateDb.GetById(model.TemplateId1);

            model.ModelId = tempInfo.TemplateTypeId;
            var dbModel = mapper.Map <Project>(model);
            var s       = base.Db.Storageable(dbModel)
                          .SplitError(it => string.IsNullOrEmpty(model.Tables), "请选择表")
                          .SplitError(it => Db.Queryable <Project>().Any(s => s.Id != model.Id && s.ProjentName == model.ProjentName && s.TemplateId1 == model.TemplateId1), "方前方案已存在请换个名字或者使用方案生成")
                          .Saveable()
                          .ToStorage();
            var id = s.AsInsertable.ExecuteReturnIdentity();

            s.AsUpdateable.ExecuteCommand();
            if (s.ErrorList.Any())
            {
                throw new Exception(s.ErrorList.First().StorageMessage);
            }
            //var template = TemplateDb.GetById(model.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(model.FileModel,item.name_space);
            //    var html = TemplateHelper.GetTemplateValue(key, template, item);
            //    var fileName = GetFileName(model, item);
            //    FileSugar.CreateFileReplace(fileName, html, Encoding.UTF8);
            //}
            //ProjectController_Common.CreateProject(dbModel);
            result.IsSuccess = true;
            result.Message   = model.Id == 0 ? "创建成功" : "修改成功";
            return(result);
        }