Skip to content

Commit

Permalink
mvc readme
Browse files Browse the repository at this point in the history
  • Loading branch information
pimbrouwers committed Oct 3, 2024
1 parent 6a62210 commit 916ad19
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 5 deletions.
93 changes: 90 additions & 3 deletions src/Danom.Mvc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
[![NuGet Version](https://img.shields.io/nuget/v/Danom.Mvc.svg)](https://www.nuget.org/packages/Danom.Mvc)
[![build](https://github.com/pimbrouwers/Danom/actions/workflows/build.yml/badge.svg)](https://github.com/pimbrouwers/Danom/actions/workflows/build.yml)

Danom.Mvc is a library that provides a set of utilities to help integrate the [Danom](../../README.md) library with common tasks in ASP.NET Core MVC applications.
Danom.Mvc is a library that provides a set of rendering utilities to help integrate the [Danom](../../README.md) library with common tasks in ASP.NET Core MVC applications.

## Getting Started

Expand All @@ -17,11 +17,98 @@ Or using the dotnet CLI
dotnet add package Danom.Mvc
```

### Quick Start
## Working With `Option`

```csharp
using Danom;
using Danom.Mvc;
using Microsoft.AspNetCore.Mvc;

public sealed class OptionController
: DanomController
{
private readonly Option<string> _someOption = Option.Some("Hello world");
private readonly Option<string> _noneOption = Option<string>.None();

public IActionResult OptionSome() =>
ViewOption(
option: _someOption,
viewName: "Detail");

// Returns the ASP.NET default `NotFound` result
public IActionResult OptionNone() =>
ViewOption(
option: _noneOption,
viewName: "Detail");

public IActionResult OptionNoneCustom() =>
ViewOption(
option: _noneOption,
viewName: "Detail",
noneAction: () => NotFound("Not found!"));
}
```

## Working with `Result`

```csharp
using Danom.Mvc;
using Microsoft.AspNetCore.Mvc;

public sealed class ResultController
: DanomController
{
private readonly Result<string, ResultErrors> _okResult = Result.Ok("Success!");
private readonly Result<string, ResultErrors> _errorResult = Result<string>.Error(["An error occurred."]);
private readonly Result<string, string> _stringErrorResult = Result<string, string>.Error("An error occurred.");

public IActionResult ResultOk() =>
ViewResult(
result: _okResult,
viewName: "Detail");

public IActionResult ResultErrors() =>
ViewResult(
result: _errorResult,
viewName: "Detail");

// Demonstrating error customization, using a string literal for error output
public IActionResult ResultError() =>
ViewResult(
result: _stringErrorResult,
errorAction: errors => View("Detail", errors),
viewName: "Detail");

}
```

## Working with `ResultOption`

```csharp
using Danom.Mvc;
using Microsoft.AspNetCore.Mvc;

public sealed class ResultOptionController
: DanomController
{
private readonly ResultOption<string, ResultErrors> _okResult = ResultOption.Ok("Success!");
private readonly ResultOption<string, ResultErrors> _errorResult = ResultOption<string>.Error("An error occurred.");
private readonly ResultOption<string, string> _stringErrorResult = ResultOption<string, string>.Error("An error occurred.");

public IActionResult ResultOk() =>
ViewResultOption(
resultOption: _okResult,
viewName: "Detail");

public IActionResult ResultErrors() =>
ViewResultOption(
resultOption: _errorResult,
viewName: "Detail");

// Demonstrating error customization, using a string literal for error output
public IActionResult ResultError() =>
ViewResultOption(
resultOption: _stringErrorResult,
errorAction: errors => View("Detail", errors),
viewName: "Detail");
}
```
2 changes: 1 addition & 1 deletion src/Danom.Validation/Danom.Validation.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<Nullable>enable</Nullable>
<DebugType>embedded</DebugType>
<OutputType>Library</OutputType>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<!-- <TreatWarningsAsErrors>true</TreatWarningsAsErrors> -->
<GenerateDocumentationFile>true</GenerateDocumentationFile>

<!-- NuGet config -->
Expand Down
4 changes: 3 additions & 1 deletion src/Danom.Validation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ Or using the dotnet CLI
dotnet add package Danom.Validation
```

### Quick Start
## Example

The kitchen sink example below demonstrates the functionality delivered from this slim library built on top of Danom.

```csharp
using Danom;
Expand Down

0 comments on commit 916ad19

Please sign in to comment.