public void AddNewPerson(HomeAddVM model) { context.Person.Add(new Person { FirstName = model.Person.FirstName, LastName = model.Person.LastName, Email = model.Person.Email, PhoneNumber = model.Person.PhoneNumber, Description = model.Person.Description }); context.SaveChanges(); var person = context.Person.Last(); foreach (var item in model.Person.SelectedSkills) { context.ConnTable.Add(new ConnTable { SkillId = item, PersonId = person.Id, }); } context.SaveChanges(); }
public IActionResult Add(HomeAddVM model) { if (!ModelState.IsValid) { var viewModel = repository.GetAllSkills(); viewModel.Person.SelectedSkills = model.Person.SelectedSkills; return(View(viewModel)); } repository.AddNewPerson(model); return(RedirectToAction(nameof(Index))); }
public HomeAddVM GetAllSkills() { HomeAddVM List = new HomeAddVM() { Person = new HomeAddVM.PersonVM { Skills = context.Skill .Select(o => new SelectListItem { Text = o.Skill1, Value = o.Id.ToString() }) .ToArray() } }; return(List); }