/
Egor1k
/
CompClubAPI
Обзор
Документация
Войти
/
Egor1k
/
CompClubAPI
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
Controllers/TariffController.cs
70 строк
2 KB
Dima Oshuev
поменял структуру проекта для сборки в docker
27 мар 2025, 16:32
27 мар 2025, 16:32
5c3d032
Код
Авторство
О чём код?
using CompClubAPI; using CompClubAPI.Models; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; namespace ComputerClubAPI.Controller { [Route("api/[controller]")] [ApiController] public class TariffController : ControllerBase { private readonly ApplicationDbContext _context; public TariffController(ApplicationDbContext context) { this._context = context; } [HttpGet("GetAllTariffs")] public async Task<IActionResult> GetAllTariffs() { var tariffs = await _context.Tariffs .ToListAsync(); if (tariffs == null) { return NotFound(); } return Ok(tariffs); } [HttpGet("GetTariffById/{id}")] public async Task<IActionResult> GetTariffById(long id) { var tariff = await _context.Tariffs .FirstOrDefaultAsync(c => c.TariffId == id); if (tariff == null) { return NotFound(); } return Ok(tariff); } [HttpGet("get-sorted-tariffs")] public async Task<IActionResult> GetSortedTariffs([FromQuery] bool? sortByHourlyRate) { var tariffs = await _context.Tariffs.ToListAsync(); if (tariffs == null) { return NotFound("Тарифы не найдены"); } if (sortByHourlyRate.HasValue && sortByHourlyRate.Value) { var sortedTariffs = tariffs.OrderByDescending(t => t.HourlyRate); return Ok(sortedTariffs); } else { var sortedTariffs = tariffs.OrderBy(t => t.HourlyRate); return Ok(sortedTariffs); } } } }