public async Task <IActionResult> CreateDeadRabbit(MRabbitsDeathsRecords rabbit) { ViewBag.title = "Create Dead Rabbit"; try { rabbit.NameId = rabbit.NameId.ToUpper(); db.MRabbitsDeathsRecords.Add(rabbit); TempData["type"] = "success"; TempData["msg"] = "Saved"; await db.SaveChangesAsync(); return(RedirectToAction("AllDeadRabbits")); } catch (Exception ex) { TempData["type"] = "error"; TempData["msg"] = "Error: " + ex.Message; return(RedirectToAction($"CreateDeadRabbit", "Rabbits")); } }
public async Task <IActionResult> EditDeadRabbit(MRabbitsDeathsRecords rabbit, int old_rabbit_id) { ViewBag.title = "Edit Rabbit"; try { var old_rabbit = db.MRabbitsDeathsRecords.Find(old_rabbit_id); old_rabbit.DateOfDeath = rabbit.DateOfDeath; old_rabbit.NameId = rabbit.NameId.ToUpper(); old_rabbit.Notes = rabbit.Notes; db.Entry(old_rabbit).State = EntityState.Modified; await db.SaveChangesAsync(); TempData["msg"] = "Saved"; TempData["type"] = "success"; } catch (Exception ex) { TempData["msg"] = ex.Message; TempData["type"] = "error"; } return(RedirectToAction("EditDeadRabbit", "RabbitsDeaths", new { id = old_rabbit_id })); }