TvDatabase.TvBusinessLayer.GetChannel C# (CSharp) Method

GetChannel() public method

public GetChannel ( int idChannel ) : TvDatabase.Channel
idChannel int
return TvDatabase.Channel
    public Channel GetChannel(int idChannel)
    {
      SqlBuilder sb = new SqlBuilder(StatementType.Select, typeof (Channel));
      sb.AddConstraint(Operator.Equals, "idChannel", idChannel);

      SqlStatement stmt = sb.GetStatement(true);
      IList<Channel> channels = ObjectFactory.GetCollection<Channel>(stmt.Execute());
      if (channels == null)
      {
        return null;
      }
      if (channels.Count == 0)
      {
        return null;
      }
      return channels[0];
    }

Usage Example

    private void AddSelectedItemsToGroup(MPListView sourceListView)
    {
      if (_channelGroup == null)
      {
        return;
      }

      TvBusinessLayer layer = new TvBusinessLayer();
      foreach (ListViewItem sourceItem in sourceListView.SelectedItems)
      {
        Channel channel = null;
        if (sourceItem.Tag is Channel)
        {
          channel = (Channel)sourceItem.Tag;
        }
        else if (sourceItem.Tag is RadioGroupMap)
        {
          channel = layer.GetChannel(((RadioGroupMap)sourceItem.Tag).IdChannel);
        }
        else
        {
          continue;
        }

        RadioGroupMap groupMap = null;

        layer.AddChannelToRadioGroup(channel, _channelGroup);

        //get the new group map and set the listitem tag
        SqlBuilder sb = new SqlBuilder(StatementType.Select, typeof (RadioGroupMap));

        sb.AddConstraint(Operator.Equals, "idChannel", channel.IdChannel);
        sb.AddConstraint(Operator.Equals, "idGroup", _channelGroup.IdGroup);

        SqlStatement stmt = sb.GetStatement(true);

        groupMap = ObjectFactory.GetInstance<RadioGroupMap>(stmt.Execute());

        foreach (ListViewItem item in listView1.Items)
        {
          if ((item.Tag as Channel) == channel)
          {
            item.Tag = groupMap;
            break;
          }
        }
      }
    }
TvBusinessLayer