private void join(string channelName, string username, int level)
        {
            aspnet_User user = userDB.getUser(username);

            Permission p = (from q in db.Permissions
                            where q.ChannelName == channelName
                            && q.UserId == userDB.getUser(username).UserId
                            select q).FirstOrDefault();
            Channel ch = getChannel(channelName);

            try
            {
                if ((ch.Closed == false && p == null) || level == 0 || p.Level == 0)
                {
                    p = new Permission();
                    p.UserId = user.UserId;
                    p.ChannelName = channelName;
                    p.Level = level;

                    db.Permissions.InsertOnSubmit(p);
                    db.SubmitChanges();
                }
            }
            catch (NullReferenceException e)
            {

                throw new NotInvitedException();
            }
        }
		private void detach_Permissions(Permission entity)
		{
			this.SendPropertyChanging();
			entity.aspnet_User = null;
		}
		private void detach_Permissions(Permission entity)
		{
			this.SendPropertyChanging();
			entity.Channel = null;
		}
		private void attach_Permissions(Permission entity)
		{
			this.SendPropertyChanging();
			entity.Channel = this;
		}
 partial void DeletePermission(Permission instance);
 partial void UpdatePermission(Permission instance);
 partial void InsertPermission(Permission instance);
 public void updatePermission(Permission p)
 {
     db.SubmitChanges();
 }