public async Task <IActionResult> DeleteConfirmed(int id) { try { await ReagentHelper.DeleteAsync(id); } catch (DbUpdateException) { ModelState.AddModelError("", "Unable to save changes. " + "Try again, and if the problem persists, " + "see your system administrator."); } return(RedirectToAction(nameof(Index))); }
// GET: Reagents/Edit/5 public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } ReagentViewModel reagent = await ReagentHelper.GetByIdAsync((int)id); if (reagent == null) { return(NotFound()); } return(View(reagent)); }
public async Task <IActionResult> Delete(int id, bool?saveChangesError = false) { ReagentViewModel reagent = await ReagentHelper.GetByIdAsync((int)id); if (reagent == null) { return(NotFound()); } if (saveChangesError.GetValueOrDefault()) { ViewData["ErrorMessage"] = "Delete failed. Try again, and if the problem persists " + "see your system administrator."; } return(View(reagent)); }
public async Task <IActionResult> Create(ReagentViewModel reagentVM) { try { if (ModelState.IsValid) { await ReagentHelper.AddAsync(reagentVM); return(RedirectToAction(nameof(Index))); } } catch (DbUpdateException) { //Log the error ModelState.AddModelError("", "Unable to save changes. " + "Try again, and if the problem persists " + "see your system administrator."); } return(View(reagentVM)); }
public async Task <IActionResult> Edit(int id, ReagentViewModel reagentVM) { if (id != reagentVM.ID) { return(NotFound()); } if (ModelState.IsValid) { try { await ReagentHelper.UpdateAsync(id, reagentVM); return(RedirectToAction(nameof(Index))); } catch (DbUpdateException) { ModelState.AddModelError("", "Unable to save changes. " + "Try again, and if the problem persists, " + "see your system administrator."); } } return(View(reagentVM)); }
public async Task <IActionResult> ConfirmReceived(int id) { try { ReagentHelper.Init(_context); await ReagentHelper.UpdateReagentStockAsync(id); await AppDataHelper.CheckReagentsStockAsync(_context); if (!Request.Cookies.ContainsKey("reagentAlert")) { Response.Cookies.Append("reagentAlert", "true", new CookieOptions { Expires = DateTime.Now.AddMinutes(10) }); } } catch (Exception ex) when(ex is DbUpdateException || ex is DbUpdateConcurrencyException) { ModelState.AddModelError("", "Unable to save changes. " + "Try again, and if the problem persists, " + "see your system administrator."); } return(RedirectToAction(nameof(Index))); }
// GET: Reagents public async Task <IActionResult> Index() { return(View(await ReagentHelper.GetAll())); }
public ReagentsController(MLabContext context) { _context = context; ReagentHelper.Init(_context); }