The purpose of this code is to centralize all error / status messages to present to the user. For example, registering an account and the user email address is already registered. A status code is set then sent off to get a friendly error message to present to the user. All services will have its own set of status code and status messages which is handled by a status handler for filtering. While this is only a basic class I want to make sure that I am going in the right direction before extending.
Status codes
namespace Services.RegistrationService
{
public enum StatusCodes
{
UserAlreadyExists,
// more to come
}
}
List of statuses for registration
using Framework;
using System.Collections.Generic;
namespace Services.RegistrationService
{
public class RegistrationStatusMessages : MessageStatusHandler
{
public void AddErrors(List<StatusCodes> codes)
{
foreach(var errorCodes in codes)
switch (errorCodes)
{
case StatusCodes.UserAlreadyExists: { base.add("User already exists", "EmailAddress", true); break; }
}
}
}
}
Message status handler
using System.Collections.Generic;
using System.Linq;
namespace Framework
{
public class MessageStatusHandler
{
protected List<MessageStatusHandler> _errorList;
private string _friendlyErrorMessage;
private bool _isError;
private string _propertyName;
public MessageStatusHandler()
{
_errorList = new List<MessageStatusHandler>();
}
protected void add(string friendlyErrorMessage, string propertyName, bool isError)
{
_errorList.Add(new MessageStatusHandler { _friendlyErrorMessage = friendlyErrorMessage, _propertyName = propertyName, _isError = isError });
}
public bool HasErrors()
{
return _errorList.Any(x => x._isError == true);
}
}
}
Again, it is a simple class setup that centralizes status codes, error messages for each service. Is there any way to improve on this, or am I going in the right direction?