mirror of
https://gitlab.com/Hukuta47/cartrix.git
synced 2026-12-05 20:40:55 +00:00
Подлатал API и Web
This commit is contained in:
1 parent
ae561f8311
commit
34868984fb
26 files changed
+435
-104
No files matched your search
@@ -0,0 +1,22 @@
|
||||
using CartriX.Api.Interfaces;
|
||||
using CartriX.Shared.Classes;
|
||||
using CartriX.Shared.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Migrations.Operations;
|
||||
|
||||
namespace CartriX.Api.Services
|
||||
{
|
||||
public class LocationService : ILocationService
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
public LocationService(AppDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
public async Task<List<Location>> GetAll()
|
||||
{
|
||||
var query = await _context.Locations.Include(l => l.printers).ToListAsync();
|
||||
return query;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,6 @@ using System.Net.Sockets;
|
||||
using CartriX.Shared.DTOs.Printer;
|
||||
using Lextm.SharpSnmpLib;
|
||||
using Lextm.SharpSnmpLib.Messaging;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Internal;
|
||||
|
||||
namespace CartriX.Api.Services
|
||||
{
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
using CartriX.Shared.Classes;
|
||||
using CartriX.Shared.Mappers;
|
||||
using CartriX.Shared.DTOs.Printer;
|
||||
using CartriX.Shared.Interfaces;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using CartriX.Shared.Models;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user