public async Task <IActionResult> AddWord(Words obj) { try { if (ModelState.IsValid) { if (obj.Id == 0) { obj.AddedTime = DateTime.Now; await _context.Words.AddAsync(obj); await _context.SaveChangesAsync(); } else { _context.Entry(obj).State = EntityState.Modified; await _context.SaveChangesAsync(); } return(RedirectToAction("List")); } return(View(obj)); } catch (Exception) { return(RedirectToAction("List")); } }
public async Task <IActionResult> Create([Bind("ID,English,Japanese,Pronunciation,Definition,Notes,Category,Synonyms,Example,System")] WordModel wordModel) { if (ModelState.IsValid) { _context.Add(wordModel); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(wordModel)); }