Beispiel #1
0
        internal static IResult <CreateContactCommandParameters> ToParsedParameters(this ICreateContactParameters createContactParameters)
        {
            if (createContactParameters == null)
            {
                throw new ArgumentNullException("createContactParameters");
            }

            var companyKeyResult = KeyParserHelper.ParseResult <ICompanyKey>(createContactParameters.CompanyKey);

            if (!companyKeyResult.Success)
            {
                return(companyKeyResult.ConvertTo <CreateContactCommandParameters>());
            }

            var setAddresses = new List <SetContactAddressParameters>();

            foreach (var address in createContactParameters.Addresses ?? new List <IContactAddressReturn>())
            {
                var addressResult = address.ToParsedParameters();
                if (!addressResult.Success)
                {
                    return(addressResult.ConvertTo <CreateContactCommandParameters>());
                }
                setAddresses.Add(addressResult.ResultingObject);
            }

            return(new SuccessResult <CreateContactCommandParameters>(new CreateContactCommandParameters
            {
                Parameters = createContactParameters,
                CompanyKey = companyKeyResult.ResultingObject.ToCompanyKey(),
                SetAddresses = setAddresses
            }));
        }
 public IResult <string> CreateContact(ICreateContactParameters parameters)
 {
     try
     {
         return(_companyServiceProvider.CreateContact(parameters));
     }
     catch (Exception ex)
     {
         _exceptionLogger.LogException(ex);
         return(new FailureResult <string>(null, ex.Message));
     }
 }
        public IResult<string> CreateContact(ICreateContactParameters parameters)
        {
            if(parameters == null) { throw new ArgumentNullException("parameters"); }

            var parametersResults = parameters.ToParsedParameters();
            if(!parametersResults.Success)
            {
                return parametersResults.ConvertTo<string>();
            }

            var createResult = new CreateContactCommand(_companyUnitOfWork).Execute(parametersResults.ResultingObject);
            if(!createResult.Success)
            {
                return createResult.ConvertTo<string>();
            }

            _companyUnitOfWork.Commit();

            return SyncParameters.Using(new SuccessResult<string>(createResult.ResultingObject.ToContactKey()), createResult.ResultingObject.ToCompanyKey());
        }