Пример #1
0
        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)));
        }
Пример #2
0
        // 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));
        }
Пример #3
0
        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));
        }
Пример #4
0
        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));
        }
Пример #5
0
        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));
        }
Пример #6
0
        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)));
        }
Пример #7
0
 // GET: Reagents
 public async Task <IActionResult> Index()
 {
     return(View(await ReagentHelper.GetAll()));
 }
Пример #8
0
 public ReagentsController(MLabContext context)
 {
     _context = context;
     ReagentHelper.Init(_context);
 }