public async Task <IActionResult> Create([Bind("ID,Name")] Product product) { if (ModelState.IsValid) { _context.Add(product); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(product)); }
public async Task <TEntity> AddAsync(TEntity entity) { if (entity == null) { throw new ArgumentNullException($"{nameof(AddAsync)} entity must not be null"); } try { await context.Set <TEntity>().AddAsync(entity); await context.SaveChangesAsync(); return(entity); } catch (Exception ex) { throw new Exception($"{nameof(entity)} could not be saved: {ex.Message}"); } }