public IActionResult NewReagent() { var Suppliers = _context.Suppliers.Select(r => new { r.ID, r.Name }).ToList(); Reagent reagent = new Reagent(); FormReagentViewModel viewModel = new FormReagentViewModel { SuppliersChoices = new SelectList(Suppliers, "ID", "Name"), Action = "NewReagent" }; _mapper.Map <Reagent>(viewModel); return(View("FormReagent", viewModel)); }
public IActionResult NewReagent(FormReagentViewModel reagent) { if (!ModelState.IsValid) { return(View("FormReagent", reagent)); } Reagent newReagent = new Reagent(); _mapper.Map(reagent, newReagent); _context.Reagents.Add(newReagent); _context.SaveChanges(); var routeValue = new RouteValueDictionary(new { action = "Index", controller = "Home" }); return(RedirectToRoute(routeValue)); }
public IActionResult UpdateReagent(int id, FormReagentViewModel reagent) { if (!ModelState.IsValid) { return(View("FormReagent", reagent)); } var ToEdit = _context.Reagents.FirstOrDefault(r => r.Id == id); _mapper.Map(reagent, ToEdit); _context.SaveChanges(); var routeValue = new RouteValueDictionary(new { action = "Index", controller = "Home" }); return(RedirectToRoute(routeValue)); }
//Update Reagent get public IActionResult UpdateReagent(int id) { var Reagent = _context.Reagents.Where(r => r.Id == id) .Include(r => r.Supplier) .Include(r => r.State) .FirstOrDefault(); if (Reagent == null) { return(NotFound()); } var Suppliers = _context.Suppliers.Select(r => new { r.ID, r.Name }).ToList(); FormReagentViewModel viewModel = new FormReagentViewModel { SuppliersChoices = new SelectList(Suppliers, "ID", "Name"), Action = "UpdateReagent" }; _mapper.Map(Reagent, viewModel); return(View("FormReagent", viewModel)); }