public ActionResult PatchCustomerAccount(Guid companyId, Guid customerAccountId, [FromBody] JsonPatchDocument <CustomerAccountForUpdateDto> patchDocument)
        {
            if (patchDocument == null)
            {
                return(BadRequest());
            }

            if (!_customerAccountRepository.CustomerAccountExists(customerAccountId))
            {
                return(NotFound());
            }

            var customerAccountFromRepo = _customerAccountRepository.GetCustomerAccount(companyId, customerAccountId);

            if (customerAccountFromRepo == null)
            {
                var customerAccountDto = new CustomerAccountForUpdateDto();
                patchDocument.ApplyTo(customerAccountDto, ModelState);

                if (!TryValidateModel(customerAccountDto))
                {
                    return(ValidationProblem(ModelState));
                }

                var customerAccountToAdd = _mapper.Map <Entities.CustomerAccount>(customerAccountDto);
                customerAccountToAdd.Id = customerAccountId;

                _customerAccountRepository.CreateCustomerAccount(companyId, customerAccountToAdd);

                _customerAccountRepository.Save();

                var companyToReturn = _mapper.Map <CustomerAccountDto>(customerAccountToAdd);

                return(CreatedAtRoute("GetCustomerAccount",
                                      new { companyId, customerAccountId }, companyToReturn));
            }

            var customerAccountToPatch = _mapper.Map <CustomerAccountForUpdateDto>(customerAccountFromRepo);

            patchDocument.ApplyTo(customerAccountToPatch, ModelState);


            if (!TryValidateModel(customerAccountToPatch))
            {
                return(ValidationProblem(ModelState));
            }

            _mapper.Map(customerAccountToPatch, customerAccountFromRepo);

            _customerAccountRepository.UpdateCustomerAccount(customerAccountFromRepo);

            _customerAccountRepository.Save();

            return(NoContent());
        }