public async Task <IActionResult> Edit(string id, [Bind("Name,Information,Symptoms,Treatment,Vaccination")] DiseaseDescription diseaseDescription) { if (id != diseaseDescription.Name) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(diseaseDescription); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DiseaseDescriptionExists(diseaseDescription.Name)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(diseaseDescription)); }
public async Task <ActionResult <DiseaseDescription> > Get(string disease) { try { var diseaseData = await _context.DiseaseDescriptions.Where(d => d.Name == disease) .Include(d => d.UsefulReferences) .FirstOrDefaultAsync(); if (diseaseData == null) { return(NotFound()); } var usefulReferences = diseaseData.UsefulReferences?.Select(d => new DiseaseUsefulUrl { Url = d.Url, Name = d.Name }).ToList(); DiseaseDescription result = new DiseaseDescription() { Treatment = diseaseData.Treatment, Symptoms = diseaseData.Symptoms, Vaccination = diseaseData.Vaccination, Information = diseaseData.Information, UsefulReferences = usefulReferences ?? new List <DiseaseUsefulUrl>() }; return(result); } catch (Exception e) { Trace.WriteLine(e); throw; } }
public async Task <IActionResult> Create([Bind("Name,Information,Symptoms,Treatment,Vaccination")] DiseaseDescription diseaseDescription) { if (ModelState.IsValid) { _context.Add(diseaseDescription); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(diseaseDescription)); }