public ActionResult <TrackReadDto> CreateTrack(TrackCreateDto trackCreateDto)
        {
            var trackModel = _mapper.Map <Track>(trackCreateDto);

            _repository.CreateTrack(trackModel);

            _repository.SaveChanges();

            var trackReadDto = _mapper.Map <TrackReadDto>(trackModel);

            return(CreatedAtRoute(nameof(GetSingleTrack), new { Id = trackReadDto.Id }, trackCreateDto));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> CreateTrack([FromBody] TrackCreateDto track)
        {
            if (track == null)
            {
                return(BadRequest("TrackDto object is null."));
            }
            else
            {
                var trackEntity = _mapper.Map <Track>(track);
                _repository.Track.CreateTrack(trackEntity);
                await _repository.SaveAsync();

                var trackToReturn = _mapper.Map <TrackDto>(trackEntity);
                return(CreatedAtRoute("GetTrack", new { id = trackToReturn.Id }, trackToReturn));
            }
        }