Existing entity constraints

Action methods of controllers usually perform constraints on incoming data. A common practice is to centralize that kind of logic in filters. Let's take, for example, OrderController, which we discussed in the previous chapter:

using System;using System.Collections.Generic;using System.Linq;using Microsoft.AspNetCore.JsonPatch;using Microsoft.AspNetCore.Mvc;using SampleAPI.Filters;using SampleAPI.Models;using SampleAPI.Repositories;using SampleAPI.Requests;namespace SampleAPI.Controllers{    [Route("api/order")]    [ApiController]    public class OrderController : ControllerBase    {        private readonly IOrderRepository _orderRepository;        public OrderController(IOrderRepository ordersRepository)        { _orderRepository = ordersRepository; ...

Get Hands-On RESTful Web Services with ASP.NET Core 3 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.