Beispiel #1
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);
        }
Beispiel #2
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);
        }
Beispiel #3
0
        public ActionResult <ApiResult <TableModel <TemplateGridViewModel> > > GetTemplateList([FromForm] TemplateViewModel model)
        {
            var result = new ApiResult <TableModel <TemplateGridViewModel> >();

            result.Data = new TableModel <TemplateGridViewModel>();
            int count = 0;
            var list  = TemplateDb.AsQueryable()
                        .ToPageList(model.PageIndex, model.PageSize, ref count);

            result.Data.Rows       = mapper.Map <List <TemplateGridViewModel> >(list);
            result.Data.Total      = count;
            result.Data.PageSize   = model.PageSize;
            result.Data.PageNumber = model.PageIndex;
            result.IsSuccess       = true;
            return(result);
        }
Beispiel #4
0
        public ActionResult <ApiResult <List <TreeModel> > > GetTemplate(int type)
        {
            List <TreeModel> trees = new List <TreeModel>();
            var databses           = TemplateDb.GetList(it => it.TemplateTypeId == type || type == 0);

            foreach (var db in databses)
            {
                trees.Add(new TreeModel()
                {
                    Id           = db.Id.ToString(),
                    Title        = db.Title,
                    IsSelectable = true
                });
            }
            ApiResult <List <TreeModel> > result = new ApiResult <List <TreeModel> >();

            result.Data      = trees;
            result.IsSuccess = true;
            return(result);
        }
Beispiel #5
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);
        }
Beispiel #6
0
        public ActionResult <ApiResult <bool> > DeleteTemplate([FromForm] string model)
        {
            var result = new ApiResult <bool>();

            if (!string.IsNullOrEmpty(model))
            {
                var list   = Newtonsoft.Json.JsonConvert.DeserializeObject <List <TemplateViewModel> >(model);
                var isInit = Db.Queryable <Template>().In(list.Select(it => it.Id).ToList()).Any(it => it.IsInit == true);
                base.Check(isInit, "无法删除初始化数据");
                var exp = Expressionable.Create <Template>();
                foreach (var item in list)
                {
                    exp.Or(it => it.Id == item.Id);
                }
                TemplateDb.Update(it => new Template()
                {
                    IsDeleted = true
                }, exp.ToExpression());
            }
            result.IsSuccess = true;
            return(result);
        }