62 lines
1.7 KiB
C#
62 lines
1.7 KiB
C#
using Hospitality.Backend.DTOs;
|
|
using Hospitality.Infrastructure.Data;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace Hospitality.Backend.Services;
|
|
|
|
public class QrCodeService : IQrCodeService
|
|
{
|
|
private readonly HospitalityDbContext _context;
|
|
|
|
public QrCodeService(HospitalityDbContext context)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
public async Task<PersonDetailResponse?> GetPersonByQrCodeAsync(Guid qrCode)
|
|
{
|
|
var person = await _context.People
|
|
.Include(p => p.Quotas)
|
|
.ThenInclude(q => q.Product)
|
|
.FirstOrDefaultAsync(p => p.QrCode == qrCode);
|
|
|
|
if (person == null) return null;
|
|
|
|
return new PersonDetailResponse(
|
|
person.Id,
|
|
person.GroupId,
|
|
person.QrCode,
|
|
person.Name,
|
|
person.Email,
|
|
person.PhoneNumber,
|
|
person.Quotas.Select(q => new QuotaResponse(
|
|
q.ProductId,
|
|
q.Product.Name,
|
|
q.Product.Type.ToString(),
|
|
q.InitialAmount,
|
|
q.UsedAmount,
|
|
q.RemainingAmount
|
|
)).ToList()
|
|
);
|
|
}
|
|
|
|
public async Task<IEnumerable<QuotaResponse>> GetQuotasByQrCodeAsync(Guid qrCode)
|
|
{
|
|
var quotas = await _context.PersonQuotas
|
|
.Include(q => q.Product)
|
|
.Include(q => q.Person)
|
|
.Where(q => q.Person.QrCode == qrCode)
|
|
.Select(q => new QuotaResponse(
|
|
q.ProductId,
|
|
q.Product.Name,
|
|
q.Product.Type.ToString(),
|
|
q.InitialAmount,
|
|
q.UsedAmount,
|
|
q.RemainingAmount
|
|
))
|
|
.ToListAsync();
|
|
|
|
return quotas;
|
|
}
|
|
}
|