public IActionResult GenerateCode([FromBody] object[] data)
        {
            List <string> spCollection = new List <string>();

            try
            {
                string webRootPath     = _hostingEnvironment.WebRootPath;     //From wwwroot
                string contentRootPath = _hostingEnvironment.ContentRootPath; //From Others

                var tblColumns = JsonConvert.DeserializeObject <List <vmColumn> >(data[0].ToString());

                string fileContentSet = string.Empty; string fileContentGet = string.Empty;
                string fileContentPut = string.Empty; string fileContentDelete = string.Empty;
                string fileContentVm = string.Empty; string fileContentView = string.Empty;
                string fileContentNg = string.Empty; string fileContentAPIGet = string.Empty;
                string fileContentAPIGetById = string.Empty;

                //SP
                fileContentSet    = SpGenerator.GenerateSetSP(tblColumns, webRootPath);
                fileContentGet    = SpGenerator.GenerateGetSP(tblColumns, webRootPath);
                fileContentPut    = SpGenerator.GeneratePutSP(tblColumns, webRootPath);
                fileContentDelete = SpGenerator.GenerateDeleteSP(tblColumns, webRootPath);
                spCollection.Add(fileContentSet);
                spCollection.Add(fileContentGet);
                spCollection.Add(fileContentPut);
                spCollection.Add(fileContentDelete);

                //VM
                fileContentVm = VmGenerator.GenerateVm(tblColumns, webRootPath);
                spCollection.Add(fileContentVm);

                //VU
                fileContentView = ViewGenerator.GenerateForm(tblColumns, webRootPath);
                spCollection.Add(fileContentView);

                //NG
                fileContentNg = NgGenerator.GenerateNgController(tblColumns, webRootPath);
                spCollection.Add(fileContentNg);

                //API
                fileContentAPIGet = APIGenerator.GenerateAPIGet(tblColumns, webRootPath);
                spCollection.Add(fileContentAPIGet);
            }
            catch (Exception ex)
            {
                ex.ToString();
            }

            return(Json(new
            {
                spCollection
            }));
        }
        public IActionResult GenerateCode([FromBody] vmGenerator data)
        {
            var spCollection = new List <string>();

            try
            {
                var webRootPath     = _hostingEnvironment.WebRootPath;     //From wwwroot
                var contentRootPath = _hostingEnvironment.ContentRootPath; //From Others

                var tblColumns     = data.Columns;
                var fullTblColumns = GetTableColumns(data.DatabaseName, data.TableName);

                var fileContentSet            = string.Empty;
                var fileContentGet            = string.Empty;
                var fileContentGetByID        = string.Empty;
                var fileContentPut            = string.Empty;
                var fileContentDelete         = string.Empty;
                var fileContentViewSp         = string.Empty;
                var fileContentIEntity        = string.Empty;
                var fileContentModifiedEntity = string.Empty;
                var fileContentEntities       = string.Empty;
                var fileContentDtos           = string.Empty;
                var fileContentCoreRepo       = string.Empty;
                var fileContentView           = string.Empty;
                var fileContentAPIGet         = string.Empty;
                var fileContentInterface      = string.Empty;
                var fileContentService        = string.Empty;
                var fileContentDbContext      = string.Empty;
                var fileContentUnitOfWork     = string.Empty;
                var fileContentCrud           = string.Empty;
                var fileModelDapper           = string.Empty;
                var fileIUnitDapper           = string.Empty;
                var fileRepoDapper            = string.Empty;

                //SP
                fileContentSet     = SpGenerator.GenerateInsertSP(tblColumns, webRootPath);
                fileContentGet     = SpGenerator.GenerateSelectSP(tblColumns, webRootPath);
                fileContentGetByID = SpGenerator.GenerateSelectByIDSP(tblColumns, webRootPath);
                fileContentPut     = SpGenerator.GenerateUpdateSP(tblColumns, webRootPath);
                fileContentDelete  = SpGenerator.GenerateDeleteSP(tblColumns, webRootPath);
                fileContentViewSp  = SpGenerator.GenerateViewSP(tblColumns, webRootPath);
                spCollection.Add(fileContentSet);
                spCollection.Add(fileContentGet);
                spCollection.Add(fileContentGetByID);
                spCollection.Add(fileContentPut);
                spCollection.Add(fileContentDelete);
                spCollection.Add(fileContentViewSp);

                //CORE
                fileContentIEntity        = VmGenerator.GenerateIEntity(webRootPath);
                fileContentModifiedEntity = VmGenerator.GenerateModifiedEntity(webRootPath);
                fileContentEntities       = VmGenerator.GenerateEntities(fullTblColumns, webRootPath);
                fileContentDtos           = VmGenerator.GenerateDtos(tblColumns, webRootPath);
                fileContentCoreRepo       = VmGenerator.GenerateIRepository(tblColumns, webRootPath);
                spCollection.Add(fileContentIEntity);
                spCollection.Add(fileContentModifiedEntity);
                spCollection.Add(fileContentEntities);
                spCollection.Add(fileContentDtos);
                spCollection.Add(fileContentCoreRepo);

                //VU
                fileContentView = ViewGenerator.GenerateForm(tblColumns, webRootPath);
                spCollection.Add(fileContentView);

                //API
                fileContentAPIGet = APIGenerator.GenerateAPIGet(tblColumns, webRootPath);
                spCollection.Add(fileContentAPIGet);

                //API SERVICE/INTERFACE
                fileContentInterface = SIGenerator.GenerateInterfaces(tblColumns, webRootPath);
                fileContentService   = SIGenerator.GenerateService(tblColumns, webRootPath);
                spCollection.Add(fileContentInterface);
                spCollection.Add(fileContentService);

                //EF REPO
                fileContentDbContext  = RepoEFGenerator.GenerateDbContext(tblColumns, webRootPath);
                fileContentUnitOfWork = RepoEFGenerator.GenerateUnitOfWork(webRootPath);
                fileContentCrud       = RepoEFGenerator.GenerateCrud(tblColumns, webRootPath);
                spCollection.Add(fileContentDbContext);
                spCollection.Add(fileContentUnitOfWork);
                spCollection.Add(fileContentCrud);

                //DAPPER REPO
                fileModelDapper = DapperGenerator.GenerateModel(tblColumns, webRootPath);
                fileIUnitDapper = DapperGenerator.GenerateUnitOfWork(tblColumns, webRootPath);
                fileRepoDapper  = DapperGenerator.GenerateRepository(tblColumns, webRootPath);
                spCollection.Add(fileModelDapper);
                spCollection.Add(fileIUnitDapper);
                spCollection.Add(fileRepoDapper);
            }
            catch (Exception ex)
            {
                ex.ToString();
            }

            return(Json(new
            {
                spCollection
            }));
        }
