Aşağıdaki metot sayesinde herhangi bir kayıdın belli bir takıma share olup olmaması bulunur.
public static bool Ishared(IOrganizationService service, string entityname, Guid entityid, string teamname)
{
var isReturn = false;
var accessResponse = RetrieveAndDisplayAccess(service, entityname, entityid);
if (accessResponse != null && accessResponse.PrincipalAccesses != null && accessResponse.PrincipalAccesses.Length != 0)
{
foreach (var principalAccess in accessResponse.PrincipalAccesses)
{
if (principalAccess.Principal.LogicalName.ToLower().Equals("team"))
{
Team team = (Team)service.Retrieve("team", principalAccess.Principal.Id, new ColumnSet("teamid", "name"));
if (team != null && team.Id != Guid.Empty)
{
if (team.Name.ToLower().Equals(teamname.ToLower()))
{
isReturn = true; break;
}
}
}
}
}
return isReturn;
}
public static RetrieveSharedPrincipalsAndAccessResponse RetrieveAndDisplayAccess(IOrganizationService service, string entityname, Guid entityid)
{
var accessRequest = new RetrieveSharedPrincipalsAndAccessRequest
{
Target = new EntityReference(entityname, entityid)
};
// The RetrieveSharedPrincipalsAndAccessResponse returns an entity reference
// that has a LogicalName of "user" when returning access information for a
// "team."
return (RetrieveSharedPrincipalsAndAccessResponse)service.Execute(accessRequest);
}
Metot Kullanımı
var isShared = Core.IsShared(serv, targetName, _targetId, team.Name);
if (!isShared)
{
// Bu takımla paylasılmamıs
}
Hiç yorum yok:
Yorum Gönder