For Your Referance I have added the code
namespace Hon.IFS.SiteManagement.SiteRiskIndices
{
[RemoteService]
public abstract class SiteRiskIndexAppService : SiteManagementAppService ,ITransientDependency
{
#region Initialization and Constructor
private readonly RiskIndexManager _riskIndexManager;
private readonly IRiskIndexRepository _riskIndexRepository; // Add this field
public SiteRiskIndexAppService(IRiskIndexRepository riskIndexRepository, RiskIndexManager riskIndexManager) // Update constructor
{
_riskIndexManager = riskIndexManager;
_riskIndexRepository = riskIndexRepository; // Initialize the repository
}
#endregion
#region BUlK CREATE RISK INDICES
[Authorize(SiteManagementPermissions.RiskIndices.Create)]
public async Task<List<RiskIndexDto>> CreateBulkRiskIndicesAsync(Guid siteId, List<Guid> buildingIds)
{
var random = new Random();
var createdRiskIndices = new List<RiskIndexDto>();
foreach (var buildingId in buildingIds)
{
// Generate random values with 2 decimal places for each field
var communityRiskIndex = Math.Round(random.NextDouble() * 100, 2); // Define communityRiskIndex
var neighbourhoodRiskIndex = Math.Round(random.NextDouble() * 100, 2); // Define neighbourhoodRiskIndex
var buildingRiskIndex = Math.Round(random.NextDouble() * 100, 2);
var buildingRiskIndexPercentage = 20;
var historicalFireIncident = random.Next(0, 11); // Integer between 0-10
var historicalFireIncidentPercentage = 10;
var maintenance = Math.Round(random.NextDouble() * 100, 2);
var maintenancePercentage = 10;
var fireSupression = Math.Round(random.NextDouble() * 100, 2);
var fireSupressionPercentage = 10;
var fireService = Math.Round(random.NextDouble() * 100, 2);
var fireServicePercentage = Math.Round(random.NextDouble() * 100, 2);
var buildingOrg = Math.Round(random.NextDouble() * 100, 2);
var buildingOrgPercentage = 10;
var passiveFire = Math.Round(random.NextDouble() * 100, 2);
var passiveFirePercentage = 10;
var detection = Math.Round(random.NextDouble() * 100, 2);
var detectionPercentage = 10;
var ignition = Math.Round(random.NextDouble() * 100, 2);
var ignitionPercentage = 10; // Ensure ignitionPercentage is included
var riskIndexScore = (buildingRiskIndex * buildingRiskIndexPercentage)
+ (historicalFireIncident * historicalFireIncidentPercentage)
+ (maintenance * maintenancePercentage)
+ (fireSupression * fireSupressionPercentage)
+ (fireService * fireServicePercentage)
+ (buildingOrg * buildingOrgPercentage)
+ (passiveFire * passiveFirePercentage)
+ (detection * detectionPercentage)
+ (ignition * ignitionPercentage);
// Create risk index for the building
var riskIndex = await _riskIndexManager.CreateAsync(
siteId, buildingId,
(decimal)communityRiskIndex, (decimal)neighbourhoodRiskIndex, // Use the defined variables
(decimal)buildingRiskIndex, (decimal)buildingRiskIndexPercentage,
historicalFireIncident, (decimal)historicalFireIncidentPercentage,
(decimal)maintenance, (decimal)maintenancePercentage,
(decimal)fireSupression, (decimal)fireSupressionPercentage,
(decimal)fireService, (decimal)fireServicePercentage,
(decimal)buildingOrg, (decimal)buildingOrgPercentage,
(decimal)passiveFire, (decimal)passiveFirePercentage,
(decimal)detection, (decimal)detectionPercentage,
(decimal)ignition, (decimal)ignitionPercentage, // Pass ignitionPercentage here
(decimal)riskIndexScore
);
createdRiskIndices.Add(ObjectMapper.Map<RiskIndex, RiskIndexDto>(riskIndex));
}
return createdRiskIndices;
}
[Authorize(SiteManagementPermissions.RiskIndices.Default)]
public async Task<List<RiskIndexDto>> GetListBySiteAndBuildingsAsync(Guid siteId, List<Guid> buildingIds)
{
// Create a query to filter by siteId
var query = await _riskIndexRepository.GetQueryableAsync();
query = query.Where(ri => ri.SiteId == siteId);
// Further filter by buildingIds if provided
if (buildingIds != null && buildingIds.Any())
{
query = query.Where(ri => buildingIds.Contains(ri.BuildingId));
}
// Execute the query and retrieve the results
var items = await AsyncExecuter.ToListAsync(query);
// Map the results to DTOs and return
return ObjectMapper.Map<List<RiskIndex>, List<RiskIndexDto>>(items);
}
#endregion
}
}
12 Answer(s)
-
0
hi
Can you remove the
abstract
keyword?public class SiteRiskIndexAppService :
-
0
HI have Did that Still the issue is there
-
0
Where did you add this new app service? In your app or a module?
Thanks.
-
0
Module
-
0
If Possible, please provide Step by Step process to create the Custon Api in module Application it Helps
-
0
hi
In the module, there is an
HttpApi
layer.You should add a new controller that implements the
ISiteRiskIndexAppService
and addRoute
attributes.eg
IdentityUserController
andIIdentityUserAppService
https://github.com/abpframework/abp/blob/dev/modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/IdentityUserController.cs#L0-L1
-
0
I have added the controller HttpApi layer and facing Swagger error add a screen shot
namespace Hon.IFS.SiteManagement.SiteRiskIndices { [RemoteService(Name = SiteManagementRemoteServiceConsts.RemoteServiceName)] [Area(SiteManagementRemoteServiceConsts.ModuleName)] [ControllerName("SiteRiskIndex")] [Route("api/site-management/site-risk-indices")] [ApiController] public class SiteRiskIndexController : ISiteRiskIndexAppService { protected ISiteRiskIndexAppService _siteRiskIndexAppService; public SiteRiskIndexController(ISiteRiskIndexAppService siteRiskIndexAppService) { _siteRiskIndexAppService = siteRiskIndexAppService; } public async Task<List<RiskIndexDto>> CreateBulkRiskIndicesAsync(Guid siteId, List<Guid> buildingIds) { // Implementation logic for creating bulk risk indices // Replace the following line with actual implementation return await _siteRiskIndexAppService.CreateBulkRiskIndicesAsync( siteId, buildingIds); } public async Task<List<RiskIndexDto>> GetListBySiteAndBuildingsAsync(Guid siteId, List<Guid> buildingIds) { // Implementation logic for retrieving risk indices by site and buildings // Replace the following line with actual implementation return await _siteRiskIndexAppService.GetListBySiteAndBuildingsAsync(siteId, buildingIds); } } }
-
0
hi
Please share the logst.txt with liming.ma@volosoft.com
Thanks.
-
0
I have Sent Logs.txt to above Email Please Check.
-
0
hi
Ambiguous HTTP method for action - Hon.IFS.SiteManagement.SiteRiskIndices.SiteRiskIndexController.CreateBulkRiskIndicesAsync (Hon.IFS.SiteManagement.HttpApi). Actions require an explicit HttpMethod binding for Swagger/OpenAPI 3.0
Try adding
[HttpPost]
and[HttpGet]
attributes to your methods.namespace Hon.IFS.SiteManagement.SiteRiskIndices { [RemoteService(Name = SiteManagementRemoteServiceConsts.RemoteServiceName)] [Area(SiteManagementRemoteServiceConsts.ModuleName)] [ControllerName("SiteRiskIndex")] [Route("api/site-management/site-risk-indices")] [ApiController] public class SiteRiskIndexController : ISiteRiskIndexAppService { protected ISiteRiskIndexAppService _siteRiskIndexAppService; public SiteRiskIndexController(ISiteRiskIndexAppService siteRiskIndexAppService) { _siteRiskIndexAppService = siteRiskIndexAppService; } [HttpPost] public async Task<List<RiskIndexDto>> CreateBulkRiskIndicesAsync(Guid siteId, List<Guid> buildingIds) { // Implementation logic for creating bulk risk indices // Replace the following line with actual implementation return await _siteRiskIndexAppService.CreateBulkRiskIndicesAsync( siteId, buildingIds); } [HttpGet] public async Task<List<RiskIndexDto>> GetListBySiteAndBuildingsAsync(Guid siteId, List<Guid> buildingIds) { // Implementation logic for retrieving risk indices by site and buildings // Replace the following line with actual implementation return await _siteRiskIndexAppService.GetListBySiteAndBuildingsAsync(siteId, buildingIds); } } }
-
0
Thanks, Issue Resolved
-
0
Great 👍