Пример #3
0
        public ActionResult Generate(FormCollection form)
        {
            var vm = new PopulateTablesViewModel();

            vm.AppName      = form["AppName"];
            vm.ConxType     = form["ConxType"];
            vm.DatabaseName = form["DatabaseName"];
            vm.ScaffoldType = form["ScaffoldType"];
            vm.ServerName   = form["ServerName"];
            vm.Username     = form["Username"];
            vm.Password     = form["Password"];
            var tables = form["Tables"];

            var formatedList = tables.Split(',');

            try
            {
                var conxString = GetConnectionString(vm);
                DataAccessSql.ConnectionString = conxString;
                bool writeFiles = false;
                bool writeSP    = false;
                switch (vm.ScaffoldType)
                {
                case "Both":
                    writeFiles = true;
                    writeSP    = true;
                    break;

                case "SP Only":
                    writeSP = true;
                    break;

                case "Files Only":
                    writeFiles = true;
                    break;
                }

                List <DatabaseTable> databaseTableList = new List <DatabaseTable>();
                var genUp = new SpGenerator();
                genUp.timestamp = DateTime.Now.ToString("yyyyMMddhhmmss");
                genUp.AppName   = vm.AppName;
                foreach (string checkedItem in formatedList)
                {
                    databaseTableList.Add(new DatabaseTable()
                    {
                        TableName              = checkedItem.ToString(),
                        SingularName           = checkedItem.ToString().Replace("dbo.", "").Replace(".", "").Trim(),
                        PluralName             = checkedItem.ToString().Replace("dbo.", "").Replace(".", "").Trim(),
                        DeleteProcedure        = true,
                        UpdateProcedure        = true,
                        InsertProcedure        = true,
                        SelectProcedure        = true,
                        SelectDetailsProcedure = true,
                        CreateTables           = true,
                        WriteFiles             = writeFiles,
                        WriteProcedures        = writeSP
                    });
                }
                genUp.GenerateStoreProcedures(conxString, databaseTableList);
            }
            catch (Exception ex)
            {
                return(View("Generate", ex.Message));
            }

            return(View("Generate"));
        }