public static async Task <Reagent> Create(IRequestContext context, ReagentsCreateViewModel model) { var reagent = new Reagent { Name = model.Name, Quantity = model.Quantity, AddedDate = DateTimeOffset.Now, ExpiryDate = model.ExpiryDate, ManufacturerCode = model.ManufacturerCode, }; context.DbContext.Reagents.Add(reagent); await context.DbContext.SaveChangesAsync(); await context.LogAsync($"Created reagent ID {reagent.ReagentId}"); return(reagent); }
public async Task <ActionResult> Create(ReagentsCreateViewModel model) { if (!ModelState.IsValid) { return(View(model)); } Reagent newReagent = null; try { newReagent = await ReagentsDao.Create(this, model); } catch (Exception e) { ModelState.AddModelError("", e.ToString()); return(View(model)); } return(RedirectToAction("Details", new { reagent = newReagent?.ReagentId ?? 0 })); }
public async Task <IHttpActionResult> Create(ReagentsCreateViewModel model) { return(JsonWithPermissions(await ReagentsDao.Create(this, model))); }