public ActionResult Index(JsonFileViewModel _viewModel) { string s = ""; using (StreamReader sr = new StreamReader(Server.MapPath("~/UserData/") + "tmp.txt")) { while ((s = sr.ReadLine()) != null) { _fileName = s; } } string Json = System.IO.File.ReadAllText(_fileName); JavaScriptSerializer ser = new JavaScriptSerializer(); JsonFileViewModel viewModel = new JsonFileViewModel(); List <CcorrectModel> ldbModel = ConvertJsonToModel(ser.Deserialize <List <CRFID> >(Json)); CorrectJsonData(ldbModel); string json = JsonConvert.SerializeObject(ConvertModelToJson(ldbModel).ToArray(), Formatting.Indented); System.IO.File.WriteAllText(_fileName.Insert(_fileName.Length - 5, "_correct"), json); CompareViewModel compareViewModel = new CompareViewModel { _oldModel = ConvertJsonToModel(ser.Deserialize <List <CRFID> >(Json)), _newModel = ldbModel }; return(View("Compare", compareViewModel)); }
public IActionResult GetJson(JsonFileViewModel fileModel) { if (ModelState.IsValid) { IFormFile formFile = fileModel.FileJson; if (formFile != null && formFile.Length > 0) { Form form = fileSerializer.ReadJson(formFile); if (form != null) { FormsViewModel formModel = new FormsViewModel { Form = form }; return(View("GenerateForm", formModel)); } } ModelState.AddModelError("", "Uploaded file is empty or null."); return(View(fileModel)); } return(View(fileModel)); }
private void SaveJson(JsonFileViewModel model) { _receiptService.Add(new Receipt { Json = model.Json, ReceiptImageId = model.ReceiptImage.Id }); }
internal FileViewModelBase OpenFile(string filePath) { var fileViewModel = _files.FirstOrDefault(fm => fm.FilePath == filePath); if (fileViewModel != null) { return(fileViewModel); } string extension = Path.GetExtension(filePath).ToLower(); switch (extension) { case ".ogg": case ".rpgmvo": case ".ogg_": case ".m4a": case ".rpgmvm": case ".m4a_": case ".wav": case ".rpgmvw": case ".wav_": fileViewModel = new AudioFileViewModel(filePath); _files.Add(fileViewModel); break; case ".png": case ".rpgmvp": case ".png_": fileViewModel = new ImageFileViewModel(filePath); _files.Add(fileViewModel); break; case ".json": fileViewModel = new JsonFileViewModel(filePath); _files.Add(fileViewModel); break; case ".rpgsave": fileViewModel = new SaveFileViewModel(filePath); _files.Add(fileViewModel); break; case ".script": fileViewModel = new ScriptFileViewModel(filePath); _files.Add(fileViewModel); break; default: fileViewModel = new GeneralFileViewModel(filePath); _files.Add(fileViewModel); break; } return(fileViewModel); }
internal void SaveFile(FileViewModelBase fileToSave, bool saveAsFlag = false) { if (fileToSave.FilePath == null || saveAsFlag) { var dlg = new SaveFileDialog(); if (dlg.ShowDialog().GetValueOrDefault()) { fileToSave.FilePath = dlg.SafeFileName; } } if (fileToSave.FilePath == null) { return; } if (fileToSave is AudioFileViewModel) { // TODO : Save action } else if (fileToSave is GeneralFileViewModel) { GeneralFileViewModel file = fileToSave as GeneralFileViewModel; if (file.IsDirty) { FileManager.WriteTextFile(file.FilePath, file.TextContent, Encoding.UTF8); } } else if (fileToSave is ImageFileViewModel) { // TODO : Save action } else if (fileToSave is JsonFileViewModel) { JsonFileViewModel file = fileToSave as JsonFileViewModel; if (file.IsDirty) { FileManager.WriteTextFile(file.FilePath, file.DocumentText, Encoding.UTF8); } } else if (fileToSave is SaveFileViewModel) { // TODO : Save action } else if (fileToSave is ScriptFileViewModel) { // TODO : Save action } ActiveDocument.IsDirty = false; ActiveDocument.OnAfterSave(null); }
public IActionResult FormJson(int id) { var json = "Json"; var receiptImage = _receiptImageService.Get(id); var data = new JsonFileViewModel { ReceiptImage = receiptImage, Json = json }; SaveJson(data); return(View("Index", data)); }
// GET: Korrektur public ActionResult Index(Files files) { string file = Server.MapPath("~/UserData/" + files.FileName); //deserialize JSON from file string Json = System.IO.File.ReadAllText(file); JavaScriptSerializer ser = new JavaScriptSerializer(); JsonFileViewModel viewModel = new JsonFileViewModel(); viewModel.cRFIDs = ser.Deserialize <List <CRFID> >(Json); viewModel.fileName = files.FileName; _fileName = files.FileName; string createText = file; using (StreamWriter sw = new StreamWriter(Server.MapPath("~/UserData/") + "tmp.txt")) { sw.WriteLine(createText); sw.Flush(); } return(View(viewModel)); }
public IActionResult GetJson() { JsonFileViewModel fileModel = new JsonFileViewModel(); return(View(fileModel)); }
public IActionResult GenerateJson(int id) { Screen ScreenObject = context.Screens.FirstOrDefault(s => s.ID == id); Module customerProgram = context.Modules.FirstOrDefault(s => s.ID == ScreenObject.ModuleID); IEnumerable <ScreenComponent> ScreenComponents = context.ScreenComponent.Where(s => s.ScreenID == ScreenObject.ID); List <InputObjectViewModel> inputObject = new List <InputObjectViewModel>(); List <SelectObjectViewModel> selectObject = new List <SelectObjectViewModel>(); foreach (ScreenComponent ScreenComponent in ScreenComponents) { if (ScreenComponent.FieldTypeID == 1) { IEnumerable <ScreenComponent> ScreenComponentList = context.ScreenComponent.Where(s => s.ScreenComponentID == ScreenComponent.ID); SelectObjectViewModel var = new SelectObjectViewModel(); var.Label = ScreenComponent.FielNameArabic; var.Field = ScreenComponent.FieldNameEnglish; //Camel case (stylized as camelCase var.ServiceName = ScreenComponent.ServiceNameForDropdown; //Camel case (stylized as camelCase FieldType fieldType = context.FieldTypes.FirstOrDefault(s => s.ID == ScreenComponent.FieldTypeID); var.Validators = GenerateValidation(ScreenComponent); var.ReadOnly = ScreenComponent.Readonly; var.Dependants = GenerateDependant(ScreenComponentList); ScreenComponent ScreenComp = context.ScreenComponent.FirstOrDefault(s => s.ID == ScreenComponent.ScreenComponentID); var.Dependant = ScreenComp != null ? ScreenComp.FieldNameEnglish : ""; var.Visible = ScreenComponent.Visible; selectObject.Add(var); } else { InputObjectViewModel var = new InputObjectViewModel(); var.Label = ScreenComponent.FielNameArabic; //Camel case (stylized as camelCase var.Field = ScreenComponent.FieldNameEnglish; //Camel case (stylized as camelCase FieldType fieldType = context.FieldTypes.FirstOrDefault(s => s.ID == ScreenComponent.FieldTypeID); var.Type = fieldType.Name; var.Visible = ScreenComponent.Visible; var.ReadOnly = ScreenComponent.Readonly; var.Default = ScreenComponent.DefaultValue; var.Validators = GenerateValidation(ScreenComponent); ScreenComponent ScreenComp = context.ScreenComponent.FirstOrDefault(s => s.ID == ScreenComponent.ScreenComponentID); var.Dependant = ScreenComp != null ? ScreenComp.FieldNameEnglish : ""; inputObject.Add(var); } } JsonFileViewModel jsoncontent = new JsonFileViewModel(); jsoncontent.InputObjects = inputObject; jsoncontent.SelectObjects = selectObject; jsoncontent.Url = customerProgram.URLForService; jsoncontent.CustomValidators = GenerateCustomValidation(ScreenObject.ID); jsoncontent.ComponentName = customerProgram.EnglishNameInSingle; jsoncontent.ComponentPlural = customerProgram.EnglishNameInPlural; jsoncontent.PageTitle = customerProgram.ArabicNameInSingle; jsoncontent.PageTitles = customerProgram.ArabicNameInPlural; ScreenType screenType = context.ScreenTypes.FirstOrDefault(s => s.ID == ScreenObject.screenTypeID); string result = JsonConvert.SerializeObject(jsoncontent); result = result.Replace("null", "\"\"").Replace("\t", ""); var stream = new MemoryStream(Encoding.UTF8.GetBytes(result)); return(new FileStreamResult(stream, new MediaTypeHeaderValue("text/plain")) { FileDownloadName = screenType.Name.ToLower() + "model.json" }); }