public async Task <IActionResult> Create([Bind("WigId,Description,Status,Title,SelectedUserProfiles")] CreateWigViewModel model) { if (ModelState.IsValid) { var wig = new Wig(); wig.Title = model.Title; wig.Description = model.Description; wig.Status = model.Status; wig.DateCreated = DateTime.Now; _context.Add(wig); if (model.SelectedUserProfiles != null) { foreach (var i in model.SelectedUserProfiles) { var uw = new UserWig(); uw.WigId = wig.WigId; uw.UserProfileId = i; _context.Add(uw); } } await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(model)); }
// GET: Wigs/Create public async Task <ViewResult> Create() { var model = new CreateWigViewModel(); model.UserProfiles = await _context.UserProfile.ToListAsync(); return(View(model)); }