Show / Hide Table of Contents

Class ModelResult

Concrete class that implements the interface with the necessary methods to execute the validations of the models.

Inheritance
System.Object
ModelResult
ModelListResult<TModel>
ModelPagedListResult<TModel>
ModelResult<TModel>
Implements
IModelResult
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ToString()
System.Object.ReferenceEquals(System.Object, System.Object)
Namespace: StoneCo.Framework.Model.ModelRules
Assembly: cs.temp.dll.dll
Syntax
public class ModelResult : IModelResult

Constructors

ModelResult()

Default constructor that set ModelStatusCode 200 and Message Success.

Declaration
public ModelResult()

ModelResult(Guid)

Default constructor that set ModelStatusCode 200, Message Success and TraceKey.

Declaration
public ModelResult(Guid traceKey)
Parameters
Type Name Description
Guid traceKey

Key of trace.

Properties

Message

Validation message.

Declaration
public string Message { get; }
Property Value
Type Description
System.String

Sample Error on service layer., Success, ...

ModelStatusCode

Model ststus code. This code follows the HttpStatusCode pattern.

Declaration
public int ModelStatusCode { get; }
Property Value
Type Description
System.Int32

Sample 400, 500, 200, ...

TraceKey

Key of trace.

Declaration
public string TraceKey { get; }
Property Value
Type Description
System.String

Sample a4477c7f88264bc1973e55856c8cfbd2

Methods

CreateBusinessValidationResult(String)

Create the business validation with ModelStatusCode 422 and Message with the value of parameter.

To simplify development and facilitate traceability, the codes follow the Http status code pattern.

Declaration
public void CreateBusinessValidationResult(string message)
Parameters
Type Name Description
System.String message

Message validation.

Examples

Foo class used in this example.

public class Foo : IAggregateRoot
{
    public IModelResult NewName(string name)
    {
        var result = new ModelResult();

        if (string.IsNullOrWhiteSpace(name))
            result.CreateBusinessValidationResult("The name is required.");

        return result;
    }
}

CreateConflictValidationResult(String)

Create a conflict validation with ModelStatusCode 409 and Message with the value of parameter.

Declaration
public void CreateConflictValidationResult(string message)
Parameters
Type Name Description
System.String message

Message validation.

Examples

Foo class used in this example.

public class IFooService
{
    public IModelResult Insert(Model model)
    {
        var result = new ModelResult();
        try
        {
            _repository.Insert(model);
        }
        catch(SqlException sqlException)
        {
            if (sqlException.Number == PRIMARY_KEY_DUPLICATED_NUMBER)
            {        
                result.CreateConflictValidationResult($"Duplicated primary key conflict. {sqlException.Message}");
            }
            else throw slqException;
        }
        return result;
    }
}

CreateErrorValidationResult(String)

Create the error validation with ModelStatusCode 500 and Message with the value of parameter.

To simplify development and facilitate traceability, the codes follow the Http status code pattern.

Declaration
public void CreateErrorValidationResult(string message = null)
Parameters
Type Name Description
System.String message

Message validation. If message is null, the default message will be .

Examples

Foo class used in this example.

public class Foo : IAggregateRoot
{
    public IModelResult NewName(string name)
    {
        var result = new ModelResult();

        if (string.IsNullOrWhiteSpace(name))
            result.CreateErrorValidationResult("Name cannot be null.");

        return result;
    }
}

CreateOk()

Create ModelStatusCode 200 and Message Success.

To simplify development and facilitate traceability, the codes follow the Http status code pattern.

Declaration
public virtual void CreateOk()
Examples

Foo class used in this example.

public class Foo : IAggregateRoot
{
    public IModelResult NewFoo() => new ModelResult();
}

IsModelResultValid()

Check the result.

Declaration
public bool IsModelResultValid()
Returns
Type Description
System.Boolean

True if ModelStatusCode less than 400, otherwise, false.

Examples

Bar class used in this example.

To implement full example, see first the CreateBusinessValidationResult(String) example.

public class Bar
{
    public void VerifyResult()
    {
        var foo = new Foo();
        var result = foo.NewName("Stone Co");

        if(!result.IsModelResultValid())
            // Your decision...

    }
}

Implements

IModelResult
Back to top Generated by DocFX