Basit Nisar

Basit Nisar

  • 1.6k
  • 84
  • 10.8k

restrict data for type of users

Sep 15 2023 3:11 PM

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<ReleaseNoteModel>();

            }

            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

            },

            "

            }

        }

    ],

 


Answers (1)