mirror of
https://gitlab.com/Hukuta47/cartrix.git
synced 2026-12-05 12:30:55 +00:00
46 lines
1.6 KiB
C#
46 lines
1.6 KiB
C#
using CartriX.Shared.Classes;
|
|
using CartriX.Shared.Mappers;
|
|
using CartriX.Shared.DTOs.Printer;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using CartriX.Shared.Models;
|
|
using CartriX.Api.Interfaces;
|
|
|
|
namespace CartriX.Api.Services
|
|
{
|
|
public class PrinterService : IPrinterService
|
|
{
|
|
private readonly AppDbContext _context;
|
|
public PrinterService(AppDbContext context)
|
|
{
|
|
_context = context;
|
|
}
|
|
public async Task<Printer> AddAsync(CreatePrinterRequestDto requestDto)
|
|
{
|
|
Task<Printer> printerModel = requestDto.ToPrinterModelAsync(_context); // context Because in ToPrinterModelAsync, enable check to database, vot takie porogi :\
|
|
|
|
await _context.Printers.AddAsync(printerModel.Result);
|
|
await _context.SaveChangesAsync();
|
|
|
|
return printerModel.Result;
|
|
}
|
|
public async Task<List<Printer>> GetAll()
|
|
{
|
|
Console.WriteLine("Запрос в базу данных.");
|
|
List<Printer> queryResult = await _context.Printers
|
|
.Include(l => l.location)
|
|
.Include(m => m.model).ToListAsync();
|
|
return queryResult;
|
|
}
|
|
|
|
public async Task<Printer?> GetById(int id)
|
|
{
|
|
Console.WriteLine("Запрос в базу данных.");
|
|
Printer queryResult = await _context.Printers.Include(l => l.location).Include(m => m.model).FirstAsync(p => p.id == id);
|
|
|
|
//Printer? queryResult = await _context.Printers.FindAsync(id);
|
|
|
|
return queryResult;
|
|
}
|
|
}
|
|
}
|