using Fitness_core_BE.Interfaces; using Fitness_core_BE.Models; using Microsoft.EntityFrameworkCore; namespace Fitness_core_BE.Repos { public class AdminSuggestionRepository : IAdminSuggestionRepository { private readonly CentralDbContext _context; public AdminSuggestionRepository(CentralDbContext context) => _context = context; public async Task<(List Workouts, List Meals)> GetPublishedAsync(CancellationToken ct = default) => (await _context.WorkoutPlans.AsNoTracking().Include(x => x.WorkoutCategory).Include(x => x.WorkoutItems).Where(x => x.FKClientId == null && x.IsTemplate && x.IsActive).OrderByDescending(x => x.CreateDate).ToListAsync(ct), await _context.MealPlans.AsNoTracking().Include(x => x.MealCategory).Include(x => x.MealItems).Where(x => x.FKClientId == null && x.IsTemplate && x.IsActive).OrderByDescending(x => x.CreateDate).ToListAsync(ct)); public Task FindWorkoutCategoryAsync(string name, CancellationToken ct = default) => _context.WorkoutCategories.FirstOrDefaultAsync(x => x.WorkoutCategoryName == name, ct); public Task FindMealCategoryAsync(string name, CancellationToken ct = default) => _context.MealCategories.FirstOrDefaultAsync(x => x.Name == name, ct); public Task AddWorkoutCategoryAsync(WorkoutCategory category, CancellationToken ct = default) => _context.WorkoutCategories.AddAsync(category, ct).AsTask(); public Task AddMealCategoryAsync(MealCategory category, CancellationToken ct = default) => _context.MealCategories.AddAsync(category, ct).AsTask(); public Task AddWorkoutAsync(WorkoutPlan plan, CancellationToken ct = default) => _context.WorkoutPlans.AddAsync(plan, ct).AsTask(); public Task AddMealAsync(MealPlan plan, CancellationToken ct = default) => _context.MealPlans.AddAsync(plan, ct).AsTask(); } }