public async Task<ActionResult> Create(CreateViewModel createViewModel)
        {
            if (!ModelState.IsValid)
            {
                return View(createViewModel);
            }

            var checkBoxGroupViewModelArray = createViewModel.CheckBoxGroupViewModelList.ToArray();
            var user = UserManager.FindByName(createViewModel.UserName);
            for (var i = 0; i < checkBoxGroupViewModelArray.Count(); i++)
            {
                var checkBoxGroup = createViewModel.CheckBoxGroupViewModelList[i];
                var selectedGroupId = checkBoxGroup.Selected ? checkBoxGroup.Id : 0;
                var selectedGroup = GroupService.FindById(selectedGroupId);
                if (selectedGroup == null)
                    continue;
                var selectedRoleArray = selectedGroup.ApplicationRoles.ToArray();    
                for (var j = 0; j < selectedRoleArray.Count(); j++)
                {
                    UserManager.AddToRole(user.Id, selectedRoleArray[j].Name);
                }
                selectedGroup.ApplicationUsers.Add(user);
                GroupService.UpdateGroup(selectedGroup);
            }
            return RedirectToAction("index", "permissions");
        }
 public ActionResult Create()
 {
     var checkBoxGroupViewModelList = new List<CheckBoxGroupViewModel>();
     var groupArray = GroupService.GetGroups().ToArray();
     for (int i = 0; i < groupArray.Count(); i++)
     {
         var group = groupArray[i];
         var checkBoxGroupViewModel = new CheckBoxGroupViewModel()
         {
             Id = group.GroupId,
             Description = group.Description,
             Name = group.Name,
             Roles = group.ApplicationRoles.ToList()
         };
         checkBoxGroupViewModelList.Add(checkBoxGroupViewModel);
     }
     var createViewModel = new CreateViewModel()
     {
         CheckBoxGroupViewModelList = checkBoxGroupViewModelList
     };
     return View(createViewModel);
 }