Пример #1
0
        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));
        }
Пример #2
0
        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);
        }