|
|
@@ -2,6 +2,7 @@ using Common;
|
|
|
using Common.Constant;
|
|
|
using Common.Http;
|
|
|
using Common.Logic;
|
|
|
+using Esim.Apis.DTO.Content;
|
|
|
using Esim.Apis.Singleton;
|
|
|
using Database.Database;
|
|
|
using log4net;
|
|
|
@@ -330,5 +331,166 @@ namespace Esim.Apis.Business
|
|
|
);
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// Load device eSIM compatibility list
|
|
|
+ /// </summary>
|
|
|
+ public async Task<IActionResult> DeviceCompatibilityLoad(HttpRequest httpRequest, DeviceCompatibilityReq request)
|
|
|
+ {
|
|
|
+ var url = httpRequest.Path;
|
|
|
+ var json = JsonConvert.SerializeObject(request);
|
|
|
+ log.Debug("URL: " + url + " => Request: " + json);
|
|
|
+ try
|
|
|
+ {
|
|
|
+ string lang = CommonLogic.GetLanguage(httpRequest, request.lang);
|
|
|
+ int pageNumber = request.pageNumber < 0 ? 0 : request.pageNumber;
|
|
|
+ int pageSize = request.pageSize <= 0 ? 50 : request.pageSize;
|
|
|
+
|
|
|
+ // Base query - only active devices
|
|
|
+ var query = dbContext.DeviceEsimCompatibilities
|
|
|
+ .Where(d => d.Status == true && d.SupportsEsim == true);
|
|
|
+
|
|
|
+ // Filter by brand
|
|
|
+ if (!string.IsNullOrEmpty(request.brand))
|
|
|
+ {
|
|
|
+ query = query.Where(d => d.Brand == request.brand);
|
|
|
+ }
|
|
|
+
|
|
|
+ // Filter by category
|
|
|
+ if (!string.IsNullOrEmpty(request.category))
|
|
|
+ {
|
|
|
+ query = query.Where(d => d.Category == request.category);
|
|
|
+ }
|
|
|
+
|
|
|
+ // Filter by popular flag
|
|
|
+ if (request.isPopular.HasValue && request.isPopular.Value)
|
|
|
+ {
|
|
|
+ query = query.Where(d => d.IsPopular == true);
|
|
|
+ }
|
|
|
+
|
|
|
+ // Search by keyword in model name (all language variants)
|
|
|
+ if (!string.IsNullOrEmpty(request.searchKeyword))
|
|
|
+ {
|
|
|
+ var keyword = request.searchKeyword.ToLower();
|
|
|
+ query = query.Where(d =>
|
|
|
+ d.ModelName.ToLower().Contains(keyword) ||
|
|
|
+ (d.ModelNameEn != null && d.ModelNameEn.ToLower().Contains(keyword)) ||
|
|
|
+ (d.ModelNameLo != null && d.ModelNameLo.ToLower().Contains(keyword))
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ // Get total count for pagination
|
|
|
+ int totalCount = query.Count();
|
|
|
+ int totalPages = (int)Math.Ceiling((double)totalCount / pageSize);
|
|
|
+
|
|
|
+ // Apply pagination and ordering
|
|
|
+ var devices = query
|
|
|
+ .OrderBy(d => d.DisplayOrder)
|
|
|
+ .ThenBy(d => d.Brand)
|
|
|
+ .ThenBy(d => d.ModelName)
|
|
|
+ .Skip(pageNumber * pageSize)
|
|
|
+ .Take(pageSize)
|
|
|
+ .Select(d => new
|
|
|
+ {
|
|
|
+ d.Id,
|
|
|
+ d.Brand,
|
|
|
+ modelName = lang == "en"
|
|
|
+ ? (d.ModelNameEn ?? d.ModelName)
|
|
|
+ : (d.ModelNameLo ?? d.ModelName),
|
|
|
+ d.Category,
|
|
|
+ notes = lang == "en"
|
|
|
+ ? (d.NotesEn ?? d.Notes)
|
|
|
+ : (d.NotesLo ?? d.Notes),
|
|
|
+ supportsEsim = d.SupportsEsim ?? true,
|
|
|
+ isPopular = d.IsPopular ?? false,
|
|
|
+ displayOrder = d.DisplayOrder ?? 999
|
|
|
+ })
|
|
|
+ .ToList();
|
|
|
+
|
|
|
+ return ApiResponseHelper.BuildResponse(
|
|
|
+ log, url, json,
|
|
|
+ CommonErrorCode.Success,
|
|
|
+ ConfigManager.Instance.GetConfigWebValue("LOAD_SUCCESS", lang),
|
|
|
+ new
|
|
|
+ {
|
|
|
+ devices = devices,
|
|
|
+ pagination = new
|
|
|
+ {
|
|
|
+ pageNumber,
|
|
|
+ pageSize,
|
|
|
+ totalCount,
|
|
|
+ totalPages
|
|
|
+ }
|
|
|
+ }
|
|
|
+ );
|
|
|
+ }
|
|
|
+ catch (Exception exception)
|
|
|
+ {
|
|
|
+ log.Error("Exception: ", exception);
|
|
|
+ }
|
|
|
+ return ApiResponseHelper.BuildResponse(
|
|
|
+ log, url, json,
|
|
|
+ CommonErrorCode.SystemError,
|
|
|
+ ConfigManager.Instance.GetConfigWebValue("SYSTEM_FAILURE"),
|
|
|
+ new { }
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Get list of device brands and categories (for filters/tabs)
|
|
|
+ /// </summary>
|
|
|
+ public async Task<IActionResult> GetDeviceBrandsAndCategories(HttpRequest httpRequest)
|
|
|
+ {
|
|
|
+ var url = httpRequest.Path;
|
|
|
+ log.Debug("URL: " + url);
|
|
|
+ try
|
|
|
+ {
|
|
|
+ // Get distinct brands with device count
|
|
|
+ var brands = dbContext.DeviceEsimCompatibilities
|
|
|
+ .Where(d => d.Status == true && d.SupportsEsim == true)
|
|
|
+ .GroupBy(d => d.Brand)
|
|
|
+ .Select(g => new
|
|
|
+ {
|
|
|
+ brand = g.Key,
|
|
|
+ deviceCount = g.Count(),
|
|
|
+ popularCount = g.Count(d => d.IsPopular == true)
|
|
|
+ })
|
|
|
+ .OrderBy(b => b.brand)
|
|
|
+ .ToList();
|
|
|
+
|
|
|
+ // Get distinct categories with device count
|
|
|
+ var categories = dbContext.DeviceEsimCompatibilities
|
|
|
+ .Where(d => d.Status == true && d.SupportsEsim == true)
|
|
|
+ .GroupBy(d => d.Category)
|
|
|
+ .Select(g => new
|
|
|
+ {
|
|
|
+ category = g.Key,
|
|
|
+ deviceCount = g.Count()
|
|
|
+ })
|
|
|
+ .OrderBy(c => c.category)
|
|
|
+ .ToList();
|
|
|
+
|
|
|
+ return ApiResponseHelper.BuildResponse(
|
|
|
+ log, url, "",
|
|
|
+ CommonErrorCode.Success,
|
|
|
+ ConfigManager.Instance.GetConfigWebValue("LOAD_SUCCESS"),
|
|
|
+ new
|
|
|
+ {
|
|
|
+ brands = brands,
|
|
|
+ categories = categories
|
|
|
+ }
|
|
|
+ );
|
|
|
+ }
|
|
|
+ catch (Exception exception)
|
|
|
+ {
|
|
|
+ log.Error("Exception: ", exception);
|
|
|
+ }
|
|
|
+ return ApiResponseHelper.BuildResponse(
|
|
|
+ log, url, "",
|
|
|
+ CommonErrorCode.SystemError,
|
|
|
+ ConfigManager.Instance.GetConfigWebValue("SYSTEM_FAILURE"),
|
|
|
+ new { }
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
}
|