public IActionResult GetScope(string access_token) { var scope = tokenGenerator.DecodeToken(access_token).Claims.First(x => x.Type == "scope").Value; var username = tokenGenerator.DecodeToken(access_token).Claims.First(x => x.Type == "_unid").Value; return(Ok(new { scope, username })); }
public async Task <UserAdvertiseDTO> Handle(Query request, CancellationToken cancellationToken) { var ad = await RunAdvertiseQuery(request).AsNoTracking().FirstOrDefaultAsync(); if (ad is null) { throw new HttpContextException(System.Net.HttpStatusCode.NotFound, new { Advertise = "Advertise is not found" }); } var token = contextAccessor.HttpContext.Request.Cookies["_aid"]; if (token is null) { return(ad); } var userId = tokenGenerator.DecodeToken(token).Claims.FirstOrDefault(x => x.Type == "_cuser").Value; var userFav = await dataContext.UserFavorites.AsNoTracking() .FirstOrDefaultAsync(x => x.Advertise.UniqueId == ad.Root.AdvertiseDTO.UniqueId && x.AppUserId == userId); ad.Root.IsFavorite = userFav is not null ? true : false; var userLike = await dataContext.UserLikes.AsNoTracking() .FirstOrDefaultAsync(x => x.Advertise.UniqueId == ad.Root.AdvertiseDTO.UniqueId && x.AppUserId == userId); ad.Root.IsLiked = userLike is not null ? true : false; var likesCount = await dataContext.UserLikes.Where(x => x.Advertise.UniqueId == request.Id).AsNoTracking().CountAsync(); ad.Root.Likes = likesCount; return(ad); }