public async Task <bool> Index(string directoryName, DynamicObjectDTO dynamicObjectDTO) { try { string directory = await _directoryService.GetDirectory(directoryName, true); 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\")+" + "\"" + dynamicObjectDTO.Page + "\";" + //"\n\t\t\tTempData.Keep(\"Group\");" + "\n\t\t\treturn View(" + "viewName" + ");\n\t\t}"; var file = Path.Combine(directory, dynamicObjectDTO.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 async Task <bool> AddRefernces(string directoryName, DynamicObjectDTO dynamicObjectDTO) { try { string directory = await _directoryService.GetDirectory(directoryName, true); var file = Path.Combine(directory, dynamicObjectDTO.Page + "Controller.cs"); string references = @"" + "using System.Threading.Tasks;\n" + "using Nexawo.Application." + dynamicObjectDTO.Page + ";\n" + "using Microsoft.AspNetCore.Http;\n" + "using Microsoft.AspNetCore.Mvc;\n" + "namespace Nexawo.WebApp.Controllers\n{" + "\n\tpublic class " + dynamicObjectDTO.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 Nexawo.WebApp.Controllers")) { txtLines.Insert(actionIndexToBeAdded, references); System.IO.File.WriteAllLines(file, txtLines); } } catch (Exception exception) { Console.WriteLine(exception.Message); return(false); } return(true); }
public async Task <bool> AddContent(string directoryName, DynamicObjectDTO dynamicObjectDTO) { string directory = await _directoryService.GetDirectory(directoryName, false); try { var file = Path.Combine(directory, dynamicObjectDTO.Service + dynamicObjectDTO.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 Nexawo.Application." + dynamicObjectDTO.Page + "" + "\n{" + "\n\tpublic class " + dynamicObjectDTO.Service + dynamicObjectDTO.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 dynamicObjectDTO.FieldsDetailDTO) { 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); }
private ServiceDetail GenerateServiceDetailObject(DynamicObjectDTO dynamicObjectDTO) { string content = JsonConvert.SerializeObject(dynamicObjectDTO.FieldsDetailDTO); var serviceDetail = new ServiceDetail(); serviceDetail.Page = dynamicObjectDTO.Page; serviceDetail.Service = dynamicObjectDTO.Service; serviceDetail.Content = content; return(serviceDetail); }
public async Task <bool> AddContent(string directoryName, DynamicObjectDTO dynamicObjectDTO) { string directory = await _directoryService.GetDirectory(directoryName + "\\" + dynamicObjectDTO.Page, true); var file = Path.Combine(directory, dynamicObjectDTO.Service + dynamicObjectDTO.Page + ".cshtml"); using (TextWriter text = new StreamWriter(file)) { text.WriteLine("@model Nexawo.Application." + dynamicObjectDTO.Page + "." + dynamicObjectDTO.Service + dynamicObjectDTO.Page + "ViewModel"); text.WriteLine("@{ \n ViewData[\"Title\"] = \"" + dynamicObjectDTO.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=" + dynamicObjectDTO.Service + dynamicObjectDTO.Page + ">"); text.WriteLine("\t\t\t\t<div asp-validation-summary=" + "ModelOnly" + " class=" + "text-danger" + "></div>"); } foreach (var row in dynamicObjectDTO.FieldsDetailDTO) { 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 async Task <bool> GenerateFile(string directoryName, DynamicObjectDTO dynamicObjectDTO) { try { string directory = await _directoryService.GetDirectory(directoryName, true); var file = Path.Combine(directory, dynamicObjectDTO.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); }
public async Task <JsonResult> Create([FromBody] DynamicObjectDTO dynamicObjectDTO) { var command = new CreateModelCommand(); command.DynamicObjectDTO = dynamicObjectDTO; bool result = await Mediator.Send(command); if (result) { var controllerCommand = new CreateControllerCommand(); controllerCommand.DynamicObjectDTO = dynamicObjectDTO; result = await Mediator.Send(controllerCommand); if (result) { var viewCommand = new CreateViewCommand(); viewCommand.DynamicObjectDTO = dynamicObjectDTO; result = await Mediator.Send(viewCommand); } } return(Json(dynamicObjectDTO)); }
public async Task <bool> Post(string directoryName, DynamicObjectDTO dynamicObjectDTO) { try { string directory = await _directoryService.GetDirectory(directoryName, true); string postAction = "\n\t\t[HttpPost]\n\t\tpublic IActionResult " + dynamicObjectDTO.Service + dynamicObjectDTO.Page + "(" + dynamicObjectDTO.Service + dynamicObjectDTO.Page + "ViewModel " + dynamicObjectDTO.Service.ToLower() + dynamicObjectDTO.Page + "ViewModel" + ")\n\t\t{\n\t\t\treturn View();\n\t\t}"; var file = Path.Combine(directory, dynamicObjectDTO.Page + "Controller.cs"); var txtLines = System.IO.File.ReadAllLines(file).ToList(); int actionIndexToBeAdded = txtLines.Count() - 2; if (!txtLines.Contains(postAction)) { txtLines.Insert(actionIndexToBeAdded, postAction); System.IO.File.WriteAllLines(file, txtLines); } } catch (Exception exception) { Console.WriteLine(exception.Message); return(false); } return(true); }