Exemplo n.º 1
0
 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);
 }
Exemplo n.º 2
0
 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);
 }