public async Task <string> Promote_with_async_methods_in_the_beginning_and_in_the_middle_of_the_chain(long id) { var gateway = new EmailGateway(); return(await GetByIdAsync(id) .EnsureAsync(customer => customer.CanBePromoted(), "The customer has the highest status possible") .OnSuccessAsync(customer => customer.PromoteAsync()) .OnSuccessAsync(customer => gateway.SendPromotionNotificationAsync(customer.Email)) .OnBothAsync(result => result.IsSuccess ? "Ok" : result.Error.FormatString())); }
public async Task <string> Promote_with_async_methods_in_the_middle_of_the_chain(long id) { var gateway = new EmailGateway(); return(await GetById(id) .ToResult("Customer with such Id is not found: " + id) .Ensure(customer => customer.CanBePromoted(), "The customer has the highest status possible") .OnSuccess(customer => customer.PromoteAsync()) .OnSuccess(customer => gateway.SendPromotionNotificationAsync(customer.Email)) .OnBoth(result => result.IsSuccess ? "Ok" : result.Error)); }
public async Task <string> Promote_with_async_methods_in_the_beginning_and_in_the_middle_of_the_chain_using_compensate(long id) { var gateway = new EmailGateway(); return(await GetByIdAsync(id) .ToResult("Customer with such Id is not found: " + id) .Ensure(customer => customer.CanBePromoted(), "Need to ask manager") .OnFailure(error => Log(error)) .OnFailureCompensate(() => AskManager(id)) .Tap(customer => Log("Manager approved promotion")) .Tap(customer => customer.PromoteAsync()) .Bind(customer => gateway.SendPromotionNotificationAsync(customer.Email)) .Finally(result => result.IsSuccess ? "Ok" : result.Error)); }