Esempio n. 1
0
        public async Task <ActionResult> Post(MovieDto dto)
        {
            _movieDtoValidator.Validate(dto).ThrowIfInvalid();

            await _service.CreateAsync(dto);

            return(Created(dto.Id.ToString(), null));
        }
        public async Task <ActionResult <MovieDto> > Post()
        {
            var poster =
                Request.Form.Files.Count() > 0 ?
                new AppFile()
            {
                FileName = Request.Form.Files[0].FileName,
                Content  = await Request.Form.Files[0].ToByteArrayAsync()
            } :
            null;

            Enum.TryParse(Request.Form["Genre"].ToString(), out MovieGenre genre);
            var movie = new Movie()
            {
                Name  = Request.Form["Name"].ToString(),
                Genre = genre
            };

            return(new OkObjectResult(
                       _mapper.Map <Movie, MovieDto>(await _service.CreateAsync(movie, poster))
                       ));
        }