Ejemplo n.º 1
0
        public JsonResult IndexPost([FromBody] DynamicObjectsViewModel dynamicObjectsViewModel)//List<DynamicCreationViewModel> dynamicCreationViewModels)
        {
            string message = string.Empty;
            object responseJSON;

            if (string.IsNullOrEmpty(dynamicObjectsViewModel.Service))
            {
                responseJSON = new { isSuccess = false, message = "Service name is required" }
            }
            ;
            else if (string.IsNullOrEmpty(dynamicObjectsViewModel.Page))
            {
                responseJSON = new { isSuccess = false, message = "Page name is required" }
            }
            ;
            else if (dynamicObjectsViewModel.FieldsDetailViewModel.Count > 0)
            {
                GenerateDynamics(dynamicObjectsViewModel);
                responseJSON = new { isSuccess = true, message = "Objects have been created successfully" };
            }
            else
            {
                responseJSON = new { isSuccess = false, message = "Field(s) are required" }
            };

            return(Json(responseJSON));
        }
 public static bool Index(string directory, DynamicObjectsViewModel dynamicObjectsViewModel)
 {
     try
     {
         string responsibleView = "\n\t\t" + @"[HttpGet]" +
                                  "\n\t\tpublic IActionResult Index()" +
                                  "\n\t\t{\n " +
                                  "\n\t\t\tstring viewName = string.Empty; " +
                                  "\n\t\t\tviewName = HttpContext.Session.GetString(\"Service\")+" + "\"" + dynamicObjectsViewModel.Page + "\";" +
                                  //"\n\t\t\tTempData.Keep(\"Group\");" +
                                  "\n\t\t\treturn View(" + "viewName" + ");\n\t\t}";
         var file                 = Path.Combine(directory, dynamicObjectsViewModel.Page + "Controller.cs");
         var txtLines             = System.IO.File.ReadAllLines(file).ToList();
         int actionIndexToBeAdded = txtLines.Count() - 2;
         if (!txtLines.Contains("\t\tpublic IActionResult Index()"))
         {
             txtLines.Insert(actionIndexToBeAdded, responsibleView);
             System.IO.File.WriteAllLines(file, txtLines);
         }
     }
     catch (Exception exception)
     {
         Console.WriteLine(exception.Message);
         return(false);
     }
     return(true);
 }
 public static bool AddRefernces(string directory, DynamicObjectsViewModel dynamicObjectsViewModel)
 {
     try
     {
         var    file       = Path.Combine(directory, dynamicObjectsViewModel.Page + "Controller.cs");
         string references = @""
                             + "using System.Threading.Tasks;\n"
                             + "using DynamicObjects.Models;\n"
                             + "using Microsoft.AspNetCore.Http;\n"
                             + "using Microsoft.AspNetCore.Mvc;\n"
                             + "namespace DynamicObjects.Controllers\n{"
                             + "\n\tpublic class " + dynamicObjectsViewModel.Page + "Controller : Controller\n\t{"
                             + "\n\t}\n}"
                             + ""
         ;
         var txtLines             = System.IO.File.ReadAllLines(file).ToList();
         int actionIndexToBeAdded = txtLines.Count();// - 3;
         if (!txtLines.Contains("namespace DynamicObjects.Controllers"))
         {
             txtLines.Insert(actionIndexToBeAdded, references);
             System.IO.File.WriteAllLines(file, txtLines);
         }
     }
     catch (Exception exception)
     {
         Console.WriteLine(exception.Message);
         return(false);
     }
     return(true);
 }
