public async Task <IActionResult> Edit(int id, [Bind("ID,ActID,ChildID")] childEnrolled childEnrolled)
        {
            if (id != childEnrolled.ActID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(childEnrolled);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!childEnrolledExists(childEnrolled.ActID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            PopulateDropDownLists(childEnrolled);
            return(View(childEnrolled));
        }
        private void UpdateChildActivities(string[] selectedOptions, Child childToUpdate)
        {
            if (selectedOptions == null)
            {
                childToUpdate.ChildEnrolleds = new List <childEnrolled>();
                return;
            }

            var selectedOptionsHS = new HashSet <string>(selectedOptions);
            var childActivities   = new HashSet <int>(childToUpdate.ChildEnrolleds.Select(e => e.ActID));

            foreach (var a in _context.Activities)
            {
                if (selectedOptionsHS.Contains(a.ID.ToString()))
                {
                    if (!childActivities.Contains(a.ID))
                    {
                        childToUpdate.ChildEnrolleds.Add(new childEnrolled
                        {
                            ActID   = a.ID,
                            ChildID = childToUpdate.ID
                        });
                    }
                }
                else
                {
                    if (childActivities.Contains(a.ID))
                    {
                        childEnrolled specToRemove = childToUpdate.ChildEnrolleds.SingleOrDefault(e => e.ActID == a.ID);
                        _context.Remove(specToRemove);
                    }
                }
            }
        }
        public async Task <IActionResult> Create([Bind("ID,ActID,ChildID")] childEnrolled childEnrolled)
        {
            if (ModelState.IsValid)
            {
                _context.Add(childEnrolled);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            PopulateDropDownLists(childEnrolled);
            return(View(childEnrolled));
        }
 private void PopulateDropDownLists(childEnrolled childEnrolled = null)
 {
     ViewData["ActTypeID"] = ActivitySelectList(childEnrolled?.ActID);
     ViewData["ChildID"]   = ChildSelectList(childEnrolled?.ChildID);
 }