public async Task <bool> Update(OngInputModel ongInputModel) { List <PersonPhoto> personPhotos = new List <PersonPhoto>(); if (ongInputModel.Photos != null) { foreach (var i in ongInputModel?.Photos) { personPhotos.Add(new PersonPhoto(new Photo(i))); } } var ong = await _ongRepository.GetByPersonId(ongInputModel.personId); ong.Update(ongInputModel.OpeningTime, ongInputModel.ClosingTime, ongInputModel.PageProfileLink ?? "", ongInputModel.About); ong.Person.Update(ongInputModel.Name, ongInputModel.Phone); ong.Person.PersonPhotos = personPhotos; var ongId = await _ongRepository.Update(ong); var address = await _addressRepository.GetByPersonId(ongInputModel.personId); if (address != null) { address.Update(ongInputModel.Address.Longitude, ongInputModel.Address.Latitude, ongInputModel.Address.Street, ongInputModel.Address.Neighborhood, ongInputModel.Address.Province, ongInputModel.Address.Zip, ongInputModel.Address.City, ongInputModel.Address.Country, ongInputModel.Address.Number, personId: ong.Person.Id, eventId: null); await _addressRepository.Update(address); } else { await _addressRepository.Add(new Address(ongInputModel.Address.Longitude, ongInputModel.Address.Latitude, ongInputModel.Address.Street, ongInputModel.Address.Neighborhood, ongInputModel.Address.Province, ongInputModel.Address.Zip, ongInputModel.Address.City, ongInputModel.Address.Country, ongInputModel.Address.Number, personId : ong.Person.Id, eventId : null)); } return(ongId > 0); }
public async Task <IActionResult> Put([FromBody] OngInputModel ongInputModel) { bool ret = false; var personId = GetPersonId(); if (!personId.HasValue) { return(BadRequest()); } ongInputModel.personId = (int)personId; ret = await _ongService.Update(ongInputModel); return(Ok(new { Ok = ret })); }