Esempio n. 1
0
 public IActionResult ProjectLoad([FromBody] string ProjectID)
 {
     if (ProjectID != null)
     {
         var context   = new Model.Context();
         var projectdb = context.Projects.Where(c => c.Id == Convert.ToInt32(ProjectID)).FirstOrDefault();
         var Project   = new Tempproj();
         Project.Data = new ConectionData()
         {
             ConnectionString = projectdb.ConnectionString,
             ContextName      = projectdb.ContextName,
             ProjName         = projectdb.ProjectName
         };
         Project.Id           = projectdb.Id;
         Project.FileNames    = context.Model.Where(c => c.Projectid == projectdb.Id).Select(e => e.Filename).ToList();
         Project.Models       = context.Model.Where(c => c.Projectid == projectdb.Id).Select(e => e.Model1).ToList();
         Project.RandomEnding = randomEndingForFolder;
         context.Dispose();
         return(Ok(Project));
     }
     else
     {
         return(BadRequest());
     }
 }
Esempio n. 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);
        }
Esempio n. 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));
            }
        }