public async Task<ActionResult> ToggleSystemAccess(string userId, SystemAccessType accessType, bool isEnabled) { var currentUserId = User.Identity.GetUserId(); if (isEnabled) await systemAccessesRepo.GrantAccess(userId, accessType, currentUserId); else await systemAccessesRepo.RevokeAccess(userId, accessType); return Json(new { status = "ok" }); }
public async Task <List <SystemAccess> > RevokeAccessAsync(string userId, SystemAccessType accessType) { var accesses = await db.SystemAccesses.Where(a => a.UserId == userId && a.AccessType == accessType).ToListAsync().ConfigureAwait(false); foreach (var access in accesses) { access.IsEnabled = false; } await db.SaveChangesAsync().ConfigureAwait(false); return(accesses); }
public async Task <SystemAccess> GrantAccessAsync(string userId, SystemAccessType accessType, string grantedById) { var currentAccess = await db.SystemAccesses.FirstOrDefaultAsync(a => a.UserId == userId && a.AccessType == accessType).ConfigureAwait(false); if (currentAccess == null) { currentAccess = new SystemAccess { UserId = userId, AccessType = accessType, }; db.SystemAccesses.Add(currentAccess); } currentAccess.GrantedById = grantedById; currentAccess.GrantTime = DateTime.Now; currentAccess.IsEnabled = true; await db.SaveChangesAsync().ConfigureAwait(false); return(db.SystemAccesses.Include(a => a.GrantedBy).Single(a => a.Id == currentAccess.Id)); }
public Task <bool> HasSystemAccessAsync(string userId, SystemAccessType accessType) { return(db.SystemAccesses.AnyAsync(a => a.UserId == userId && a.AccessType == accessType && a.IsEnabled)); }
public static bool HasSystemAccess(this IPrincipal User, SystemAccessType accessType) { var systemAccessesRepo = new SystemAccessesRepo(); return(systemAccessesRepo.HasSystemAccess(User.Identity.GetUserId(), accessType)); }
public static bool HasSystemAccess(this ApplicationUser user, SystemAccessType accessType) { var systemAccessesRepo = new SystemAccessesRepo(); return(systemAccessesRepo.HasSystemAccess(user.Id, accessType)); }
public bool HasSystemAccess(string userId, SystemAccessType accessType) { return(db.SystemAccesses.Any(a => a.UserId == userId && a.AccessType == accessType && a.IsEnabled)); }