public Tuple <bool, IEnumerable <string> > Save(ManifestAppFileViewModel vieModel) { var validationResult = Validate(vieModel); if (validationResult.Item1) { var manifestAppFileRecord = Get(); manifestAppFileRecord.FileContent = vieModel.Text; manifestAppFileRecord.Enable = vieModel.Enable; manifestAppFileRecord.DeveloperDomainText = vieModel.DeveloperDomainText; manifestAppFileRecord.EnableDeveloperDomain = vieModel.EnableDeveloperDomain; _signals.Trigger("ManifestAppFile.SettingsChanged"); } return(validationResult); }
public ActionResult Index(ManifestAppFileViewModel viewModel) { if (!Authorized()) { return(new HttpUnauthorizedResult()); } var saveResult = _manifestAppService.Save(viewModel); if (saveResult.Item1) { Services.Notifier.Information(T("File settings successfully saved.")); } else { Services.Notifier.Error(T("File not saved.")); saveResult.Item2.ToList().ForEach(error => Services.Notifier.Warning(T(error)) ); } return(View(viewModel)); }
private Tuple <bool, IEnumerable <string> > Validate(ManifestAppFileViewModel vieModel) { //string schemaJson = @"{ // 'definition': { // 'webcredentials': { // 'type':'object', // 'properties': { // 'apps': { // 'type':'array' // } // }, // 'required': [ 'apps' ] // } // } // }"; if (String.IsNullOrEmpty(vieModel.Text)) { return(new Tuple <bool, IEnumerable <string> >(true, new List <string>() { })); } string schemaJson = @"{ }"; JSchema schema = JSchema.Parse(schemaJson); try { JObject jText = JObject.Parse(vieModel.Text); IList <string> message; bool valid = jText.IsValid(schema, out message); return(new Tuple <bool, IEnumerable <string> >(valid, message)); } catch (JsonReaderException ex) { return(new Tuple <bool, IEnumerable <string> >(false, new List <string>() { ex.Message })); } }