// post action method to add new phone in records // method utilizes hidden filed and uses action for both purposes adding new phone and editing the phone based on id public async Task <IActionResult> New(SmartPhoneModel phone) { try { if (ModelState.IsValid) { if (phone.PhoneId > 0) { _DbContext.Update(phone); await _DbContext.SaveChangesAsync(); } else { _DbContext.Add(phone); await _DbContext.SaveChangesAsync(); } return(RedirectToAction("Phones")); } } catch (Exception) { return(RedirectToAction("Phones")); } return(View(phone)); }
// default action method for new creation of phone record public IActionResult Create(SmartPhoneModel phone) { return(View(phone)); }