Ejemplo n.º 1
0
 public static Show MapToShow(this TvShowDto dto)
 => new Show
 {
     Id   = dto.Id,
     Name = dto.Name,
     Cast = dto._embedded
            .Cast?
            .Select(c => c.Person)
            .OrderBy(p => p.Birthday ?? DateTime.MaxValue)
            .Select(MapToPerson)
            .ToArray()
 };
Ejemplo n.º 2
0
        public static TvShowDto FromQueryResponse(this TvShowDto dto, GetTvShowsResponse.MediaContainerDirectory queryResult)
        {
            if (queryResult == null)
            {
                return(dto);
            }

            return(new TvShowDto
            {
                Title = queryResult.title,
                Year = queryResult.year,
                IdPlex = queryResult.ratingKey
            });
        }
Ejemplo n.º 3
0
        public IHttpActionResult CreateTvShow(TvShowDto tvShowDto)
        {
            //First we validate the object, and throw exception if model is not valid
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            //We need to map the tvShowDto back to our domain model.
            var tvShow = Mapper.Map <TvShowDto, TvShow>(tvShowDto);

            //otherwise we add it to our context and save the changes
            _context.TvShows.Add(tvShow);
            _context.SaveChanges();

            tvShowDto.Id = tvShow.Id;

            //At this point the Id of the tv show will be generated by the server and be returned by the object.
            //As part of RESTful convention, we need to return the URI of the newly created resource to the client.
            //i.e. /api/members/10
            return(Created(new Uri(Request.RequestUri + "/" + tvShow.Id), tvShowDto));
        }
Ejemplo n.º 4
0
        public IHttpActionResult UpdateTvShow(int id, TvShowDto tvShowDto)
        {
            //First we validate the object, and throw exception if model is not valid
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var tvShowInDb = _context.TvShows.SingleOrDefault(c => c.Id == id);

            //It's possible that the client sends an invalid Id so we need to check for the existence of the object.
            if (tvShowInDb == null)
            {
                return(NotFound());
            }

            Mapper.Map(tvShowDto, tvShowInDb);

            _context.SaveChanges();

            return(Ok());
        }
Ejemplo n.º 5
0
        public static TvShowDto FromQueryResponse(this TvShowDto dto, GetTvShowResponse response)
        {
            if (response == null)
            {
                return(dto);
            }

            int?year = null;

            if (!string.IsNullOrWhiteSpace(response.first_air_date))
            {
                year = int.Parse(response.first_air_date.Split('-')[0]);
            }

            return(new TvShowDto
            {
                Id = response.id.ToString(),
                Title = response.name,
                Year = year,
                Language = response.original_language,
                Seasons = null,
            });
        }