48 lines
1.6 KiB
C#
48 lines
1.6 KiB
C#
using Back.Data.Contracts;
|
|
using Back.Data.Models;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Shared.DTOs;
|
|
|
|
namespace Back.Services
|
|
{
|
|
|
|
|
|
public class ServPromotion
|
|
{
|
|
private readonly IAsyncRepository<Promotion> _repoPromotion;
|
|
private readonly IAsyncRepository<PromotionDetails> _repoPromotionDetails;
|
|
|
|
|
|
public ServPromotion(IAsyncRepository<Promotion> repoPromotion, IAsyncRepository<PromotionDetails> repoPromotionDetails)
|
|
{
|
|
_repoPromotion = repoPromotion;
|
|
_repoPromotionDetails = repoPromotionDetails;
|
|
|
|
}
|
|
public async Task<List<PromotionDto>> GetAll()
|
|
{
|
|
return await _repoPromotion.Get(w => w.Status)
|
|
.Include(inc => inc.PromotionDetails).ThenInclude(tinc => tinc.Permission)
|
|
.Select(s => new PromotionDto
|
|
{
|
|
ID = s.ID,
|
|
Name = s.Name,
|
|
promotionDetails = s.PromotionDetails.Select(s => new PromotionDetailDto
|
|
{
|
|
ID = s.ID,
|
|
APrice = s.APrice,
|
|
CreditAmount = s.CreditAmount,
|
|
PermissionID = s.PermissionID,
|
|
PermissionTitle = s.Permission.Title
|
|
}).ToList()
|
|
}).ToListAsync();
|
|
}
|
|
public async Task<Promotion> GetByPromotionID(int PromotionID)
|
|
{
|
|
return await _repoPromotion.Get(w => w.Status && w.ID == PromotionID)
|
|
.Include(inc => inc.PromotionDetails).ThenInclude(tinc => tinc.Permission)
|
|
.FirstOrDefaultAsync();
|
|
}
|
|
}
|
|
}
|