here i am sharing my c# code where we are using [LogedInID] and on the basis of this id I should show my response data that is if the [LogedInID] matches with Adjuster user then only adjuster object shows the response.
my c# code
{
ClaimsPrincipal principal = Request.GetRequestContext().Principal as ClaimsPrincipal;
Int32 LogedInID = Convert.ToInt32(principal.Claims.FirstOrDefault(t => t.Type == "LogedInID").Value);
ReleaseNoteViewModel ReleaseNote = new ReleaseNoteViewModel();
try
{
ReleaseNote.ReleaseNoteView = db.ReleaseVersions.AsNoTracking().Where(x => x.ReleaseVersionID == ID).OrderBy(x => x.ReleaseVersionName).Select(x => new ReleaseNoteModel
{
ReleaseVersionID = x.ReleaseVersionID,
ReleaseVersionName = x.ReleaseVersionName,
IsCurrentVersion = x.IsCurrentVersion,
Staff = db.UserLoginProfiles.Where(s => s.UserLoginProfileID == 3).Select(s => new ReleaseItemModel
{
Improvement = s.ReleaseNotes.Where(a=> a.ReleaseItemTypeID == 2 && a.ReleaseVersionID ==ID).OrderBy(a => a.ReleaseNoteDescription).Select(a => new ReleaseNotesModel
{
ReleaseNoteID = a.ReleaseNoteID,
ReleaseNoteHeader = a.ReleaseNoteHeader,
ReleaseNoteDescription = a.ReleaseNoteDescription,
}).ToList(),
Feature = s.ReleaseNotes.Where(a => a.ReleaseItemTypeID == 1 && a.ReleaseVersionID == ID).OrderBy(a => a.ReleaseNoteDescription).Select(p => new ReleaseNotesModel
{
ReleaseNoteID = p.ReleaseNoteID,
ReleaseNoteHeader = p.ReleaseNoteHeader,
ReleaseNoteDescription = p.ReleaseNoteDescription
}).ToList()
}).FirstOrDefault(),
Adjuster = db.UserLoginProfiles.Where(a => a.UserLoginProfileID == 2).Select(s => new ReleaseItemModel
{
Improvement = s.ReleaseNotes.Where(a => a.ReleaseItemTypeID == 2 && a.ReleaseVersionID == ID).OrderBy(a => a.ReleaseNoteDescription).Select(a => new ReleaseNotesModel
{
ReleaseNoteID = a.ReleaseNoteID,
ReleaseNoteHeader = a.ReleaseNoteHeader,
ReleaseNoteDescription = a.ReleaseNoteDescription
}).ToList(),
Feature = s.ReleaseNotes.Where(a => a.ReleaseItemTypeID == 1 && a.ReleaseVersionID == ID).OrderBy(a => a.ReleaseNoteDescription).Select(a => new ReleaseNotesModel
{
ReleaseNoteID = a.ReleaseNoteID,
ReleaseNoteHeader = a.ReleaseNoteHeader,
ReleaseNoteDescription = a.ReleaseNoteDescription
}).ToList()
}).FirstOrDefault(),
Client = db.UserLoginProfiles.Where(t => t.UserLoginProfileID == 1).Select(t => new ReleaseItemModel
{
Improvement = t.ReleaseNotes.Where(a => a.ReleaseItemTypeID == 2 && a.ReleaseVersionID == ID).OrderBy(a => a.ReleaseNoteDescription).Select(a => new ReleaseNotesModel
{
ReleaseNoteID = a.ReleaseNoteID,
ReleaseNoteHeader = a.ReleaseNoteHeader,
ReleaseNoteDescription = a.ReleaseNoteDescription
}
).ToList(),
Feature = t.ReleaseNotes.Where(a => a.ReleaseItemTypeID == 1 && a.ReleaseVersionID == ID).OrderBy(a => a.ReleaseNoteDescription).Select(a => new ReleaseNotesModel
{
ReleaseNoteID = a.ReleaseNoteID,
ReleaseNoteHeader = a.ReleaseNoteHeader,
ReleaseNoteDescription = a.ReleaseNoteDescription
}).ToList()
}).FirstOrDefault(),
}).ToList
}
catch (Exception ex)
{
Global.InsertException(ex);
}
return Ok(ReleaseNote);
}
my json response
"ReleaseNoteView": [
{
"ReleaseVersionID": 3,
"ReleaseVersionName": "v5.1.1",
"IsCurrentVersion": false,
"Staff": {
"Feature": [],
"Improvement": [
{
"ReleaseNoteID": 9,
"ReleaseNoteHeader": "CMS Profile Creation",
"ReleaseNoteDescription": "Adjuster’s CMS Profile and Branch Add to the CMS Profile automation will now go forward be triggered when assignment is added (instead of check-in approval)",
"ReleaseVersionID": null,
"ReleaseItemTypeID": null
},
{
"ReleaseNoteID": 10,
"ReleaseNoteHeader": "Commission Assignments",
"ReleaseNoteDescription": "An issue was resolved that was causing delays in the compensation for commission-based adjusters if/when billing was entered post-assignment dates. A grace period (35 days). Compensation is still done on a weekly basis – work needs to be input before Friday to be calculated in payroll.",
"ReleaseVersionID": null,
"ReleaseItemTypeID": null
},
{
"ReleaseNoteID": 11,
"ReleaseNoteHeader": "Admin",
"ReleaseNoteDescription": "Enhancements to the Expenses permission when accessed from adjuster profile.",
"ReleaseVersionID": null,
"ReleaseItemTypeID": null
}
],
"ReleaseNoteView": null
},
"Adjuster": {
"Feature": [],
"Improvement": [
{
"ReleaseNoteID": 8,
"ReleaseNoteHeader": "Profile",
"ReleaseNoteDescription": "Adjusters no longer have the capability to update address on Profile. Must contact Manager or Resource Team staff for any updates",
"ReleaseVersionID": null,
"ReleaseItemTypeID": null
}
],
"ReleaseNoteView": null
},
"Client": {
"Feature": [],
"Improvement": [],
"ReleaseNoteView": null
}
}
],
so i need to show the response if user is Adjuster then json response will be like
"ReleaseNoteView": [
{
"ReleaseVersionID": 3,
"ReleaseVersionName": "v5.1.1",
"IsCurrentVersion": false,
"Adjuster": {
"Feature": [],
"Improvement": [
{
"ReleaseNoteID": 8,
"ReleaseNoteHeader": "Profile",
"ReleaseNoteDescription": "Adjusters no longer have the capability to update address on Profile. Must contact Manager or Resource Team staff for any updates",
"ReleaseVersionID": null,
"ReleaseItemTypeID": null
}
],
"ReleaseNoteView": null
},
"
}
}
],
Prasad RaveendranPosted Sep 16, 2023, 11:53 AM
It seems you want to modify the JSON response based on the user's role. Specifically, if the user is an Adjuster, you want to filter out the Staff and Client sections from the response and only include the Adjuster section. To achieve this, you can conditionally create the JSON response based on the user's role before returning it.
Here's an example of how you can modify your code to achieve this:
In this code snippet, we introduced the GetUserRole method, which you should implement to retrieve the user's role. Depending on the user's role, the Adjuster section will be included or set to null in the JSON response. The Staff and Client sections are not included in the response for Adjusters.
Make sure to adapt the GetUserRole method to your authentication system and replace "Adjuster" with the actual role name that represents Adjusters in your application.
I hope, this may help you.