Byndyusoft.ModelResult.AspNetCore 1.3.0

dotnet add package Byndyusoft.ModelResult.AspNetCore --version 1.3.0
NuGet\Install-Package Byndyusoft.ModelResult.AspNetCore -Version 1.3.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Byndyusoft.ModelResult.AspNetCore" Version="1.3.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Byndyusoft.ModelResult.AspNetCore --version 1.3.0
#r "nuget: Byndyusoft.ModelResult.AspNetCore, 1.3.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Byndyusoft.ModelResult.AspNetCore as a Cake Addin
#addin nuget:?package=Byndyusoft.ModelResult.AspNetCore&version=1.3.0

// Install Byndyusoft.ModelResult.AspNetCore as a Cake Tool
#tool nuget:?package=Byndyusoft.ModelResult.AspNetCore&version=1.3.0

Byndyusoft.ModelResult

The result of domain logic, similar to ActionResult

Byndyusoft.ModelResult Nuget Downloads
Byndyusoft.ModelResult.AspNetCore Nuget Downloads

Installing

dotnet add package Byndyusoft.ModelResult

Usage

ModelResult can be used to return either an "ok" value or an "error" value without explicit casting. Here are some usage examples:

public ModelResult<int> GetId(SampleEntity entity)
{
    if (entity.HasId())
        return entity.Id;

    return new ErrorModelResult("Project.SampleEntity.NoId", "Entity does not contain Id");
}

public ModelResult ValidateEntity(SampleEntity entity)
{
    var errorInfoItems = new List<ErrorInfoItem>();

    if (entity.HasId() == false)
        errorInfoItems.Add(new ErrorInfoItem("Id", "Entity does not contain Id"));

    if (errorInfoItems.Any())
        return new ErrorModelResult("Project.SampleEntity.NotValid", "There are validation errors", errorInfoItems.ToArray());

    return new OkModelResult();
}

public ModelResult<EntityInfoDto> GetEntityInfoDto(SampleEntity entity)
{
    ModelResult<int> idResult = GetId(entity);

    if (idResult.IsError())
    {
        _logger.LogError("Error getting id: {@ErrorInfo}", idResult.GetError());
        return idResult.AsSimple();
    }

    var entityInfoDto = new EntityInfoDto {Id = idResult.Result};
    return entityInfoDto;
}

ModelResult.AspNetCore

A converter of ModelResult to ActionResult

Installing

dotnet add package Byndyusoft.ModelResult.AspNetCore

Usage

[HttpGet("{id:long}")]
public async Task<ActionResult<EntityInfoDto>> GetEntityInfoDto([FromRoute] long id,
    [FromServices] IGetEntityInfoDtoUseCase useCase, CancellationToken cancellationToken)
{
    var result = await useCase.GetAsync(id, cancellationToken);
    return result.ToActionResult();
}

If result is an "ok" result then the action method will return a message with the 200 code and the contents of the DTO. Otherwise if it is "error" result it is usually will be transformed to 400 code with error info that contains code, message and items. The current version has one exception: if an error code is equal to Byndyusoft.ModelResult.Common.CommonErrorCodes.NotFound there will be the 404 code without any content.

Contributing

To contribute, you will need to setup your local environment, see prerequisites. For a contribution and workflow guide, see package development lifecycle.

A detailed overview on how to contribute can be found in the contributing guide.

Prerequisites

Make sure you have installed all of the following prerequisites on your development machine:

Package development lifecycle

  • Implement package logic in src
  • Add or adapt unit-tests in tests
  • Add or change the documentation as needed
  • Open pull request for a correct branch. Target the project's master branch

Maintainers

github.maintain@byndyusoft.com

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.1 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.3.0 177 2/27/2024
1.2.0 212 11/21/2023
1.1.5 122 9/7/2023
1.1.4 1,575 2/9/2023
1.1.3 930 12/25/2020
1.1.2 429 12/17/2020
1.1.1 448 11/16/2020
1.0.1 442 11/9/2020
1.0.0 512 11/7/2020