locked
I need to do in my controller a foreach of my table AspNetUserRoles RRS feed

  • Question

  • User1991482975 posted

    Hi,

    how to do a foreach of my table AspNetUserRoles ?

    i need to send one notification only to the admin users 

    in myAspNetRoles] table the Admin id is : 49eb03a9-05c6-4e33-9d04-a4ae99f84162

    i am lost ::

    //Notify the admins
                        var useradmin = db.USERROLE??? as IQueryable<????>;
                        useradmin = useradmin.Where(r => r.RoleId == "49eb03a9-05c6-4e33-9d04-a4ae99f84162");
                        foreach (var usertocontact in useradmin)
                        {
                           
    //Notifications
                    HairNotification hairnotification = new HairNotification();
                    hairnotification.UserId = usertocontact.UserId;
                    hairnotification.UserId2 = actualuser;
                    hairnotification.HairNotificationIdSource = cvannonce.CvAnnonceId;
                    hairnotification.HairNotificationType = "AnnonceApplied";
                    hairnotification.HairNotificationIpAdress = ipAddress;
                    hairnotification.HairNotificationDate = DateTime.Now;
                    hairnotification.HairNotificationWatched = false;
                    hairnotification.HairNotificationVisible = true;
                    hairnotification.HairNotificationDelete = false;
                    db.HairNotifications.Add(hairnotification);
                    db.SaveChanges();
    
                          
                        }

    Any help?

    Friday, January 15, 2021 9:03 AM

All replies

  • User-1545767719 posted

    Are you sure that you have enabled the Role management in your ASP.NET Identity and have assigned the Admin role to certain users? If not probably nobody knows the answer to your question. 

    Friday, January 15, 2021 9:14 AM
  • User1991482975 posted

    yes i did and i use the admin role to give access to some controllers..

    i though doing something like this but it does not work :

    var userforpartner = db.Users.Where(m => m.Roles.RoleId == "49eb03a9-05c6-4e33-9d04-a4ae99f84162" ).ToList();
                    foreach (var itemuserp in userforpartner)
                    {
                    //   
                   }  

    any suggestions?

    Friday, January 15, 2021 9:27 AM
  • User-1545767719 posted

    yes i did and i use the admin role to give access to some controllers..

    Take look at the AspNetRoles table in the database to confirm that there is a record for the role. If the name of role is "Admin" you will be able to find the record which Name field contains "Admin".

    Friday, January 15, 2021 9:47 AM