public async Task <ActionResult> Post([FromForm] ActorCreateDTO actorCreateDTO) { var actor = _mapper.Map <Actor>(actorCreateDTO); if (actorCreateDTO.Image != null) { using (var memoryStream = new MemoryStream()) { await actorCreateDTO.Image.CopyToAsync(memoryStream); var content = memoryStream.ToArray(); var extension = Path.GetExtension(actorCreateDTO.Image.FileName); actor.Image = await _filesStore.SaveFile(content, extension, _container, actorCreateDTO.Image.ContentType); } } _context.Actors.Add(actor); await _context.SaveChangesAsync(); var dto = _mapper.Map <ActorDTO>(actor); return(new CreatedAtRouteResult("GetActor", new { id = actor.Id }, dto)); }
public async Task <ActionResult> Post([FromForm] MovieCreateDTO movieCreateDTO) { var movie = _mapper.Map <Movie>(movieCreateDTO); if (movieCreateDTO.Poster != null) { using (var memoryStream = new MemoryStream()) { await movieCreateDTO.Poster.CopyToAsync(memoryStream); var content = memoryStream.ToArray(); var extension = Path.GetExtension(movieCreateDTO.Poster.FileName); movie.Image = await _filesStore.SaveFile(content, extension, _container, movieCreateDTO.Poster.ContentType); } } AssignActorsOrder(movie); _context.Movies.Add(movie); await _context.SaveChangesAsync(); var dto = _mapper.Map <MovieDTO>(movie); return(new CreatedAtRouteResult("GetMovie", new { id = movie.Id }, dto)); }