public void InsertGetUpdateDeleteChannel()
        {
            string            testName = "Test";
            YoutubeChannelDto dto      = new YoutubeChannelDto()
            {
                Description = "Test channel", Id = 0, Name = testName, UploadPlaylistId = "PlaylistId", YoutubeChannelId = "ChannelId"
            };
            int id = _youtubeChannelsService.InsertOrUpdateYoutubeChannel(dto);

            var addedDto = _youtubeChannelsService.GetYoutubeChannels().SingleOrDefault(p => p.YoutubeChannelId == dto.YoutubeChannelId);

            Assert.AreEqual(dto.YoutubeChannelId, addedDto.YoutubeChannelId);
            Assert.AreEqual(dto.UploadPlaylistId, addedDto.UploadPlaylistId);
            Assert.AreEqual(dto.Description, addedDto.Description);

            addedDto.UploadPlaylistId = "PlaylistId124";

            _youtubeChannelsService.InsertOrUpdateYoutubeChannel(addedDto);

            addedDto = _youtubeChannelsService.GetYoutubeChannels().SingleOrDefault(p => p.YoutubeChannelId == dto.YoutubeChannelId);
            Assert.AreEqual("PlaylistId124", addedDto.UploadPlaylistId);

            var success = _youtubeChannelsService.DeleteYoutubeChannel(addedDto.Id);

            Assert.IsTrue(success);

            addedDto = _youtubeChannelsService.GetYoutubeChannels().SingleOrDefault(p => p.YoutubeChannelId == dto.YoutubeChannelId);

            Assert.IsNull(addedDto);
        }
 public int InsertOrUpdateYoutubeChannel(YoutubeChannelDto channelDto)
 {
     using (var scope = new TransactionScope())
     {
         var channel = _unitOfWork.YoutubeChannelRepository.GetSingle(p => p.YoutubeChannelId == channelDto.YoutubeChannelId);
         if (channel != null)
         {
             channel.Description      = channelDto.Description;
             channel.Name             = channelDto.Name;
             channel.UploadPlaylistId = channelDto.UploadPlaylistId;
             _unitOfWork.YoutubeChannelRepository.Update(channel);
         }
         else
         {
             var newchannel = new YoutubeChannel()
             {
                 Description      = channelDto.Description,
                 Name             = channelDto.Name,
                 UploadPlaylistId = channelDto.UploadPlaylistId,
                 YoutubeChannelId = channelDto.YoutubeChannelId
             };
             _unitOfWork.YoutubeChannelRepository.Insert(newchannel);
             _unitOfWork.Save();
             channel = newchannel;
         }
         scope.Complete();
         return(channel.Id);
     }
 }
        public IHttpActionResult InsertOrUpdate(YoutubeChannelDto channel)
        {
            var result = _youtubeChannelService.InsertOrUpdateYoutubeChannel(channel);

            if (result != 0)
            {
                return(Ok(result));
            }
            return(BadRequest());
        }