本文整理汇总了C#中Permission类的典型用法代码示例。如果您正苦于以下问题:C# Permission类的具体用法?C# Permission怎么用?C# Permission使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Permission类属于命名空间,在下文中一共展示了Permission类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Add
public ActionResult Add(IdentityRole model)
{
try
{
db.Roles.Add(model);
db.SaveChanges();
var Projectdb = new ProjectMvcDbContext();
foreach (var p in Projectdb.WebActions)
{
var perm = new Permission
{
Allow = false,
RoleId = model.Id,
WebActionId = p.Id
};
Projectdb.Permissions.Add(perm);
}
Projectdb.SaveChanges();
return RedirectToAction("Index");
}
catch (Exception Ex)
{
ModelState.AddModelError("", Ex.Message);
ViewBag.Role = db.Roles;
return View("Index", model);
}
}
示例2: CheckPermissionStatusAsync
/// <summary>
/// Determines whether this instance has permission the specified permission.
/// </summary>
/// <returns><c>true</c> if this instance has permission the specified permission; otherwise, <c>false</c>.</returns>
/// <param name="permission">Permission to check.</param>
public Task<PermissionStatus> CheckPermissionStatusAsync(Permission permission)
{
var names = GetManifestNames(permission);
//if isn't an android specific group then go ahead and return true;
if (names == null)
{
Debug.WriteLine("No android specific permissions needed for: " + permission);
return Task.FromResult(PermissionStatus.Granted);
}
//if no permissions were found then there is an issue and persmission is not set in Android manifest
if (names.Count == 0)
{
Debug.WriteLine("No permissions found in manifest for: " + permission);
return Task.FromResult(PermissionStatus.Unknown);
}
Context context = CrossCurrentActivity.Current.Activity ?? Application.Context;
if (context == null)
{
Debug.WriteLine("Unable to detect current Activity or App Context. Please ensure Plugin.CurrentActivity is installed in your Android project and your Application class is registering with Application.IActivityLifecycleCallbacks.");
return Task.FromResult(PermissionStatus.Unknown);
}
foreach (var name in names)
{
if (ContextCompat.CheckSelfPermission(context, name) == Android.Content.PM.Permission.Denied)
return Task.FromResult(PermissionStatus.Denied);
}
return Task.FromResult(PermissionStatus.Granted);
}
示例3: Page_Init
protected void Page_Init(object sender, EventArgs e)
{
ctx = new AriClinicContext("AriClinicContext");
// security control, it must be a user logged
if (Session["User"] == null)
Response.Redirect("Default.aspx");
else
{
user = CntAriCli.GetUser((Session["User"] as User).UserId, ctx);
Process proc = (from p in ctx.Processes
where p.Code == "professional"
select p).FirstOrDefault<Process>();
per = CntAriCli.GetPermission(user.UserGroup, proc, ctx);
btnAccept.Visible = per.Modify;
}
//
if (Request.QueryString["ProfessionalId"] != null)
{
professionalId = Int32.Parse(Request.QueryString["ProfessionalId"]);
prof = CntAriCli.GetProfessional(professionalId, ctx);
LoadData(prof);
}
else
{
LoadUserCombo(null);
LoadTypeCombo(null);
LoadTaxWithholdingTypeCombo(null);
}
}
示例4: GrantPermissionOperation
public GrantPermissionOperation(string table, string user, Permission permission)
: base(null)
{
Table = table;
User = user;
Permission = permission;
}
示例5: HasPermission
public bool HasPermission(Permission permission, HttpContextBase httpContext)
{
// get the list of roles that the user must have some overlap with to have the permission
HashSet<string> rolesRequired = _rolePermissions[permission];
foreach(var role in _allRoles)
{
if (httpContext.User.IsInRole(role) && rolesRequired.Contains(role))
{
return true;
}
}
// fallback for no roles -- give them at least Read Only status
bool userHasAtLeastOneRole = false;
foreach(var role in _allRoles)
{
if (httpContext.User.IsInRole(role))
{
userHasAtLeastOneRole = true;
break;
}
}
if (!userHasAtLeastOneRole)
{
if (rolesRequired.Contains(READ_ONLY_ROLE_NAME))
{
return true;
}
}
return false;
}
示例6: GetLimitIndex
static int GetLimitIndex( Rank rank, Permission permission ) {
if( rank.HasLimitSet( permission ) ) {
return rank.GetLimit( permission ).Index + 1;
} else {
return 0;
}
}
示例7: Remap
public Permission Remap(Permission permission)
{
if ((permission & From) == From)
return (permission ^ From) | To;
return permission;
}
示例8: Authorizes
public virtual bool Authorizes(IPrincipal user, ContentItem item, Permission permission)
{
if(item != null && permission == Permission.Read && !item.IsAuthorized(user))
return false;
return MapsTo(permission) && Contains(user);
}
示例9: GetRoles
/// <summary>Gets roles allowed for a certain permission stored in a content item.</summary>
/// <param name="item">The item whose permitted roles get.</param>
/// <param name="permission">The permission asked for.</param>
/// <returns>Permitted roles.</returns>
public static IEnumerable<string> GetRoles(ContentItem item, Permission permission)
{
List<string> roles = null;
foreach (Permission permissionLevel in SplitPermission(permission))
{
if(permissionLevel == Permission.Read)
{
foreach(AuthorizedRole role in item.AuthorizedRoles)
{
AddTo(ref roles, role.Role);
}
continue;
}
DetailCollection roleDetails = item.GetDetailCollection(AuthorizedRolesPrefix + permissionLevel, false);
if (roleDetails == null)
continue;
foreach(string role in roleDetails)
{
roles = AddTo(ref roles, role);
}
}
return roles;
}
示例10: Page_Init
protected void Page_Init(object sender, EventArgs e)
{
ctx = new AriClinicContext("AriClinicContext");
// security control, it must be a user logged
if (Session["User"] == null)
Response.Redirect("Default.aspx");
else
{
user = CntAriCli.GetUser((Session["User"] as User).UserId, ctx);
Process proc = (from p in ctx.Processes
where p.Code == "policy"
select p).FirstOrDefault<Process>();
per = CntAriCli.GetPermission(user.UserGroup, proc, ctx);
btnAccept.Visible = per.Modify;
}
//
if (Request.QueryString["CustomerId"] != null)
{
patientId = Int32.Parse(Request.QueryString["CustomerId"]);
pat = CntAriCli.GetCustomer(patientId, ctx);
txtCustomer.Text = pat.FullName;
}
//
if (Request.QueryString["PolicyId"] != null)
{
policyId = Int32.Parse(Request.QueryString["PolicyId"]);
pol = CntAriCli.GetPolicy(policyId, ctx);
LoadData(pol);
}
else
{
LoadTypeCombo(null);
LoadInsuranceCombo(null);
}
}
示例11: Page_Init
protected void Page_Init(object sender, EventArgs e)
{
ctx = new AriClinicContext("AriClinicContext");
// security control, it must be a user logged
if (Session["User"] == null)
Response.Redirect("Default.aspx");
else
{
user = (User)Session["User"];
user = CntAriCli.GetUser(user.UserId, ctx);
Process proc = (from p in ctx.Processes
where p.Code == "visitreason"
select p).FirstOrDefault<Process>();
per = CntAriCli.GetPermission(user.UserGroup, proc, ctx);
btnAccept.Visible = per.Modify;
}
//
if (Request.QueryString["VisitReasonId"] != null)
{
visitReasonId = Int32.Parse(Request.QueryString["VisitReasonId"]);
visitReason = CntAriCli.GetVisitReason(visitReasonId, ctx);
LoadData(visitReason);
}
}
示例12: Page_Init
protected void Page_Init(object sender, EventArgs e)
{
ctx = new AriClinicContext("AriClinicContext");
// security control, it must be a user logged
if (Session["User"] == null)
Response.Redirect("Default.aspx");
else
{
user = CntAriCli.GetUser((Session["User"] as User).UserId, ctx);
Process proc = (from p in ctx.Processes
where p.Code == "scat"
select p).FirstOrDefault<Process>();
per = CntAriCli.GetPermission(user.UserGroup, proc, ctx);
}
//cheks if is call from customer form tabs
if (type == "InTab")
{
HtmlControl tt = (HtmlControl)this.FindControl("TitleArea");
tt.Attributes["class"] = "ghost";
// hide patient column
RadGrid1.Columns.FindByDataField("Patient.FullName").Visible = false;
}
// cheks if is call from another form
if (Request.QueryString["Type"] != null)
type = Request.QueryString["Type"];
// translate filters
CntWeb.TranslateRadGridFilters(RadGrid1);
}
示例13: GrantPermission
/// <summary>
/// 为指定<see cref="IGrantee" />授予特定的<see cref="Permission" />。
/// 目前只支持被授权者为<see cref="GroupGrantee.AllUsers" />。
/// </summary>
/// <param name="grantee">被授权者。</param>
/// <param name="permission">被授予的权限。</param>
internal void GrantPermission(IGrantee grantee, Permission permission)
{
if (grantee == null)
throw new ArgumentNullException("grantee");
_grants.Add(new Grant(grantee, permission), true);
}
示例14: CanMapFullPermission
public void CanMapFullPermission(Permission expectedPermission)
{
var map = new PermissionMap { Permissions = Permission.Full, Roles = new[] { "rolename" } };
Assert.That(map.MapsTo(expectedPermission), Is.True);
Assert.That(map.Authorizes(user, item, expectedPermission), Is.True);
}
示例15: PermissionUnitTest
public PermissionUnitTest()
{
List<Permission> permList = Permission.index();
Assert.IsNotNull(permList);
Assert.IsTrue(permList.Count > 0);
testPermission = permList[0];
}