예제 #1
0
        public void addProjToUser(ConectionData data, ScaffoldedModel models)
        {
            Model.Context context = new Model.Context();
            Model.User    user    = context.User.Where(c => c.LoginName == User.Identity.Name).FirstOrDefault();

            Model.Projects project = new Model.Projects();
            project.Owner            = user;
            project.OwnerId          = user.Id;
            project.ProjectName      = data.ProjName;
            project.ContextName      = data.ContextName;
            project.ConnectionString = data.ConnectionString;
            context.Add(project);
            foreach (var file in models.AdditionalFiles)
            {
                Model.Model model = new Model.Model();
                model.Project   = project;
                model.Projectid = project.Id;
                model.Model1    = file.Code;
                model.Filename  = Path.GetFileName(file.Path);
                context.Add(model);
            }
            Model.Model ContextModel = new Model.Model();
            ContextModel.Project   = project;
            ContextModel.Projectid = project.Id;
            ContextModel.Model1    = models.ContextFile.Code;
            ContextModel.Filename  = Path.GetFileName(models.ContextFile.Path);
            context.Add(ContextModel);
            context.SaveChanges();
            context.Dispose();
        }
예제 #2
0
        public Tempproj GenerateTempProject(ConectionData data, string ending, ScaffoldedModel models)
        {
            DiplomWork.Model.Context context     = new Model.Context();
            Model.TempProjects       tempProject = new Model.TempProjects();
            tempProject.ConnectionString = data.ConnectionString;
            tempProject.ContextName      = data.ContextName;
            tempProject.ProjectName      = data.ProjName;
            Tempproj tempproj = new Tempproj();

            context.Add(tempProject);
            tempproj.Models    = new List <string>();
            tempproj.FileNames = new List <string>();
            foreach (var file in models.AdditionalFiles)
            {
                DiplomWork.Model.Model model = new DiplomWork.Model.Model();
                model.Tempproject           = tempProject.Id;
                model.Model1                = file.Code;
                model.Filename              = Path.GetFileName(file.Path);
                model.TempprojectNavigation = tempProject;
                context.Add(model);
                context.SaveChanges();
                tempproj.FileNames.Add(Path.GetFileName(file.Path));
                tempproj.Models.Add(file.Code);
            }
            tempproj.FileNames.Add(Path.GetFileName(models.ContextFile.Path));
            tempproj.Models.Add(models.ContextFile.Code);
            DiplomWork.Model.Model Contextmodel = new DiplomWork.Model.Model();
            Contextmodel.Tempproject = tempProject.Id;
            Contextmodel.Model1      = models.ContextFile.Code;
            Contextmodel.Filename    = Path.GetFileName(models.ContextFile.Path);
            context.Add(Contextmodel);

            context.SaveChanges();
            tempproj.Id           = tempProject.Id;
            tempproj.RandomEnding = ending;
            tempproj.Data         = data;
            context.Dispose();
            return(tempproj);
        }
예제 #3
0
        public IActionResult ModelGenerate([FromBody] ConectionData data, string RandomEnding = null)
        {
            if (RandomEnding != null)
            {
                randomEndingForFolder = RandomEnding;
            }

            try
            {
                if (string.IsNullOrEmpty(value: data.ContextName))
                {
                    data.ContextName = "Context";
                }

                if (!string.IsNullOrEmpty(data.ConnectionString))
                {
                    string filter = "";
                    if (!data.selectedTables.Distinct().Any())
                    {
                        filter = "dbo";
                    }

                    var models = CustomReverseEngineerScaffolder.ScaffoldContext(
                        provider: "Microsoft.EntityFrameworkCore.SqlServer",
                        connectionString: data.ConnectionString,
                        outputDir: Path.GetTempPath() + "Model_" + randomEndingForFolder,
                        outputContextDir: Path.GetTempPath() + "Model_" + randomEndingForFolder,
                        dbContextClassName: data.ContextName,
                        schemas: new string[] { filter },
                        tables: data.selectedTables.Distinct().Count() > 0 ? data.selectedTables.Distinct() : Array.Empty <string>(),
                        useDataAnnotations: false,
                        overwriteFiles: true,
                        useDatabaseNames: true
                        );

                    var TempProj = new Tempproj();

                    if (User.Identity.IsAuthenticated)
                    {
                        if (data.ProjName == "")
                        {
                            data.ProjName = "TEMP_PROJ_" + randomEndingForFolder;
                        }
                        addProjToUser(data, models);
                        TempProj.Models = models.AdditionalFiles.Select(c => c.Code).ToList();
                        TempProj.Models.Add(models.ContextFile.Code);
                        TempProj.FileNames = models.AdditionalFiles.Select(c => Path.GetFileName(c.Path)).ToList();
                        TempProj.FileNames.Add(Path.GetFileName(models.ContextFile.Path));
                    }
                    else
                    {
                        TempProj = GenerateTempProject(data, randomEndingForFolder, models);
                    }

                    return(Ok(TempProj));
                }
                else
                {
                    return(BadRequest("ConnectionString empty"));
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }