Example #1
0
        /// <summary>
        /// Actualiza la entrada de un video de youtube
        /// </summary>
        /// <param name="youtubeDto"></param>
        /// <returns></returns>
        public ApiCallResult ActualizarEntradaYoutube(YoutubeDto youtubeDto)
        {
            try
            {
                Blogs blogs = this.repository.ObtenerSlug(youtubeDto.Slug);
                blogs.Titulo             = youtubeDto.Titulo ?? blogs.Titulo;
                blogs.Descripcion        = youtubeDto.Descripcion ?? blogs.Descripcion;
                blogs.Idcategoria        = youtubeDto.Idcategoria ?? blogs.Idcategoria;
                blogs.Fechaactualizacion = DateTime.Now;
                if (youtubeDto.RutaVideo != null)
                {
                    ActualizarVideo(youtubeDto.RutaVideo, blogs.Idimagen);
                }
                if (youtubeDto.KeyWords != null)
                {
                    this.ActualizarBlogKey(youtubeDto.KeyWords, blogs.Idblog);
                }
                this.repository.ActualizarEntrada(blogs);

                return(new ApiCallResult
                {
                    Estado = true,
                    Mensaje = "Video actualizado con extido"
                });
            }
            catch (NegocioExecption)
            {
                throw;
            }
            catch (Exception)
            {
                throw;
            }
        }
Example #2
0
        public async Task <ActionResult <YoutubeDto> > GetItems()
        {
            var res = await _youtubeService.GetItems();

            var result = new YoutubeDto
            {
                Items = res.ToList()
            };

            return(Ok(result));
        }
Example #3
0
 public IActionResult ActualizarEntradaYoutube(YoutubeDto youtubeDto)
 {
     try
     {
         ApiCallResult result = this.service.ActualizarEntradaYoutube(youtubeDto);
         return(StatusCode((int)System.Net.HttpStatusCode.OK, result));
     }
     catch (NegocioExecption e)
     {
         return(StatusCode((int)System.Net.HttpStatusCode.NotFound, e.Message));
     }
     catch (Exception e)
     {
         return(StatusCode((int)System.Net.HttpStatusCode.InternalServerError, e.Message));
     }
 }
Example #4
0
 public IActionResult MostrarVideoYoutube(string slug, bool estado)
 {
     try
     {
         YoutubeDto result = this.service.MostrarVideoYoutubePorSlug(slug, estado);
         return(StatusCode((int)System.Net.HttpStatusCode.OK, result));
     }
     catch (NegocioExecption e)
     {
         return(StatusCode((int)System.Net.HttpStatusCode.NotFound, e.Message));
     }
     catch (Exception e)
     {
         return(StatusCode((int)System.Net.HttpStatusCode.InternalServerError, e.Message));
     }
 }
Example #5
0
 /// <summary>
 /// Muestra el video detalle del video de youtube
 /// </summary>
 /// <param name="slug"></param>
 /// <param name="estado"></param>
 /// <returns></returns>
 public YoutubeDto MostrarVideoYoutubePorSlug(string slug, bool estado)
 {
     try
     {
         Blogs blog = this.repository.ObtenerSlug(slug);
         if (blog is null)
         {
             throw new NegocioExecption("No existe el slug", 404);
         }
         BlogDetalleDto blogDto    = this.repository.MostrarEntradaPorSlug(slug, estado);
         YoutubeDto     youtubeDto = mapper.Map <YoutubeDto>(blogDto);
         return(youtubeDto);
     }
     catch (NegocioExecption)
     {
         throw;
     }
     catch (Exception)
     {
         throw;
     }
 }
Example #6
0
        public async Task <YoutubeDto> Search(string query)
        {
            var youtubeConfigs = _config.GetSection("YoutubeConfigs");
            var baseUrl        = youtubeConfigs["baseUrl"].ToString();
            var key            = youtubeConfigs["key"].ToString();

            var readerParams = new ReaderParams
            {
                urlParams = new Dictionary <string, string>
                {
                    { "part", "snippet" },
                    { "q", query },
                    { "key", key }
                }
            };

            var youtubeResponse = await _reader.Get <YoutubeResponse>(baseUrl + "search?", readerParams);

            var youtubeDto = new YoutubeDto
            {
                NextPageToken = youtubeResponse.nextPageToken,
            };

            foreach (var item in youtubeResponse.items)
            {
                var ytModel = new YoutubeModel();

                ytModel.Title        = item.snippet.title;
                ytModel.Description  = item.snippet.description;
                ytModel.PublishedAt  = item.snippet.publishedAt;
                ytModel.IsChannel    = false;
                ytModel.ChannelName  = item.snippet.channelTitle;
                ytModel.ThumbnailUrl = item.snippet.thumbnails.medium.url;

                if (item.id.kind == "youtube#channel")
                {
                    ytModel.IsChannel = true;
                    ytModel.youtubeId = item.id.channelId;
                }
                else if (item.id.kind == "youtube#video")
                {
                    ytModel.youtubeId = item.id.videoId;
                }
                else
                {
                    ytModel.youtubeId = item.id.playlistId;
                }

                if (_youtubeRepository.Exists(x => x.youtubeId == ytModel.youtubeId))
                {
                    var res = _youtubeRepository.ListBy(x => x.youtubeId == ytModel.youtubeId).Result.FirstOrDefault();
                    ytModel.Id = res.Id;
                    await _youtubeRepository.Update(ytModel);
                }
                else
                {
                    await _youtubeRepository.Create(ytModel);
                }

                youtubeDto.Items.Add(ytModel);
            }

            return(youtubeDto);
        }