using Sarand.Net.Standard.Base.Utils; using System; namespace Sarand.Net.Standard.Base.Core { //======================================================================= /// State Item interface. public interface ISacsStateItem { bool HasErrorState(); SacsErrorState ErrorState { get; } String ErrorStateMessage { get; } bool SetErrorState(String message); void ClearErrorState(); } //======================================================================= /// /// State Item - allows business component to record and report error message. /// public class SacsStateItem : ISacsStateItem { //------------------------------------------------------------------- // Data items. //------------------------------------------------------------------- // Protected construction - use derived classes. protected SacsStateItem() { } //------------------------------------------------------------------- // Poperties. /// OK - No error state message. public bool OK { get { return !HasErrorState(); } } // Error state. public SacsErrorState ErrorState { get; private set; } public bool HasErrorState() { return ErrorState != null; } public String ErrorStateMessage { get { return (ErrorState != null ? ErrorState.Message : String.Empty); } } // Update properties. public virtual bool SetErrorState(String message) { if (StringUtil.IsEmpty(StringUtil.EmptyOnNull(message).Trim())) throw new NotSupportedException($"{SysUtil.Fn} Blank error message."); this.ErrorState = new SacsErrorState(message); return false; } public void ClearErrorState() { ErrorState = null; } //------------------------------------------------------------------- } //======================================================================= }