QrRapido/Services/PlanService.cs
2025-07-29 19:11:47 -03:00

36 lines
1.0 KiB
C#

using MongoDB.Driver;
using QRRapidoApp.Data;
using QRRapidoApp.Models;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace QRRapidoApp.Services
{
public class PlanService : IPlanService
{
private readonly IMongoCollection<Plan> _plans;
public PlanService(MongoDbContext context)
{
_plans = context.Plans;
}
public async Task<List<Plan>> GetActivePlansAsync()
{
return await _plans.Find(p => p.IsActive).SortBy(p => p.PricesByCountry["BRL"].Amount).ToListAsync();
}
public async Task<List<Plan>> GetPlansByLanguageAsync(string languageCode, string countryCode = "BRL")
{
var plans = await _plans.Find(p => p.IsActive).SortBy(p => p.PricesByCountry[countryCode].Amount).ToListAsync();
return plans;
}
public async Task<Plan?> GetPlanByIdAsync(string id)
{
return await _plans.Find(p => p.Id == id).FirstOrDefaultAsync();
}
}
}