Created
July 3, 2015 13:40
-
-
Save vkhorikov/7df31ddd7bdc066623c4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void Create(string name, string email, string billingInfo) | |
{ | |
Result<CustomerName> nameResult = CustomerName.Create(name); | |
Result<Email> emailResult = Email.Create(email); | |
Result<BillingInfo> billingInfoResult = BillingInfo.Create(billingInfo); | |
return Result.Combine(nameResult, emailResult, billingInfoResult) | |
.OnSuccess(() => _paymentGateway.ChargeCommission(billingInfoResult.Value)); | |
/* Other OnSuccess, OnFailure, OnBoth methods */ | |
} | |
public class Result | |
{ | |
public bool Success { get; private set; } | |
public string[] Errors { get; private set; } | |
public static Result Combine(params Result[] results) | |
{ | |
if (results.Any(r => r.Failure)) | |
{ | |
string[] errors = results.SelectMany(r => r.Errors).ToArray(); | |
return Fail(errors); | |
} | |
return Ok(); | |
} | |
/* Other members as before */ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment