public async Task <ActionResult <ApiContactResultModel> > Add([FromBody] ContactsModel model)
        {
            var result    = new ApiContactResultModel();
            var contactId = new IdValueObject().Value;

            try
            {
                model.Id = contactId;
                await _mediator.Send(new AddContactCommand(model));

                result.Success   = true;
                result.ContactId = contactId;
                return(Ok(result));
            }
            catch (InvalidEntityException ex)
            {
                result.Errors = new List <string> {
                    ex.Message
                };
                return(BadRequest(result));
            }
            catch (EntityValidationException ex)
            {
                result.Errors = ex.ValidationResults.Select(x => x.ErrorMessage);
                return(BadRequest(result));
            }
            catch (Exception ex)
            {
                result.Errors = new List <string> {
                    ex.Message
                };
                _logger.Error(ex, "Error adding contact");
                return(BadRequest(result));
            }
        }
        public async Task <ActionResult <ApiContactResultModel> > Delete([FromRoute] string id)
        {
            var result = new ApiContactResultModel();

            try
            {
                await _mediator.Send(new DeleteContactCommand(id));

                result.Success   = true;
                result.ContactId = id;
                return(Ok(result));
            }
            catch (InvalidEntityException ex)
            {
                result.Errors = new List <string> {
                    ex.Message
                };
                return(BadRequest(result));
            }
            catch (EntityNotFound ex)
            {
                result.Errors = new List <string> {
                    ex.Message
                };
                return(NotFound(result));
            }
            catch (Exception ex)
            {
                result.Errors = new List <string> {
                    ex.Message
                };
                _logger.Error(ex, "Error deleting contact");
                return(BadRequest(result));
            }
        }
        public async Task <ActionResult <ApiContactResultModel> > Update([FromBody] ContactsModel model)
        {
            var result = new ApiContactResultModel();

            try
            {
                await _mediator.Send(new UpdateContactCommand(model));

                result.Success   = true;
                result.ContactId = model.Id;
                return(Ok(result));
            }
            catch (InvalidEntityException ex)
            {
                result.Errors = new List <string> {
                    ex.Message
                };
                return(BadRequest(result));
            }
            catch (EntityValidationException ex)
            {
                result.Errors = ex.ValidationResults.Select(x => x.ErrorMessage);
                return(BadRequest(result));
            }
            catch (EntityNotFound ex)
            {
                result.Errors = new List <string> {
                    ex.Message
                };
                return(NotFound(result));
            }
            catch (Exception ex)
            {
                result.Errors = new List <string> {
                    ex.Message
                };
                _logger.Error(ex, "Error updating contact");
                return(BadRequest(result));
            }
        }