public ActionResult Save(Housband housband) { if (!ModelState.IsValid) { var viewModel = new NewHousbandViewModel(housband) { PersonalityTypes = _context.PersonalityTypes.ToList() }; return(View("HousbandForm", viewModel)); } if (housband.Id == 0) { _context.Housbands.Add(housband); } else { var housbandInDb = _context.Housbands.Include(h => h.PersonalityType).Single(h => h.Id == housband.Id); housbandInDb.Name = housband.Name; housbandInDb.SkillName = housband.SkillName; housbandInDb.Age = housband.Age; housbandInDb.IsBearded = housband.IsBearded; housbandInDb.PersonalityTypeId = housband.PersonalityTypeId; } _context.SaveChanges(); return(RedirectToAction("Show", "Housbands")); }
public NewHousbandViewModel(Housband housband) { Id = housband.Id; Name = housband.Name; SkillName = housband.SkillName; Age = housband.Age; IsBearded = housband.IsBearded; PersonalityTypeId = housband.PersonalityTypeId; }