public async Task <IActionResult> Create(CaseReportFormOptionGroupViewModel optionGroupVM) { try { if (ModelState.IsValid) { var optionGroup = new CaseReportFormOptionGroup(); optionGroup.Name = optionGroupVM.Name; optionGroup.Choices = new List <CaseReportFormOptionChoice>(); foreach (string choiceName in optionGroupVM.Options) { var optionChoice = new CaseReportFormOptionChoice(); optionChoice.Name = choiceName; optionChoice.CaseReportFormOptionGroup = optionGroup; optionGroup.Choices.Add(optionChoice); } _context.Add(optionGroup); await _context.SaveChangesAsync(); return(Json(new { result = "ok" })); } else { Hashtable errors = ModelStateHelper.Errors(ModelState); return(Json(new { success = false, errors })); } } catch (DbUpdateException) { return(null); } }
private static void AddCaseResultFormDefaultOptionDropdowns(AspergillosisContext context) { var caseReportFormOptionGroups = new CaseReportFormOptionGroup[] { new CaseReportFormOptionGroup { Name = "Specimen" }, new CaseReportFormOptionGroup { Name = "Serology Result" } }; foreach (var item in caseReportFormOptionGroups) { context.Add(item); } var caseReportFormSerologyOptionChoices = new String[] { "Positive", "Weakly Positive", "Negative" }; var caseReportFormSpecimenOptionChoices = new String[] { "Blood", "Sputum", "Fungal isolate" }; var serologyOptionGroup = caseReportFormOptionGroups .Where(crfog => crfog.Name.Contains("Serology Result")) .FirstOrDefault(); foreach (string serologyOptName in caseReportFormSerologyOptionChoices) { CaseReportFormOptionChoice serologyOpt = new CaseReportFormOptionChoice(); serologyOpt.CaseReportFormOptionGroup = serologyOptionGroup; serologyOpt.Name = serologyOptName; context.CaseReportFormOptionChoices.Add(serologyOpt); } var specimenOptionGroup = caseReportFormOptionGroups .Where(crfog => crfog.Name.Contains("Specimen")) .FirstOrDefault(); foreach (string serologyOptName in caseReportFormSpecimenOptionChoices) { CaseReportFormOptionChoice serologyOpt = new CaseReportFormOptionChoice(); serologyOpt.CaseReportFormOptionGroup = specimenOptionGroup; serologyOpt.Name = serologyOptName; context.CaseReportFormOptionChoices.Add(serologyOpt); } }