/
nicteres
/
Lab1
Обзор
Документация
Войти
/
nicteres
/
Lab1
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
123
API_Lab_1/src/Services/ShelfService.cs
63 строки
2 KB
Matthew
Добавьте файлы проекта.
18 окт 2025, 18:03
18 окт 2025, 18:03
79e10ad
Код
Авторство
О чём код?
using API_Lab_1.src.Interface; using API_Lab_1.src.Models; using Microsoft.AspNetCore.Http.HttpResults; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using NuGet.Protocol; namespace API_Lab_1.src.Services { public class ShelfService(AppDbContext _appDb) : IShelfService { public async Task<ShelfModel?> CreateBook(ShelfRequest book_request) { var book = new ShelfModel { Name = book_request.Name, Description = book_request.Description, }; await _appDb.Shelf.AddAsync(book); await _appDb.SaveChangesAsync(); return book; } public async Task<List<ShelfModel>?> GetAllBooks() { var books = await _appDb.Shelf.ToListAsync(); if (books.Count is 0) return null; return books; } public async Task<ShelfModel?> GetBookById(int id) { var book = await _appDb.Shelf.FirstOrDefaultAsync(u => u.Id == id); if (book != null) { return book; } return null; } public async Task<List<ShelfModel>?> GetRange(int start, int end) { if (start > end && start < 0) return null; var amount = await _appDb.Shelf.CountAsync(); if (amount <= end) return null; // Including START and END var books = await _appDb.Shelf.Skip(start - 1).Take(end - start + 1).ToListAsync(); return books; throw new NotImplementedException(); } } }