public ActionResult GetRandomTVShow(string genre)
        {
            TVShowEntity item     = _repository.GetRandomTVShowByGenre(genre.ToLower());
            var          response = _mapper.Map <TVShowResponse>(item);

            foreach (var temp in item.TVShowGenre)
            {
                response.Genres.Add(temp.Genre.Genre);
            }
            return(Ok(response));
        }
Exemple #2
0
        public async Task Initialize(TVShowDbContext context)
        {
            context.GenreItems.Add(new GenreEntity()
            {
                Genre = "Comedy"
            });
            context.GenreItems.Add(new GenreEntity()
            {
                Genre = "Horror"
            });
            context.GenreItems.Add(new GenreEntity()
            {
                Genre = "Drama"
            });
            context.GenreItems.Add(new GenreEntity()
            {
                Genre = "Mystery"
            });
            context.TVShowItems.Add(new TVShowEntity()
            {
                Title = "True Detective", ImdbScore = 9.0
            });
            context.TVShowItems.Add(new TVShowEntity()
            {
                Title = "Killing Eve", ImdbScore = 8.3
            });
            context.TVShowItems.Add(new TVShowEntity()
            {
                Title = "The Haunting of Hill House", ImdbScore = 8.7
            });
            context.TVShowItems.Add(new TVShowEntity()
            {
                Title = "Sex Education", ImdbScore = 8.3
            });
            context.TVShowItems.Add(new TVShowEntity()
            {
                Title = "Dark", ImdbScore = 8.7
            });
            TVShowEntity TVShow = context.TVShowItems.Where(x => x.Title == "Sex Education").FirstOrDefault();

            context.TVShowGenreItems.Add(new TVShowGenre()
            {
                Genre = context.GenreItems.Where(x => x.Genre == "Comedy").FirstOrDefault(), TVShow = context.TVShowItems.Where(x => x.Title == "Sex Education").FirstOrDefault()
            });
            context.TVShowGenreItems.Add(new TVShowGenre()
            {
                TVShowId = 2, GenreId = 3
            });

            await context.SaveChangesAsync();
        }
        public ActionResult RemoveTVShow(int id)
        {
            TVShowEntity item = _repository.GetSingle(id);

            if (item == null)
            {
                return(NotFound());
            }
            _repository.Delete(id);
            if (!_repository.Save())
            {
                throw new System.Exception("Deleting failed on save.");
            }
            return(NoContent());
        }
        public ActionResult GetSingleTVShow(int id)
        {
            TVShowEntity item = _repository.GetSingle(id);

            if (item == null)
            {
                return(NotFound());
            }
            TVShowResponse response = _mapper.Map <TVShowResponse>(item);

            foreach (var temp in item.TVShowGenre)
            {
                response.Genres.Add(temp.Genre.Genre);
            }

            return(Ok(response));
        }
        public ActionResult AddTVShow([FromBody] TVShowCreateDto tvCreate)
        {
            if (tvCreate == null)
            {
                return(BadRequest());
            }


            TVShowEntity toAdd = _mapper.Map <TVShowEntity>(tvCreate);

            _repository.Add(toAdd);

            if (!_repository.Save())
            {
                throw new System.Exception("Creating failed on");
            }

            TVShowEntity newItem = _repository.GetSingle(toAdd.TVShowId);

            return(CreatedAtRoute(nameof(GetSingleTVShow), newItem));
        }
Exemple #6
0
 public TVShowEntity Update(int id, TVShowEntity item)
 {
     _context.TVShowItems.Update(item);
     return(item);
 }
Exemple #7
0
        public void Delete(int id)
        {
            TVShowEntity tvItem = GetSingle(id);

            _context.TVShowItems.Remove(tvItem);
        }
Exemple #8
0
 public void Add(TVShowEntity item)
 {
     _context.TVShowItems.Add(item);
 }