//-------------------------------------------------------------------------------------------------------
 internal int Create(UserGroup userGroup)
 {
     int result = ApplicationDbContext.DbAction(db =>
         {
             db.UserGroups.Add(userGroup);
             return db.SaveChanges();
         });
     return result;
 }
 internal static GroupViewModel From(UserGroup group, bool assigned)
 {
     return new GroupViewModel
     {
         GroupId = group.Id,
         GroupName = group.Name,
         Assigned = assigned
     };
 }
 private static object CreateUserGroupViewRow(UserGroup group, IEnumerable<ApplicationUser> groupUsers)
 {
     return new [] 
     {
         group.Id,
         group.Name,
         group.Enabled.ToString(),
         string.Join(", ", groupUsers.Select(u => u.UserName))
     };
 }
 private async Task<UserGroupWithUsers> GetVisibleUsers(UserGroup group)
 {
     var users = UserGroupAccess.GetUsersInGroup(group.Id);
     var visibleUsers = await Can(AdminActivity.ViewGroup, users);
     var result = new UserGroupWithUsers {
          Group = group,
          Users = visibleUsers.ToList()
     };
     return result;
 }
 internal void WriteUpdatesTo(UserGroup group)
 {
     group.Name = Name;
     group.Enabled = Enabled;
 }
 internal UserGroup To()
 {
     var result = new UserGroup { Id = Id, Name = Name, Enabled= Enabled };
     return result;
 }
 internal static EditUserGroupViewModel From(UserGroup userGroup)
 {
     return new EditUserGroupViewModel { Id = userGroup.Id, Name = userGroup.Name, Enabled = userGroup.Enabled };
 }