public static Contact CreateDomainContactWithId(this ContactWithId contact)
 => new Contact(
     contact?.Id ?? Guid.Empty,
     contact?.Name,
     contact?.DateOfBirth ?? new DateTime(),
     CreateDomainAddress(contact),
     contact?.PhoneNumbers);
        public async Task <IActionResult> Post(Contact contact)
        {
            try
            {
                ContactWithId result       = _useCaseFactory.CreateContactUseCase().Execute(contact);
                var           resourcePath = new Uri($"{Request.GetDisplayUrl()}/{result.Id}");
                await _hub.SendUpdateAsync(MessageType.ContactCreate, result);

                return(Created(resourcePath, result));
            }
            catch (ContactAlreadyExistsException e)
            {
                return(StatusCode(StatusCodes.Status422UnprocessableEntity, e));
            }
            catch (Exception e)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, e));
            }
        }
        public async Task <IActionResult> Put(ContactWithId contact)
        {
            try
            {
                ContactWithId result = _useCaseFactory.UpdateContactUseCase().Execute(contact);
                await _hub.SendUpdateAsync(MessageType.ContactUpdate, result);

                return(Ok(result));
            }
            catch (ContactAlreadyExistsException e)
            {
                return(StatusCode(StatusCodes.Status422UnprocessableEntity, e));
            }
            catch (ContactNotFoundException)
            {
                return(NotFound());
            }
            catch (Exception e)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, e));
            }
        }
Example #4
0
 public ContactWithId Execute(ContactWithId contact)
 => _repository.UpdateContact(contact.CreateDomainContactWithId()).CreateContactWithId();