public async Task <IActionResult> Create([Bind("Id,Name,Description")] SustainableChemistryWeb.Models.Reactant reactant) { try { Reactant appReactant = new Reactant() { Name = reactant.Name, Description = reactant.Description, Temp2 = string.Empty, }; if (string.IsNullOrEmpty(appReactant.Description)) { appReactant.Description = string.Empty; } if (ModelState.IsValid) { _context.Add(appReactant); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(RedirectToAction(nameof(Index))); } catch { return(View()); } }
public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Description")] SustainableChemistryWeb.Models.Reactant reactant) { var reactantToUpdate = await _context.AppReactant .SingleOrDefaultAsync(m => m.Id == id); if (string.IsNullOrEmpty(reactant.Description)) { reactant.Description = string.Empty; } if (await TryUpdateModelAsync <Reactant>( reactantToUpdate, "", r => r.Name, r => r.Description)) { try { await _context.SaveChangesAsync(); } catch { return(View()); } } return(RedirectToAction(nameof(Index))); }