initial commit
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
using Application.Common.CQS.Queries;
|
||||
using Application.Common.Extensions;
|
||||
using AutoMapper;
|
||||
using Domain.Entities;
|
||||
using Domain.Enums;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Application.Features.CampaignManager.Queries;
|
||||
|
||||
public record GetCampaignListDto
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? Number { get; init; }
|
||||
public string? Title { get; init; }
|
||||
public string? Description { get; init; }
|
||||
public double? TargetRevenueAmount { get; init; }
|
||||
public DateTime? CampaignDateStart { get; init; }
|
||||
public DateTime? CampaignDateFinish { get; init; }
|
||||
public CampaignStatus? Status { get; init; }
|
||||
public string? StatusName { get; init; }
|
||||
public string? SalesTeamId { get; init; }
|
||||
public string? SalesTeamName { get; init; }
|
||||
public DateTime? CreatedAtUtc { get; init; }
|
||||
}
|
||||
|
||||
public class GetCampaignListProfile : Profile
|
||||
{
|
||||
public GetCampaignListProfile()
|
||||
{
|
||||
CreateMap<Campaign, GetCampaignListDto>()
|
||||
.ForMember(
|
||||
dest => dest.StatusName,
|
||||
opt => opt.MapFrom(src => src.Status.HasValue ? src.Status.Value.ToFriendlyName() : string.Empty)
|
||||
)
|
||||
.ForMember(
|
||||
dest => dest.SalesTeamName,
|
||||
opt => opt.MapFrom(src => src.SalesTeam != null ? src.SalesTeam.Name : string.Empty)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public class GetCampaignListResult
|
||||
{
|
||||
public List<GetCampaignListDto>? Data { get; init; }
|
||||
}
|
||||
|
||||
public class GetCampaignListRequest : IRequest<GetCampaignListResult>
|
||||
{
|
||||
public bool IsDeleted { get; init; } = false;
|
||||
}
|
||||
|
||||
public class GetCampaignListHandler : IRequestHandler<GetCampaignListRequest, GetCampaignListResult>
|
||||
{
|
||||
private readonly IMapper _mapper;
|
||||
private readonly IQueryContext _context;
|
||||
|
||||
public GetCampaignListHandler(IMapper mapper, IQueryContext context)
|
||||
{
|
||||
_mapper = mapper;
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<GetCampaignListResult> Handle(GetCampaignListRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
var query = _context
|
||||
.Campaign
|
||||
.AsNoTracking()
|
||||
.IsDeletedEqualTo(request.IsDeleted)
|
||||
.Include(x => x.SalesTeam)
|
||||
.AsQueryable();
|
||||
|
||||
var entities = await query.ToListAsync(cancellationToken);
|
||||
|
||||
var dtos = _mapper.Map<List<GetCampaignListDto>>(entities);
|
||||
|
||||
return new GetCampaignListResult
|
||||
{
|
||||
Data = dtos
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
using Application.Common.CQS.Queries;
|
||||
using AutoMapper;
|
||||
using Domain.Entities;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Application.Features.CampaignManager.Queries;
|
||||
|
||||
public class GetCampaignSingleProfile : Profile
|
||||
{
|
||||
public GetCampaignSingleProfile()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class GetCampaignSingleResult
|
||||
{
|
||||
public Campaign? Data { get; init; }
|
||||
}
|
||||
|
||||
public class GetCampaignSingleRequest : IRequest<GetCampaignSingleResult>
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
}
|
||||
|
||||
public class GetCampaignSingleValidator : AbstractValidator<GetCampaignSingleRequest>
|
||||
{
|
||||
public GetCampaignSingleValidator()
|
||||
{
|
||||
RuleFor(x => x.Id).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class GetCampaignSingleHandler : IRequestHandler<GetCampaignSingleRequest, GetCampaignSingleResult>
|
||||
{
|
||||
private readonly IQueryContext _context;
|
||||
|
||||
public GetCampaignSingleHandler(
|
||||
IQueryContext context
|
||||
)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<GetCampaignSingleResult> Handle(GetCampaignSingleRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
var query = _context
|
||||
.Campaign
|
||||
.AsNoTracking()
|
||||
.Include(x => x.CampaignBudgetList.Where(budget => !budget.IsDeleted))
|
||||
.Include(x => x.CampaignExpenseList.Where(expense => !expense.IsDeleted))
|
||||
.Include(x => x.CampaignLeadList.Where(lead => !lead.IsDeleted))
|
||||
.Where(x => x.Id == request.Id)
|
||||
.AsQueryable();
|
||||
|
||||
var entity = await query.SingleOrDefaultAsync(cancellationToken);
|
||||
|
||||
return new GetCampaignSingleResult
|
||||
{
|
||||
Data = entity
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
using Application.Common.Extensions;
|
||||
using AutoMapper;
|
||||
using Domain.Enums;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.CampaignManager.Queries;
|
||||
|
||||
public record GetCampaignStatusListDto
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? Name { get; init; }
|
||||
}
|
||||
|
||||
public class GetCampaignStatusListProfile : Profile
|
||||
{
|
||||
public GetCampaignStatusListProfile()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class GetCampaignStatusListResult
|
||||
{
|
||||
public List<GetCampaignStatusListDto>? Data { get; init; }
|
||||
}
|
||||
|
||||
public class GetCampaignStatusListRequest : IRequest<GetCampaignStatusListResult>
|
||||
{
|
||||
}
|
||||
|
||||
public class GetCampaignStatusListHandler : IRequestHandler<GetCampaignStatusListRequest, GetCampaignStatusListResult>
|
||||
{
|
||||
public GetCampaignStatusListHandler()
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<GetCampaignStatusListResult> Handle(GetCampaignStatusListRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
var statuses = Enum.GetValues(typeof(CampaignStatus))
|
||||
.Cast<CampaignStatus>()
|
||||
.Select(status => new GetCampaignStatusListDto
|
||||
{
|
||||
Id = ((int)status).ToString(),
|
||||
Name = status.ToFriendlyName()
|
||||
})
|
||||
.ToList();
|
||||
|
||||
await Task.CompletedTask;
|
||||
|
||||
return new GetCampaignStatusListResult
|
||||
{
|
||||
Data = statuses
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user