Язык программирования C#9 и платформа .NET5 - Троелсен Эндрю
            Наш ресурс дает возможность бесплатно читать книгу онлайн Язык программирования C#9 и платформа .NET5 - Троелсен Эндрю. Жанр: Базы данных . Сайт books-read.com дает возможность читать полную версию книги без регистрации и sms. Все книги онлайн, не надо качать fb2, epub, txt.
        
        
        
    		protected readonly IRepo<T> MainRepo;protected readonly IAppLogging<TController> Logger;protected BaseCrudController(IRepo<T> repo, IAppLogging<TController> logger){  MainRepo = repo;  Logger = logger;}Методы GetXXX()
Есть два HTTP-метода
GETGetOne()GetAll()Getll()/// <summary>/// Gets all records/// </summary>/// <returns>All records</returns>/// <response code="200">Returns all items</response>[Produces("application/json")][ProducesResponseType(StatusCodes.Status200OK)][SwaggerResponse(200, "The execution was successful")][SwaggerResponse(400, "The request was invalid")][HttpGet]public ActionResult<IEnumerable<T>> GetAll(){  return Ok(MainRepo.GetAllIgnoreQueryFilters());}Следующий метод получает одиночную запись на основе параметра
id/// <summary>/// Gets a single record/// </summary>/// <param name="id">Primary key of the record</param>/// <returns>Single record</returns>/// <response code="200">Found the record</response>/// <response code="204">No content</response>[Produces("application/json")][ProducesResponseType(StatusCodes.Status200OK)][ProducesResponseType(StatusCodes.Status204NoContent)][SwaggerResponse(200, "The execution was successful")][SwaggerResponse(204, "No content")][HttpGet("{id}")]public ActionResult<T> GetOne(int id){  var entity = MainRepo.Find(id);  if (entity == null)  {    return NotFound();  }  return Ok(entity);}Значение маршрута автоматически присваивается параметру
id[FromRoute]Метод UpdateOne()
Обновление записи делается с применением HTTP-метода
PUTUpdateOne()/// <summary>/// Updates a single record/// </summary>/// <remarks>/// Sample body:/// <pre>/// {///   "Id": 1,///   "TimeStamp": "AAAAAAAAB+E="///   "MakeId": 1,///   "Color": "Black",///   "PetName": "Zippy",///   "MakeColor": "VW (Black)",/// }/// </pre>/// </remarks>/// <param name="id">Primary key of the record to update</param>/// <returns>Single record</returns>/// <response code="200">Found and updated the record</response>/// <response code="400">Bad request</response>[Produces("application/json")][ProducesResponseType(StatusCodes.Status200OK)][ProducesResponseType(StatusCodes.Status400BadRequest)][SwaggerResponse(200, "The execution was successful")][SwaggerResponse(400, "The request was invalid")][HttpPut("{id}")]public IActionResult UpdateOne(int id,T entity){  if (id != entity.Id)  {    return BadRequest();  }