feat: add IsActive field to UserClubFeatures for admin management
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
using MediatR;
|
||||
|
||||
namespace CMSMicroservice.Application.ClubFeatureCQ.Commands.ToggleUserClubFeature;
|
||||
|
||||
/// <summary>
|
||||
/// کامند برای فعال/غیرفعال کردن یک ویژگی باشگاه برای کاربر
|
||||
/// </summary>
|
||||
public record ToggleUserClubFeatureCommand : IRequest<ToggleUserClubFeatureResponse>
|
||||
{
|
||||
/// <summary>
|
||||
/// شناسه کاربر
|
||||
/// </summary>
|
||||
public long UserId { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// شناسه ویژگی باشگاه
|
||||
/// </summary>
|
||||
public long ClubFeatureId { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// وضعیت مورد نظر (فعال/غیرفعال)
|
||||
/// </summary>
|
||||
public bool IsActive { get; init; }
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
using CMSMicroservice.Application.Common.Interfaces;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace CMSMicroservice.Application.ClubFeatureCQ.Commands.ToggleUserClubFeature;
|
||||
|
||||
/// <summary>
|
||||
/// هندلر برای فعال/غیرفعال کردن ویژگی باشگاه کاربر
|
||||
/// </summary>
|
||||
public class ToggleUserClubFeatureCommandHandler : IRequestHandler<ToggleUserClubFeatureCommand, ToggleUserClubFeatureResponse>
|
||||
{
|
||||
private readonly IApplicationDbContext _context;
|
||||
|
||||
public ToggleUserClubFeatureCommandHandler(IApplicationDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<ToggleUserClubFeatureResponse> Handle(ToggleUserClubFeatureCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
// بررسی وجود کاربر
|
||||
var userExists = await _context.Users
|
||||
.AnyAsync(u => u.Id == request.UserId && !u.IsDeleted, cancellationToken);
|
||||
|
||||
if (!userExists)
|
||||
{
|
||||
return new ToggleUserClubFeatureResponse
|
||||
{
|
||||
Success = false,
|
||||
Message = "کاربر یافت نشد"
|
||||
};
|
||||
}
|
||||
|
||||
// بررسی وجود ویژگی
|
||||
var featureExists = await _context.ClubFeatures
|
||||
.AnyAsync(cf => cf.Id == request.ClubFeatureId && !cf.IsDeleted, cancellationToken);
|
||||
|
||||
if (!featureExists)
|
||||
{
|
||||
return new ToggleUserClubFeatureResponse
|
||||
{
|
||||
Success = false,
|
||||
Message = "ویژگی باشگاه یافت نشد"
|
||||
};
|
||||
}
|
||||
|
||||
// یافتن رکورد UserClubFeature
|
||||
var userClubFeature = await _context.UserClubFeatures
|
||||
.FirstOrDefaultAsync(
|
||||
ucf => ucf.UserId == request.UserId
|
||||
&& ucf.ClubFeatureId == request.ClubFeatureId
|
||||
&& !ucf.IsDeleted,
|
||||
cancellationToken);
|
||||
|
||||
if (userClubFeature == null)
|
||||
{
|
||||
return new ToggleUserClubFeatureResponse
|
||||
{
|
||||
Success = false,
|
||||
Message = "این ویژگی برای کاربر یافت نشد"
|
||||
};
|
||||
}
|
||||
|
||||
// بهروزرسانی وضعیت
|
||||
userClubFeature.IsActive = request.IsActive;
|
||||
userClubFeature.LastModified = DateTime.UtcNow;
|
||||
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return new ToggleUserClubFeatureResponse
|
||||
{
|
||||
Success = true,
|
||||
Message = request.IsActive ? "ویژگی با موفقیت فعال شد" : "ویژگی با موفقیت غیرفعال شد",
|
||||
UserClubFeatureId = userClubFeature.Id,
|
||||
IsActive = userClubFeature.IsActive
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
namespace CMSMicroservice.Application.ClubFeatureCQ.Commands.ToggleUserClubFeature;
|
||||
|
||||
/// <summary>
|
||||
/// پاسخ کامند فعال/غیرفعال کردن ویژگی باشگاه
|
||||
/// </summary>
|
||||
public class ToggleUserClubFeatureResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// موفقیت عملیات
|
||||
/// </summary>
|
||||
public bool Success { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// پیام
|
||||
/// </summary>
|
||||
public string Message { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// شناسه رکورد UserClubFeature
|
||||
/// </summary>
|
||||
public long? UserClubFeatureId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// وضعیت جدید
|
||||
/// </summary>
|
||||
public bool? IsActive { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using MediatR;
|
||||
|
||||
namespace CMSMicroservice.Application.ClubFeatureCQ.Queries.GetUserClubFeatures;
|
||||
|
||||
/// <summary>
|
||||
/// دریافت لیست ویژگیهای باشگاه اختصاص یافته به کاربر
|
||||
/// </summary>
|
||||
public record GetUserClubFeaturesQuery : IRequest<List<UserClubFeatureDto>>
|
||||
{
|
||||
/// <summary>
|
||||
/// شناسه کاربر
|
||||
/// </summary>
|
||||
public long UserId { get; init; }
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
using CMSMicroservice.Application.Common.Interfaces;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace CMSMicroservice.Application.ClubFeatureCQ.Queries.GetUserClubFeatures;
|
||||
|
||||
/// <summary>
|
||||
/// هندلر برای دریافت لیست ویژگیهای باشگاه یک کاربر
|
||||
/// </summary>
|
||||
public class GetUserClubFeaturesQueryHandler : IRequestHandler<GetUserClubFeaturesQuery, List<UserClubFeatureDto>>
|
||||
{
|
||||
private readonly IApplicationDbContext _context;
|
||||
|
||||
public GetUserClubFeaturesQueryHandler(IApplicationDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<List<UserClubFeatureDto>> Handle(GetUserClubFeaturesQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var userClubFeatures = await _context.UserClubFeatures
|
||||
.Include(ucf => ucf.ClubFeature)
|
||||
.Where(ucf => ucf.UserId == request.UserId && !ucf.IsDeleted)
|
||||
.Select(ucf => new UserClubFeatureDto
|
||||
{
|
||||
Id = ucf.Id,
|
||||
UserId = ucf.UserId,
|
||||
ClubMembershipId = ucf.ClubMembershipId,
|
||||
ClubFeatureId = ucf.ClubFeatureId,
|
||||
FeatureTitle = ucf.ClubFeature.Title,
|
||||
FeatureDescription = ucf.ClubFeature.Description,
|
||||
IsActive = ucf.IsActive,
|
||||
GrantedAt = ucf.GrantedAt,
|
||||
Notes = ucf.Notes
|
||||
})
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
return userClubFeatures;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
namespace CMSMicroservice.Application.ClubFeatureCQ.Queries.GetUserClubFeatures;
|
||||
|
||||
/// <summary>
|
||||
/// DTO برای ویژگیهای باشگاه کاربر
|
||||
/// </summary>
|
||||
public class UserClubFeatureDto
|
||||
{
|
||||
/// <summary>
|
||||
/// شناسه رکورد UserClubFeature
|
||||
/// </summary>
|
||||
public long Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// شناسه کاربر
|
||||
/// </summary>
|
||||
public long UserId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// شناسه عضویت باشگاه
|
||||
/// </summary>
|
||||
public long ClubMembershipId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// شناسه ویژگی باشگاه
|
||||
/// </summary>
|
||||
public long ClubFeatureId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// عنوان ویژگی
|
||||
/// </summary>
|
||||
public string FeatureTitle { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// توضیحات ویژگی
|
||||
/// </summary>
|
||||
public string? FeatureDescription { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// وضعیت فعال/غیرفعال ویژگی برای این کاربر
|
||||
/// </summary>
|
||||
public bool IsActive { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// تاریخ اعطای ویژگی
|
||||
/// </summary>
|
||||
public DateTime GrantedAt { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// یادداشت
|
||||
/// </summary>
|
||||
public string? Notes { get; set; }
|
||||
}
|
||||
Reference in New Issue
Block a user