Ejemplo n.º 4
0
        public static bool Content(string directory, DynamicObjectsViewModel dynamicObjectsViewModel)
        {
            try
            {
                var file = Path.Combine(directory, dynamicObjectsViewModel.Service + dynamicObjectsViewModel.Page + "ViewModel.cs");
                using (TextWriter text = new StreamWriter(file))
                {
                    text.WriteLine(@""
                                   + "\nusing System;"
                                   + "\nusing System.Collections.Generic;"
                                   + "\nusing System.Linq;"
                                   + "\nusing System.Threading.Tasks;"
                                   + "\nusing System.ComponentModel.DataAnnotations;"
                                   + "\nnamespace DynamicObjects.Models." + dynamicObjectsViewModel.Page + "" + "\n{" +
                                   "\n\tpublic class " + dynamicObjectsViewModel.Service + dynamicObjectsViewModel.Page + "ViewModel" +
                                   "\n\t{"
                                   );
                    text.WriteLine("\t\t[Key]\n\t\t[ScaffoldColumn(true)]");
                    text.WriteLine("\t\tpublic int Id {get;set;}");
                }
                foreach (var row in dynamicObjectsViewModel.FieldsDetailViewModel)
                {
                    using (StreamWriter text = new StreamWriter(file, true))
                    {
                        if (row.FieldType.Equals("string"))
                        {
                            text.WriteLine("\t\t[MaxLength(" + row.MaxLength + "),MinLength(" + row.MinLength + ")]");
                        }
                        else
                        {
                            text.WriteLine("\t\t[Range(" + row.MinLength + "," + row.MaxLength + ")]");
                        }
                        if (row.IsRequired)
                        {
                            text.WriteLine("\t\t[Required]");
                        }

                        text.WriteLine("\t\tpublic " + row.FieldType + " " + row.FieldName + " {get;set;}");
                        text.WriteLine();
                    }
                }
                using (StreamWriter text = new StreamWriter(file, true))
                {
                    text.WriteLine("\t}");
                    text.WriteLine("}");
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception.Message);
                return(false);
            }
            return(true);
        }
 public static bool Generate(string directory, DynamicObjectsViewModel dynamicObjectsViewModel)
 {
     try
     {
         var file = Path.Combine(directory, dynamicObjectsViewModel.Page + "Controller.cs");
         if (!System.IO.File.Exists(file))
         {
             System.IO.File.Create(file).Dispose();
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         return(false);
     }
     return(true);
 }
Ejemplo n.º 6
0
        public static bool AddContent(string directory, DynamicObjectsViewModel dynamicObjectsViewModel)
        {
            //directory = GetDirectory("Views\\Home");

            var file = Path.Combine(directory, dynamicObjectsViewModel.Service + dynamicObjectsViewModel.Page + ".cshtml");

            using (TextWriter text = new StreamWriter(file))
            {
                text.WriteLine("@model DynamicObjects.Models." + dynamicObjectsViewModel.Page + "." + dynamicObjectsViewModel.Service + dynamicObjectsViewModel.Page + "ViewModel");
                text.WriteLine("@{ \n ViewData[\"Title\"] = \"" + dynamicObjectsViewModel.Page + "\";\n}");
                text.WriteLine();
                text.WriteLine("<div class=" + "row" + ">");
                text.WriteLine(EmptyColumns(4));
                text.WriteLine("\t\t<div class=" + "col-md-4" + ">");
                text.WriteLine("\t\t\t<form asp-action=" + dynamicObjectsViewModel.Service + dynamicObjectsViewModel.Page + ">");
                text.WriteLine("\t\t\t\t<div asp-validation-summary=" + "ModelOnly" + " class=" + "text-danger" + "></div>");
            }
            foreach (var row in dynamicObjectsViewModel.FieldsDetailViewModel)
            {
                using (StreamWriter text = new StreamWriter(file, true))
                {
                    text.WriteLine(FormGroup());
                    text.WriteLine(LabelFor(row.FieldName));
                    text.WriteLine(TextBoxFor(row.FieldName));
                    text.WriteLine(ErrorFor(row.FieldName));
                    text.WriteLine(CLoseDiv("\t\t\t\t"));
                }
            }
            using (StreamWriter text = new StreamWriter(file, true))
            {
                text.WriteLine(FormGroup());
                text.WriteLine(SubmitButtonFor("Save"));
                text.WriteLine(CLoseDiv("\t\t\t\t"));
            }
            using (StreamWriter text = new StreamWriter(file, true))
            {
                text.WriteLine(@""
                               + "\n\t\t</form>"
                               + "\n\t</div>"
                               + "\n</div>"
                               );
            }

            return(true);
        }
 public static bool Get(string directory, DynamicObjectsViewModel dynamicObjectsViewModel)
 {
     try
     {
         string getAction            = "\n\t\t[HttpGet]\n\t\tpublic IActionResult " + dynamicObjectsViewModel.Service + dynamicObjectsViewModel.Page + "()\n\t\t{\n\t\t\t return View();\n\t\t}";
         var    file                 = Path.Combine(directory, dynamicObjectsViewModel.Page + "Controller.cs");
         var    txtLines             = System.IO.File.ReadAllLines(file).ToList();
         int    actionIndexToBeAdded = txtLines.Count() - 2;
         if (!txtLines.Contains(getAction))
         {
             txtLines.Insert(actionIndexToBeAdded, getAction);
             System.IO.File.WriteAllLines(file, txtLines);
         }
     }
     catch (Exception exception)
     {
         Console.WriteLine(exception.Message);
         return(false);
     }
     return(true);
 }
Ejemplo n.º 8
0
        public static bool Generate(string directory, DynamicObjectsViewModel dynamicObjectsViewModel)
        {
            try
            {
                var file = Path.Combine(directory, dynamicObjectsViewModel.Service + dynamicObjectsViewModel.Page + ".cshtml");
                if (!Directory.Exists(directory))
                {
                    Directory.CreateDirectory(directory);
                }

                if (!System.IO.File.Exists(file))
                {
                    System.IO.File.Create(file).Dispose();
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception.Message);
                return(false);
            }
            return(true);
        }
Ejemplo n.º 9
0
        private void GenerateDynamics(DynamicObjectsViewModel dynamicObjectsViewModel)
        {
            bool isSuccessModelGenerated = Dynamics.ModelDynamics.Generate(GetDirectory("Models\\" + dynamicObjectsViewModel.Page), dynamicObjectsViewModel);

            if (isSuccessModelGenerated)
            {
                bool isSuccessContentAdded = Dynamics.ModelDynamics.Content(GetDirectory("Models\\" + dynamicObjectsViewModel.Page), dynamicObjectsViewModel);
                if (isSuccessContentAdded)
                {
                    bool isSuccessController = Dynamics.ControllerDynamics.Generate(GetDirectory("Controllers"), dynamicObjectsViewModel);
                    if (isSuccessController)
                    {
                        bool isSuccessRef = Dynamics.ControllerDynamics.AddRefernces(GetDirectory("Controllers"), dynamicObjectsViewModel);
                        if (isSuccessRef)
                        {
                            bool isSuccessIndex = Dynamics.ControllerDynamics.Index(GetDirectory("Controllers"), dynamicObjectsViewModel);
                            if (isSuccessIndex)
                            {
                                bool isSuccessGet = Dynamics.ControllerDynamics.Get(GetDirectory("Controllers"), dynamicObjectsViewModel);
                                if (isSuccessGet)
                                {
                                    bool isSuccessPost = Dynamics.ControllerDynamics.Post(GetDirectory("Controllers"), dynamicObjectsViewModel);
                                    if (isSuccessPost)
                                    {
                                        bool isSuccessViewGenerated = Dynamics.ViewDynamics.Generate(GetDirectory("Views\\" + dynamicObjectsViewModel.Page), dynamicObjectsViewModel);
                                        if (isSuccessViewGenerated)
                                        {
                                            Dynamics.ViewDynamics.AddContent(GetDirectory("Views\\" + dynamicObjectsViewModel.Page), dynamicObjectsViewModel);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }