public async Task <ServiceResponse <PersonDto> > AddPerson(PersonDtoAdd newItem) { var response = new ServiceResponse <PersonDto>(); Person person = _mapper.Map <Person>(newItem); if (newItem.Picture != null) { using (var memoryStream = new MemoryStream()) { await newItem.Picture.CopyToAsync(memoryStream); var content = memoryStream.ToArray(); var extension = Path.GetExtension(newItem.Picture.FileName); person.Picture = await _fileStorageService.SaveFile(content, extension, containerName, newItem.Picture.ContentType); } } _context.People.Add(person); await _context.SaveChangesAsync(); PersonDto personDTO = _mapper.Map <PersonDto>(person); response.Data = personDTO; return(response); }
public async Task <IActionResult> Add([FromForm] PersonDtoAdd newItem) { var result = await _PersonService.AddPerson(newItem); return(Ok(result)); }