Beispiel #1
0
        public async Task <ActionResult> PostRemoveReagent(Lab lab, [System.Web.Http.FromUri] long usedReagentId, LabsRemoveReagentViewModel model)
        {
            var usedReagent = await DbContext.UsedReagents
                              .Include(ur => ur.Reagent)
                              .FirstOrDefaultAsync(ur => ur.UsedReagentId == usedReagentId);

            if (usedReagent == null)
            {
                return(RedirectToAction("Reagents", new { lab = lab.LabId }));
            }

            model.Lab     = lab;
            model.Reagent = usedReagent.Reagent;

            if (!ModelState.IsValid)
            {
                return(View("RemoveReagent", model));
            }

            try
            {
                await LabsDao.RemoveReagent(this, lab.LabId, usedReagentId, model.ReturnQuantity);
            }
            catch (Exception e)
            {
                ModelState.AddModelError("", e);
                return(RedirectToAction("RemoveReagent", new { usedReagentId }));
            }

            return(RedirectToAction("Reagents", new { lab = lab.LabId }));
        }
Beispiel #2
0
        public async Task <IHttpActionResult> RemoveReagent(long labId, long usedReagentId, int returnQuantity = 0)
        {
            var result = await LabsDao.RemoveReagent(this, labId, usedReagentId, returnQuantity);

            if (result == null)
            {
                return(NotFound());
            }

            return(JsonWithPermissions(result, true, true, true));
        }