Byndyusoft.ModelResult 1.1.5

There is a newer version of this package available.
See the version list below for details.
dotnet add package Byndyusoft.ModelResult --version 1.1.5                
NuGet\Install-Package Byndyusoft.ModelResult -Version 1.1.5                
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" Version="1.1.5" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Byndyusoft.ModelResult --version 1.1.5                
#r "nuget: Byndyusoft.ModelResult, 1.1.5"                
#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 as a Cake Addin
#addin nuget:?package=Byndyusoft.ModelResult&version=1.1.5

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

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.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.1

    • No dependencies.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Byndyusoft.ModelResult:

Package Downloads
Byndyusoft.ModelResult.AspNetCore

Package Description

Byndyusoft.Net.YandexAuth

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.4.0 830 6/25/2024
1.3.0 288 2/27/2024
1.2.0 1,645 11/21/2023
1.1.5 178 9/7/2023
1.1.4 2,551 2/9/2023
1.1.3 1,827 12/25/2020
1.1.2 588 12/17/2020
1.1.1 758 11/16/2020
1.0.1 599 11/9/2020
1.0.0 664 11/7/2020