Ejemplo n.º 1
0
        public async Task <IActionResult> GetAsync(int personId)
        {
            if (await _personRepository.GetAsync(personId) == null)
            {
                return(NotFound());
            }

            var emails = await _emailRepository.GetFilterByForeignKey(personId, nameof(Email.PersonId));

            if (emails == null)
            {
                return(NotFound());
            }

            return(Ok(emails));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> GetAsync(int personId)
        {
            if (await _personRepository.GetAsync(personId) == null)
            {
                return(NotFound());
            }

            var addresses = await _addressRepository.GetFilterByForeignKey(personId, nameof(Address.PersonId));

            if (addresses == null)
            {
                return(NotFound());
            }

            return(Ok(addresses));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> DeleteAsync(int id)
        {
            var person = await _personRepository.GetAsync(id);

            if (person == null)
            {
                return(NotFound());
            }

            var user = await _userRepository.GetAsync(id);

            if (user != null)
            {
                await _userRepository.DeleteAsync(user);

                _log.LogDeleted(HttpContext.Request.Method, HttpContext.Request.Path, "user: "******"email: " + JsonConvert.SerializeObject(email).ToString());
            }

            var addresses = await _addressRepository.GetFilterByForeignKey(id, nameof(Address.PersonId));

            foreach (var address in addresses)
            {
                await _addressRepository.DeleteAsync(address);

                _log.LogDeleted(HttpContext.Request.Method, HttpContext.Request.Path, "address: " + JsonConvert.SerializeObject(address).ToString());
            }

            if (!await _personRepository.DeleteAsync(person))
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, "Unable to delete person"));
            }

            _log.LogDeleted(HttpContext.Request.Method, HttpContext.Request.Path, JsonConvert.SerializeObject(person).ToString());

            return(NoContent());
        }