Ejemplo n.º 1
0
        public async Task <ActionResult <ApiMessage <MediaTitleVm> > > Put(int id, [FromBody] MediaTitleVm title)
        {
            // find first to determine type
            var entity = await _service.Get(id);

            if (entity == null)
            {
                return(NotFound(new ApiMessage {
                    Error = ApiError.NotFound
                }));
            }

            title.Id = id;
            if (entity.Type == MediaTitleType.Movie)
            {
                var movie = _mapper.Map <Movie>(title);
                await _service.Update(movie);
            }
            else if (entity.Type == MediaTitleType.Series)
            {
                var series = _mapper.Map <Series>(title);
                await _service.Update(series);
            }
            // invalidate cache
            _cache.Remove(CacheKeys.MediaTitle(id));

            return(ApiMessage.From(title));
        }
Ejemplo n.º 2
0
        public async Task <ActionResult <ApiMessage <MediaTitleVm> > > Post([FromBody] MediaTitleVm title)
        {
            if (title.Type == MediaTitleType.Movie)
            {
                var movie = _mapper.Map <Movie>(title);
                await _service.Add(movie);

                title.Id = movie.Id;
            }
            else if (title.Type == MediaTitleType.Series)
            {
                var series = _mapper.Map <Series>(title);
                await _service.Add(series);

                title.Id = series.Id;
            }
            return(ApiMessage.From(title));
        }