Exemplo n.º 1
0
        public async Task <IActionResult> CreateVideo([FromBody] SaveVideoResource saveVideoResource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var video = _mapper.Map <SaveVideoResource, Video>(saveVideoResource);

            _repository.Add(video);
            await _unitOfWork.CompleteAsync();

            await _unitOfWork.ChangeVideo(video.Id);

            var result = _mapper.Map <Video, VideoResource>(video);

            return(Ok(result));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> UpdateVideo(int id, [FromBody] SaveVideoResource saveVideoResource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            await _unitOfWork.ChangeVideo(id);

            var video = await _repository.GetVideo(id);

            if (video == null)
            {
                return(NotFound());
            }
            _mapper.Map(saveVideoResource, video);
            await _unitOfWork.CompleteAsync();

            var result = _mapper.Map <Video, VideoResource>(video);

            return(Ok(result));
        }