Beispiel #1
0
        public async Task <IActionResult> PostSeries([FromBody] SeriesViewModel series)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var nameExists = (await _seriesRepository.GetSeriesByName(series.Name)) != null;

            if (nameExists)
            {
                return(BadRequest("A series by that name already exists."));
            }

            var entity = _mapper.Map <SeriesViewModel, Series>(series);
            await _seriesRepository.PostSeries(entity);

            await _seriesRepository.SaveChanges();

            _mapper.Map(entity, series);
            return(Created("", series));
        }