本文整理汇总了C#中System.Security.Claims.ClaimsPrincipal.GetUserId方法的典型用法代码示例。如果您正苦于以下问题:C# ClaimsPrincipal.GetUserId方法的具体用法?C# ClaimsPrincipal.GetUserId怎么用?C# ClaimsPrincipal.GetUserId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Security.Claims.ClaimsPrincipal
的用法示例。
在下文中一共展示了ClaimsPrincipal.GetUserId方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetUserShop
public ShopViewModel GetUserShop(ClaimsPrincipal user)
{
return _dbContext.Shop
.Where(x => x.UserId == user.GetUserId())
.Select(x => new ShopViewModel()
{
ID = x.ID,
Address = x.Address,
City = x.City,
Name = x.Name,
ShortDesc = x.ShortDesc,
Website = x.Website,
Phone = x.Phone,
Latitude = x.Latitude,
Longitude = x.Longitude,
OpeningHours = x.OpeningHours.Where(y => y.ShopId == x.ID)
.Select(z => new OpeningHoursViewModel()
{
ID = z.ID,
ShopId = z.ShopId,
DayOfWeek = z.DayOfWeek,
DayOfWeekName = StringHelper.GetLocalizedDayOfWeekName(z.DayOfWeek),
IsClosed = z.IsClosed,
Opening1 = z.Opening1,
Opening2 = z.Opening2,
Closing1 = z.Closing1,
Closing2 = z.Closing2
}).ToList()
}).SingleOrDefault();
}
示例2: AddPuzzleAsync
public async Task AddPuzzleAsync(ClaimsPrincipal user, string puzzleImageId, int distance, int shopId)
{
Puzzle newPuzzle = new Puzzle();
newPuzzle.PuzzleImage = puzzleImageId;
newPuzzle.Distance = distance;
newPuzzle.InsertDate = DateTime.Now;
newPuzzle.InsertUserId = user.GetUserId();
newPuzzle.ShopId = shopId;
newPuzzle.Status = (int)EnumHelper.PuzzleStatus.ToApprove;
_dbContext.Puzzle.Add(newPuzzle);
await _dbContext.SaveChangesAsync();
}
示例3: GetPuzzles
public List<PuzzleListViewModel> GetPuzzles(ClaimsPrincipal user)
{
var query = _dbContext.Puzzle
.Where(x => x.InsertUserId == user.GetUserId() && x.Status != (int)EnumHelper.PuzzleStatus.Deleted)
.OrderByDescending(x => x.InsertDate)
.Select(x => new PuzzleListViewModel()
{
ID = x.ID,
InsertDate = x.InsertDate,
PuzzleImage = x.PuzzleImage,
StatusEnum = (EnumHelper.PuzzleStatus)x.Status,
StatusInfo = StringHelper.GetStatusInfo(x)
});
return query.ToList();
}
示例4: WithUserInfo
public static ActivityViewModel WithUserInfo(this ActivityViewModel viewModel, Activity activity, ClaimsPrincipal user, IAllReadyDataAccess dataAccess)
{
if (user.IsSignedIn())
{
var userId = user.GetUserId();
var appUser = dataAccess.GetUser(userId);
viewModel.UserId = userId;
viewModel.UserSkills = appUser?.AssociatedSkills?.Select(us => us.Skill).ToList();
viewModel.IsUserVolunteeredForActivity = dataAccess.GetActivitySignups(viewModel.Id, userId).Any();
var assignedTasks = activity.Tasks.Where(t => t.AssignedVolunteers.Any(au => au.User.Id == userId)).ToList();
viewModel.Tasks = new List<TaskViewModel>(assignedTasks.Select(data => new TaskViewModel(data, userId)).OrderBy(task => task.StartDateTime));
viewModel.SignupModel = new ActivitySignupViewModel()
{
ActivityId = viewModel.Id,
UserId = userId,
Name = appUser.Name,
PreferredEmail = appUser.Email,
PreferredPhoneNumber = appUser.PhoneNumber
};
}
else
{
viewModel.Tasks = new List<TaskViewModel>();
}
return viewModel;
}
示例5: For
public bool For(ClaimsPrincipal user, AllReadyTask task)
{
var userId = user.GetUserId();
if (user.IsUserType(UserType.SiteAdmin))
{
return true;
}
if (user.IsUserType(UserType.OrgAdmin))
{
//TODO: Modify to check that user is organization admin for organization of task
return true;
}
if (task.Event?.Organizer != null && task.Event.Organizer.Id == userId)
{
return true;
}
if (task.Event?.Campaign?.Organizer != null && task.Event.Campaign.Organizer.Id == userId)
{
return true;
}
return false;
}
示例6: UpdateShopAsync
public async Task UpdateShopAsync(ClaimsPrincipal user, ShopViewModel shopViewModel)
{
Shop shop = _dbContext.Shop.FirstOrDefault(x => x.UserId == user.GetUserId());
shop.Name = shopViewModel.Name;
shop.ShortDesc = shopViewModel.ShortDesc;
shop.City = shopViewModel.City;
shop.Address = shopViewModel.Address;
shop.Website = shopViewModel.Website;
shop.Phone = shopViewModel.Phone;
shop.Latitude = shopViewModel.Latitude;
shop.Longitude = shopViewModel.Longitude;
shop.InsertDate = DateTime.Now;
shop.InsertUserId = user.GetUserId();
shop.UserId = user.GetUserId();
_dbContext.Shop.Update(shop);
await _dbContext.SaveChangesAsync();
}
示例7: UserHasShopAsync
public async Task<bool> UserHasShopAsync(ClaimsPrincipal user)
{
return await Task.FromResult(_dbContext.Shop.Any(x => x.UserId == user.GetUserId()));
}
示例8: GetLoggedInUser
public static ChatUser GetLoggedInUser(this IJabbrRepository repository, ClaimsPrincipal principal)
{
return repository.GetUserById(principal.GetUserId());
}
示例9: CreateTeamAsync
public async Task<TeamResult> CreateTeamAsync(ClaimsPrincipal signedInUser, DataTransferObjects.Team team)
{
// Validate team
if (team == null)
{
throw new ArgumentNullException(nameof(team));
}
if (team.Roster == null)
{
throw new ArgumentNullException(nameof(team.Roster));
}
if (team.Roster.Count() < 5)
{
throw new InvalidOperationException("Teams must have at least 5 members.");
}
if (team.Owner == null)
{
throw new ArgumentNullException(nameof(team.Owner));
}
if (string.IsNullOrEmpty(team.Owner.Username))
{
throw new InvalidOperationException("Team owner invalid username");
}
if (string.IsNullOrEmpty(team.Name))
{
throw new ArgumentNullException(nameof(team.Name));
}
if (!Team.TeamNameRegex.IsMatch(team.Name))
{
throw new InvalidOperationException($"Team name {team.Name} is invalid");
}
// Make sure we have a default season
var season = await _seasonManager.GetCurrentSeasonAsync();
if (season == null)
{
throw new InvalidProgramException("Current season not found");
}
var entity = new Team { Name = team.Name, NormalizedName = team.Name.ToLower().Replace(' ', '-') };
// Create team roster
var roster = new List<TeamInvite>();
foreach (var invitee in team.Roster)
{
// Validate invitee
if (string.IsNullOrEmpty(invitee.Username) && string.IsNullOrEmpty(invitee.Tag))
{
throw new InvalidOperationException("Team roster invalid");
}
if (invitee.Username != team.Owner.Username)
{
Player player = null;
if (!string.IsNullOrEmpty(invitee.Username))
{
// If the player has a username, load the user
player = _db.Players
.Include(x => x.User)
.SingleOrDefault(x => x.User.UserName == invitee.Username);
if (player == null)
{
throw new InvalidProgramException($"Player entity for user {invitee.Username} not found.");
}
}
else
{
player = await _db.Players.FirstOrDefaultAsync(x => x.Tag == invitee.Tag);
}
if (player == null)
{
throw new InvalidProgramException($"Unable to find player");
}
var invite = new TeamInvite { Player = player, Team = entity };
roster.Add(invite);
}
}
// Create team owner
var ownerPlayer = _db.Players
.Include(x => x.User)
.SingleOrDefault(x => x.User.UserName == team.Owner.Username);
if (ownerPlayer == null)
{
throw new InvalidProgramException($"Player entity for owner {team.Owner.Username} not found.");
}
if (ownerPlayer.User.Id != signedInUser.GetUserId())
{
throw new InvalidOperationException($"Team owner must be currently signed in user.");
}
var teamOwner = new TeamOwner { Player = ownerPlayer, Team = entity };
// Begin transaction as this is where we begin save operations
var transaction = await _db.Database.BeginTransactionAsync();
var result = await _userManager.AddClaimAsync(ownerPlayer.User, new Claim($"{AuthorizationDefaults.ClaimTypeTeamOwner}:{entity.NormalizedName}", ownerPlayer.User.UserName));
//.........这里部分代码省略.........
示例10: AddShopAsync
public async Task AddShopAsync(ClaimsPrincipal user, ShopViewModel shopViewModel)
{
Shop shop = new Shop();
var addressData = new AddressData
{
Address = shopViewModel.Address,
City = shopViewModel.City.ToUpper(),
Country = "Italy"
};
var gls = new GoogleLocationService();
var latlong = gls.GetLatLongFromAddress(addressData);
var latitude = latlong.Latitude;
var longitude = latlong.Longitude;
shop.Name = shopViewModel.Name;
shop.ShortDesc = shopViewModel.ShortDesc;
shop.City = shopViewModel.City;
shop.Address = shopViewModel.Address;
shop.Website = shopViewModel.Website;
shop.Phone = shopViewModel.Phone;
shop.Latitude = latitude;
shop.Longitude = longitude;
shop.InsertDate = DateTime.Now;
shop.InsertUserId = user.GetUserId();
shop.UserId = user.GetUserId();
_dbContext.Shop.Add(shop);
await _dbContext.SaveChangesAsync();
}