public IActionResult Edit(int id, MotherboardBindingModel model) { if (!ModelState.IsValid) { return(View(model)); } var pcMotherboard = context.Motherboards.FirstOrDefault(p => p.Id == id); if (pcMotherboard == null) { return(NotFound()); } MapProperties(pcMotherboard, model); context.SaveChanges(); return(RedirectToAction("Details", "Motherboards", new { area = "", id })); }
public IActionResult Create(MotherboardBindingModel model) { if (!ModelState.IsValid) { TempData["Error"] = "Invalid form."; return(RedirectToAction("Create")); } if (context.Motherboards.Any(p => p.ModelName == model.ModelName)) { TempData["Error"] = "Model name already exists."; return(RedirectToAction("Create")); } var pcMotherboard = mapper.Map <Motherboard>(model); context.Motherboards.Add(pcMotherboard); context.SaveChanges(); return(RedirectToAction("Details", "Motherboards", new { area = "", id = pcMotherboard.Id })); }