public async Task <IActionResult> Update(int id, [FromForm] PersonDtoUpdate newItem) { var result = await _PersonService.UpdatePerson(id, newItem); if (result.IsSuccess == false) { return(NotFound(result)); } return(Ok(result)); }
public async Task <ServiceResponse <PersonDto> > UpdatePerson(int id, PersonDtoUpdate newItem) { var response = new ServiceResponse <PersonDto>(); Person person = await _context.People.FindAsync(id); if (person == null) { response.IsSuccess = false; response.Message = $"id = {id} Not found."; } person = _mapper.Map(newItem, person); 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.EditFile(content, extension, containerName, person.Picture, newItem.Picture.ContentType); } } _context.People.Update(person); await _context.SaveChangesAsync(); PersonDto PersonDTO = _mapper.Map <PersonDto>(person); response.Data = PersonDTO; return(response); }