Exemplo n.º 1
0
 /// <summary>
 /// 添加兆赫到收藏列表
 /// </summary>
 /// <param name="userName">用户名</param>
 /// <param name="channel">兆赫</param>
 public void AddToFavoriateChannels(string userName, ChannelEntity channel)
 {
     GetFavoriateChannels(userName);
     if (favChannels.AllFavChannels == null)
     {
         GetChannelCollection col = new GetChannelCollection();
         List<ChannelEntity> chList = new List<ChannelEntity>();
         chList.Add(channel);
         col.Channels = chList;
         col.ChannelCount = 1;
         FavChannelEntity entity = new FavChannelEntity() { UserName = userName, FavChannels = col };
         List<FavChannelEntity> list = new List<FavChannelEntity>();
         list.Add(entity);
         favChannels.AllFavChannels = list;
     }
     else
     {
         bool findUser = false;
         foreach (FavChannelEntity entity in favChannels.AllFavChannels)
         {
             if (entity.UserName == userName)
             {
                 entity.FavChannels.Channels.Add(channel);
                 entity.FavChannels.ChannelCount++;
                 findUser = true;
                 break;
             }
         }
         if (!findUser)
         {
             GetChannelCollection col = new GetChannelCollection();
             List<ChannelEntity> chList = new List<ChannelEntity>();
             chList.Add(channel);
             col.Channels = chList;
             col.ChannelCount = 1;
             FavChannelEntity entity = new FavChannelEntity() { UserName = userName, FavChannels = col };
             List<FavChannelEntity> list = new List<FavChannelEntity>();
             list.Add(entity);
             favChannels.AllFavChannels.Add(entity);
         }
     }
     using (StreamWriter writer = new StreamWriter(DataFolder))
     {
         writer.Write(FavChannelCollection.Object2Json(favChannels));
     }
 }
Exemplo n.º 2
0
 private void InitFavChannel(string userName)
 {
     if (string.IsNullOrEmpty(userName))
     {
         channelInfo = new GetChannelCollection();
         channelInfo.Channels = new List<ChannelEntity>();
         channelInfo.ChannelCount = 0;
         using (StreamWriter writer = new StreamWriter(DataFolder))
         {
             writer.Write(string.Empty);
         }
     }
     else
     {
         ChannelEntity privateCh = new ChannelEntity() { Introduction = "私人兆赫", Name = "私人兆赫", SongsCount = "...", Cover = "Images/Private.png", Banner = "Images/Private.png", Creator = new ChannelCreator() { Name = "豆瓣FM" }, ChannelID = 0, HotSongs = new List<String>() };
         ChannelEntity redHeartCh = new ChannelEntity() { Introduction = "红心兆赫", Name = "红心兆赫", SongsCount = "...", Cover = "Images/RedHeart.jpg", Banner = "Images/RedHeart.png", Creator = new ChannelCreator() { Name = "豆瓣FM" }, ChannelID = -3, HotSongs = new List<String>() };
         //GetChannelCollection chs = new GetChannelCollection();
         List<ChannelEntity> chList = new List<ChannelEntity>();
         chList.Add(privateCh);
         chList.Add(redHeartCh);
         channelInfo = new GetChannelCollection();
         channelInfo.Channels = chList;
         channelInfo.ChannelCount = 2;
         FavChannelEntity entity = new FavChannelEntity() { UserName = userName, FavChannels = channelInfo };
         List<FavChannelEntity> list = new List<FavChannelEntity>();
         list.Add(entity);
         favChannels.AllFavChannels = list;
         using (StreamWriter writer = new StreamWriter(DataFolder))
         {
             writer.Write(FavChannelCollection.Object2Json(favChannels));
         }
     }
 }