How to do it...

  1. First, we will create a Result class. This class will be returned by the Service layer. It allows us to manage the error messages to log and to display to the views:
public class Result{  public bool IsSuccess { get; }  public string SuccessMessageToLog { get; set; }  public string ErrorToLog { get; }  public string ErrorToDisplay { get; set; }  public ErrorType? ErrorType { get; }  public bool IsFailure => !IsSuccess;  protected Result(bool isSuccess, string error, ErrorType? errorType)  {    if ((isSuccess && error != string.Empty) ||    (isSuccess && !errorType.HasValue))    throw new InvalidOperationException();    if ((!isSuccess && error == string.Empty) ||    (isSuccess && errorType.HasValue))    throw new InvalidOperationException(); IsSuccess ...

Get ASP.NET Core MVC 2.0 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.