Ashutosh_Subscription_Plan #131
@ -1,9 +1,12 @@
|
|||||||
using Marco.Pms.DataAccess.Data;
|
using AutoMapper;
|
||||||
|
using Marco.Pms.DataAccess.Data;
|
||||||
|
using Marco.Pms.Helpers.Utility;
|
||||||
using Marco.Pms.Model.Dtos.Util;
|
using Marco.Pms.Model.Dtos.Util;
|
||||||
using Marco.Pms.Model.Mapper;
|
using Marco.Pms.Model.Mapper;
|
||||||
using Marco.Pms.Model.Master;
|
using Marco.Pms.Model.Master;
|
||||||
|
using Marco.Pms.Model.TenantModels;
|
||||||
using Marco.Pms.Model.Utilities;
|
using Marco.Pms.Model.Utilities;
|
||||||
using MarcoBMS.Services.Helpers;
|
using Marco.Pms.Model.ViewModels.Tenant;
|
||||||
using MarcoBMS.Services.Service;
|
using MarcoBMS.Services.Service;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
@ -14,24 +17,30 @@ namespace Marco.Pms.Services.Controllers
|
|||||||
[ApiController]
|
[ApiController]
|
||||||
public class MarketController : ControllerBase
|
public class MarketController : ControllerBase
|
||||||
{
|
{
|
||||||
private readonly ApplicationDbContext _context;
|
private readonly IDbContextFactory<ApplicationDbContext> _dbContextFactory;
|
||||||
private readonly UserHelper _userHelper;
|
private readonly FeatureDetailsHelper _featureDetailsHelper;
|
||||||
|
private readonly IServiceScopeFactory _serviceScopeFactory;
|
||||||
private readonly IEmailSender _emailSender;
|
private readonly IEmailSender _emailSender;
|
||||||
private readonly IConfiguration _configuration;
|
private readonly IConfiguration _configuration;
|
||||||
public MarketController(ApplicationDbContext context, UserHelper userHelper, RefreshTokenService refreshTokenService,
|
public MarketController(IDbContextFactory<ApplicationDbContext> dbContextFactory,
|
||||||
IEmailSender emailSender, IConfiguration configuration, EmployeeHelper employeeHelper)
|
IServiceScopeFactory serviceScopeFactory,
|
||||||
|
IEmailSender emailSender,
|
||||||
|
IConfiguration configuration,
|
||||||
|
FeatureDetailsHelper featureDetailsHelper)
|
||||||
{
|
{
|
||||||
_context = context;
|
_dbContextFactory = dbContextFactory ?? throw new ArgumentNullException(nameof(dbContextFactory));
|
||||||
_userHelper = userHelper;
|
_serviceScopeFactory = serviceScopeFactory ?? throw new ArgumentNullException(nameof(serviceScopeFactory));
|
||||||
_emailSender = emailSender;
|
_emailSender = emailSender ?? throw new ArgumentNullException(nameof(emailSender));
|
||||||
_configuration = configuration;
|
_configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
|
||||||
|
_featureDetailsHelper = featureDetailsHelper ?? throw new ArgumentNullException(nameof(featureDetailsHelper));
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Route("industries")]
|
[Route("industries")]
|
||||||
public async Task<IActionResult> GetIndustries()
|
public async Task<IActionResult> GetIndustries()
|
||||||
{
|
{
|
||||||
var tenantId = _userHelper.GetTenantId();
|
await using var _context = await _dbContextFactory.CreateDbContextAsync();
|
||||||
|
|
||||||
var industries = await _context.Industries.ToListAsync();
|
var industries = await _context.Industries.ToListAsync();
|
||||||
|
|
||||||
return Ok(ApiResponse<object>.SuccessResponse(industries, "Success.", 200));
|
return Ok(ApiResponse<object>.SuccessResponse(industries, "Success.", 200));
|
||||||
@ -40,6 +49,8 @@ namespace Marco.Pms.Services.Controllers
|
|||||||
[HttpPost("enquire")]
|
[HttpPost("enquire")]
|
||||||
public async Task<IActionResult> RequestDemo([FromBody] InquiryDto inquiryDto)
|
public async Task<IActionResult> RequestDemo([FromBody] InquiryDto inquiryDto)
|
||||||
{
|
{
|
||||||
|
await using var _context = await _dbContextFactory.CreateDbContextAsync();
|
||||||
|
|
||||||
Inquiries inquiry = inquiryDto.ToInquiriesFromInquiriesDto();
|
Inquiries inquiry = inquiryDto.ToInquiriesFromInquiriesDto();
|
||||||
_context.Inquiries.Add(inquiry);
|
_context.Inquiries.Add(inquiry);
|
||||||
await _context.SaveChangesAsync();
|
await _context.SaveChangesAsync();
|
||||||
@ -58,5 +69,66 @@ namespace Marco.Pms.Services.Controllers
|
|||||||
}
|
}
|
||||||
return NotFound(ApiResponse<object>.ErrorResponse("Industry not found.", "Industry not found.", 404));
|
return NotFound(ApiResponse<object>.ErrorResponse("Industry not found.", "Industry not found.", 404));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpGet("list/subscription-plan")]
|
||||||
|
public async Task<IActionResult> GetSubscriptionPlanList([FromQuery] PLAN_FREQUENCY? frequency)
|
||||||
|
{
|
||||||
|
using var scope = _serviceScopeFactory.CreateScope();
|
||||||
|
|
||||||
|
var _logger = scope.ServiceProvider.GetRequiredService<ILoggingService>();
|
||||||
|
var _mapper = scope.ServiceProvider.GetRequiredService<IMapper>();
|
||||||
|
_logger.LogInfo("GetSubscriptionPlanList called with frequency: {Frequency}", frequency ?? PLAN_FREQUENCY.MONTHLY);
|
||||||
|
|
||||||
|
// Initialize the list to store subscription plan view models
|
||||||
|
List<SubscriptionPlanVM> detailsVM = new List<SubscriptionPlanVM>();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Create DbContext
|
||||||
|
await using var _context = await _dbContextFactory.CreateDbContextAsync();
|
||||||
|
|
||||||
|
// Load subscription plans with optional frequency filtering
|
||||||
|
IQueryable<SubscriptionPlanDetails> query = _context.SubscriptionPlanDetails.Include(sp => sp.Plan).Include(sp => sp.Currency);
|
||||||
|
|
||||||
|
if (frequency.HasValue)
|
||||||
|
{
|
||||||
|
query = query.Where(sp => sp.Frequency == frequency.Value);
|
||||||
|
_logger.LogInfo("Filtering subscription plans by frequency: {Frequency}", frequency);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_logger.LogInfo("Fetching all subscription plans without frequency filter");
|
||||||
|
}
|
||||||
|
|
||||||
|
var subscriptionPlans = await query.ToListAsync();
|
||||||
|
|
||||||
|
// Map and fetch feature details for each subscription plan
|
||||||
|
foreach (var subscriptionPlan in subscriptionPlans)
|
||||||
|
{
|
||||||
|
var response = _mapper.Map<SubscriptionPlanVM>(subscriptionPlan);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
response.Features = await _featureDetailsHelper.GetFeatureDetails(subscriptionPlan.FeaturesId);
|
||||||
|
}
|
||||||
|
catch (Exception exFeature)
|
||||||
|
{
|
||||||
|
_logger.LogError(exFeature, "Failed to fetch features for FeaturesId: {FeaturesId}", subscriptionPlan.FeaturesId);
|
||||||
|
response.Features = null; // or set to a default/fallback value
|
||||||
|
}
|
||||||
|
|
||||||
|
detailsVM.Add(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger.LogInfo("Successfully fetched {Count} subscription plans", detailsVM.Count);
|
||||||
|
|
||||||
|
return Ok(ApiResponse<object>.SuccessResponse(detailsVM, "List of plans fetched successfully", 200));
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Error occurred while fetching subscription plans");
|
||||||
|
return StatusCode(500, ApiResponse<object>.ErrorResponse("An error occurred while fetching subscription plans."));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user