Show / Hide Table of Contents

Class ModelListResult<TModel>

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

Inheritance
System.Object
ModelResult
ModelListResult<TModel>
Implements
IModelListResult<TModel>
IModelResult
Inherited Members
ModelResult.TraceKey
ModelResult.ModelStatusCode
ModelResult.Message
ModelResult.IsModelResultValid()
ModelResult.CreateBusinessValidationResult(String)
ModelResult.CreateConflictValidationResult(String)
ModelResult.CreateErrorValidationResult(String)
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 ModelListResult<TModel> : ModelResult, IModelListResult<TModel>, IModelResult where TModel : IModel
Type Parameters
Name Description
TModel

The type of the model to be returned in the result.

Constructors

ModelListResult()

Default constructor that set ModelStatusCode 200 and Message Success.

Declaration
public ModelListResult()

ModelListResult(Guid)

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

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

Key of trace.

Properties

Models

Collection model of the type TModel.

Declaration
public IEnumerable<TModel> Models { get; }
Property Value
Type Description
IEnumerable<TModel>

Collection of the model or null.

Validations

Validations of the properties.

Declaration
public IEnumerable<IValidation> Validations { get; }
Property Value
Type Description
IEnumerable<IValidation>

Validation items if they exist, otherwise, null.

Methods

AddValidation(String, String)

Add validated fields in the list of validations.

note

If adding a validation, the ModelStatusCode is 422 and Message is Validation.

Declaration
public void AddValidation(string attribute, string message)
Parameters
Type Name Description
System.String attribute

The field name validated.

System.String message

The message that describes the field validation.

Examples

Foo class used in this example.

public class Foo : IAggregateRoot
{
    private Foo() { }

    public string Name { get; private set; }

    public static IModelResult<Foo> NewFoo(string name)
    {
        var foo = new Foo { Name = name };

        return Validate(foo);
    }

    private static IModelResult<Foo> Validate(Foo foo)
    {
        var result = new ModelResult<Foo>();

        if (string.IsNullOrWhiteSpace(foo.Name))
            result.AddValidation("Name", "The field is required");

        if (result.IsModelResultValid())
            result.SetModel(foo);

        return result;
    }
}

CreateOk()

Override method to verify if exists items on the Validations.

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

Declaration
public override void CreateOk()
Overrides
ModelResult.CreateOk()
Examples

Foo class used in this example.

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

SetModel(IEnumerable<TModel>)

Set collection models of the type TModel.

Declaration
public void SetModel(IEnumerable<TModel> models)
Parameters
Type Name Description
IEnumerable<TModel> models

Collection of the model.

Examples

Sample using Foo class.

private static IModelListResult<Foo> Validate(Foo foo)
{
    var result = new ModelListResult<Foo>();
    var fooList = new List<Foo> { foo };

    result.SetModel(fooList);

    return result;
}

Implements

IModelListResult<TModel>
IModelResult
Back to top Generated by DocFX