Esempio n. 1
0
        private bool DoGrant(string roleId, string[] resourceId)
        {
            //var rows = db.ResourcesInRole.Where(x => x.RoleId == Guid.Parse(roleId));
            //db.ResourcesInRole.DeleteAllOnSubmit(rows);
            //db.SubmitChanges();

            foreach (var item in resourceId)
            {
                if (!string.IsNullOrEmpty(item))
                {
                    var guidRoleId = Guid.Parse(roleId);
                    var intItem    = int.Parse(item);
                    var row        = (from x in swdb.ResourcesInRole where x.RoleId == guidRoleId && x.ResourceId == intItem select x);
                    if (row.Count() > 0)
                    {
                        //var newrow = row.FirstOrDefault();
                        //newrow.RoleId = Guid.Parse(roleId),
                        //    newrow.ResourceId =
                    }
                    else
                    {
                        ResourcesInRole newrow = new ResourcesInRole
                        {
                            RoleId     = guidRoleId,
                            ResourceId = int.Parse(item)
                        };
                        swdb.ResourcesInRole.Add(newrow);
                    }
                }
            }
            swdb.SaveChanges();
            return(true);
        }
Esempio n. 2
0
 private bool DoRevoke(string roleId, string[] resourceId)
 {
     foreach (var item in resourceId)
     {
         if (!string.IsNullOrEmpty(item))
         {
             var             guidRoleId = Guid.Parse(roleId);
             var             intItem    = int.Parse(item);
             ResourcesInRole rows       = swdb.ResourcesInRole.Where(x => x.RoleId == guidRoleId && x.ResourceId == intItem).FirstOrDefault();
             swdb.ResourcesInRole.Remove(rows);
         }
     }
     swdb.SaveChanges();
     return(true);
 }