public void UpdateUserGroupFromInput(UserGroup model, UserGroupInput input)
		{
			model.DomainName = input.DomainName;
			model.Key = input.Key;
			model.Id = input.Id;
			model.Name = input.Name;
			model.HomepageHTML = input.HomepageHTML;
			model.City = input.City;
			model.Region = input.Region;
			model.Country = input.Country;
			model.GoogleAnalysticsCode = input.GoogleAnalysticsCode;
			var existingUsers = model.GetUsers();

			var usersToRemove = existingUsers.Where(user => !input.Users.Any(uf => uf.Id == user.Id));

			foreach (var user in usersToRemove)
			{
				model.Remove(user);
			}

			var userFormToAdd =
				input.Users.Where(userForm => !existingUsers.Any(user => user.Id == userForm.Id));
			var users = _userRepository.GetAll();

			foreach (var userForm in userFormToAdd)
			{
				var user = users.FirstOrDefault(user1 => user1.Id == userForm.Id);
				model.Add(user);
			}
		}
        public virtual bool HasPermissionsFor(UserGroup usergroup)
        {
            User user = _session.GetCurrentUser();

            if (usergroup != null && usergroup.GetUsers().Any(user1 => user1.Username == user.Username))
            {
                return true;
            }
            return IsAdmin();
        }
        public void Should_map_user_group()
        {
            var usergroup = new UserGroup();
            usergroup.Name = "this group";
            usergroup.Key = "AustinDotNetUsersGroup";
            usergroup.City = "city";
            usergroup.Region = "Stete";
            usergroup.Country = "USA";
            usergroup.HomepageHTML = "<H1>Hello World</H1>";
            usergroup.GoogleAnalysticsCode = "foo";
            usergroup.DomainName = "foo/bar";
            usergroup.Add(new User {EmailAddress = "foo", Name = "bar"});
            usergroup.Add(new Sponsor {Level = SponsorLevel.Platinum, Name = "the sponsor"});

            AssertObjectCanBePersisted(usergroup.GetSponsors()[0]);
            AssertObjectCanBePersisted(usergroup.GetUsers()[0]);
            AssertObjectCanBePersisted(usergroup);
        }