public async Task <bool> Add(HomelessInputModel homelessInputModel)
        {
            List <PersonPhoto> personPhotos = new List <PersonPhoto>();

            if (homelessInputModel.Photos != null)
            {
                foreach (var i in homelessInputModel.Photos)
                {
                    personPhotos.Add(new PersonPhoto(new Photo(i)));
                }
            }

            var homelessId = await _homelessRepository.Add(new Homeless(homelessInputModel.Needs, homelessInputModel.About, homelessInputModel.CounterNotFound, new Person(homelessInputModel.Name, "", personPhotos), homelessInputModel.personIdCadastro));

            var homeless = await _homelessRepository.Get(homelessId);

            await _addressRepository.Add(new Address(homelessInputModel.Address.Longitude,
                                                     homelessInputModel.Address.Latitude,
                                                     homelessInputModel.Address.Street,
                                                     homelessInputModel.Address.Neighborhood,
                                                     homelessInputModel.Address.Province,
                                                     homelessInputModel.Address.Zip,
                                                     homelessInputModel.Address.City,
                                                     homelessInputModel.Address.Country,
                                                     homelessInputModel.Address.Number,
                                                     personId : homeless.PersonId,
                                                     eventId : null));

            return(homelessId > 0);
        }
        public async Task <bool> Update(HomelessInputModel homelessInputModel)
        {
            List <PersonPhoto> personPhotos = new List <PersonPhoto>();

            if (homelessInputModel.Photos != null)
            {
                foreach (var i in homelessInputModel.Photos)
                {
                    personPhotos.Add(new PersonPhoto(new Photo(i)));
                }
            }

            var homeless = await _homelessRepository.Get(homelessInputModel.Id);

            homeless.Update(homelessInputModel.Needs, homelessInputModel.About, homelessInputModel.CounterNotFound);
            homeless.Person.Update(homelessInputModel.Name, homelessInputModel.Phone);
            homeless.Person.PersonPhotos = personPhotos;

            var homelessId = await _homelessRepository.Update(homeless);

            var address = await _addressRepository.GetByPersonId(homeless.PersonId);

            if (address != null)
            {
                address.Update(homelessInputModel.Address.Longitude,
                               homelessInputModel.Address.Latitude,
                               homelessInputModel.Address.Street,
                               homelessInputModel.Address.Neighborhood,
                               homelessInputModel.Address.Province,
                               homelessInputModel.Address.Zip,
                               homelessInputModel.Address.City,
                               homelessInputModel.Address.Country,
                               homelessInputModel.Address.Number,
                               personId: homeless.Person.Id,
                               eventId: null);

                await _addressRepository.Update(address);
            }

            return(homelessId > 0);
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Put([FromBody] HomelessInputModel homelessInputModel)
        {
            bool ret;

            var personId = GetPersonId();

            if (!personId.HasValue)
            {
                return(NotFound());
            }

            homelessInputModel.personIdCadastro = (int)personId;

            if (homelessInputModel.Id > 0)
            {
                ret = await _homelessService.Update(homelessInputModel);
            }
            else
            {
                ret = await _homelessService.Add(homelessInputModel);
            }

            return(Ok(new { Ok = ret }));
        }