public IActionResult Edit(int id) { List <Gun> guns = _db.Gun.ToList(); ViewBag.GunsList = guns; ShootingResult model = _db.ShootingResult.FirstOrDefault(x => x.id == id); return(View(model)); }
public IActionResult Add(ShootingResult model) { if (ModelState.IsValid) { _db.ShootingResult.Add(model); _db.SaveChanges(); return(RedirectToAction("Index")); } return(View(model)); }
public IActionResult Delete(int id) { ShootingResult gunToDelite = _db.ShootingResult.FirstOrDefault(x => x.id == id); if (gunToDelite is null) { return(RedirectToAction("Edit", new { id = id })); } else { _db.Remove(gunToDelite); _db.SaveChanges(); return(RedirectToAction("Index")); } }
public IActionResult Edit(ShootingResult model) { if (ModelState.IsValid) { ShootingResult gunToUpdate = _db.ShootingResult.FirstOrDefault(x => x.id == model.id); if (gunToUpdate is null) { return(RedirectToAction("Edit", new { id = model.id })); } else { gunToUpdate = model; _db.SaveChanges(); return(RedirectToAction("Index")); } } return(View(model)); }