public ActionResult Create(CharacterFieldsModel[] characters) { if (ModelState.IsValid) { var mapped = Mapper.Map<Character[]>(characters); foreach (var character in mapped.Where(x => !string.IsNullOrWhiteSpace(x.Name))) { _db.Set<Character>().Add(character); } _db.SaveChanges(); return RedirectToAction("Index"); } AssignViewItems(); return View(characters); }
public ActionResult Edit(CharacterFieldsModel model) { if (ModelState.IsValid) { var character = _db.Set<Character>().First(x => x.Id == model.Id); Mapper.Map(model, character); _db.Entry(character).State = EntityState.Modified; _db.SaveChanges(); return RedirectToAction("Index"); } return View(model); }