Avalari
Avalari
CC#
Created by Avalari on 7/31/2023 in #help
❔ All properties in RegionInfo are populated with ISO code in Blazor
2 replies
CC#
Created by Avalari on 7/21/2023 in #help
✅ [DDD] Reference IdentityUser in Domain model class
Hi, I'm starting my jurney with DDD so please take it easy on me 😄 Any pointers on how to reference AppUser : IdentityUser (that's in Persistence layer) in a domain model class? I have some entities that have:
public int OwnerId { get; set; }
public virtual AppUser Owner { get; set; }
public int OwnerId { get; set; }
public virtual AppUser Owner { get; set; }
and I want to use .Include(u => u.Owner) when getting the data using EF Core. Problem is that AppUser : IdentityUser is defined in the Persistence layer, which Domain Layer has no access to, nor does it have the EF package. What would be the best approach to deal with this?
6 replies
CC#
Created by Avalari on 1/13/2023 in #help
❔ Claim type of JwtRegisteredClaimNames.Name unrecognized as ClaimTypes.Name
Hello, I'm working with an API that returns a token with below structure:
{
"sub": "someGuid",
"name": "TestUser#1501",
"jti": "someGuid",
"email": "[email protected]",
"http://schemas.microsoft.com/ws/2008/06/identity/claims/role": "User",
"exp": 1673632405,
"iss": "siteAPI",
"aud": "siteClient"
}
{
"sub": "someGuid",
"name": "TestUser#1501",
"jti": "someGuid",
"email": "[email protected]",
"http://schemas.microsoft.com/ws/2008/06/identity/claims/role": "User",
"exp": 1673632405,
"iss": "siteAPI",
"aud": "siteClient"
}
and using this:
public async Task LoggedIn()
{
var claims = await GetClaims();
var user = new ClaimsPrincipal(new ClaimsIdentity(claims, "jwt"));
var authState = Task.FromResult(new AuthenticationState(user));
NotifyAuthenticationStateChanged(authState);
}

private async Task<List<Claim>> GetClaims()
{
var savedToken = await _localStorage.GetItemAsync<string>(StorageConstants.Local.AuthToken);
var tokenContent = _jwtSecurityTokenHandler.ReadJwtToken(savedToken);
var claims = tokenContent.Claims.ToList();
return claims;
}
public async Task LoggedIn()
{
var claims = await GetClaims();
var user = new ClaimsPrincipal(new ClaimsIdentity(claims, "jwt"));
var authState = Task.FromResult(new AuthenticationState(user));
NotifyAuthenticationStateChanged(authState);
}

private async Task<List<Claim>> GetClaims()
{
var savedToken = await _localStorage.GetItemAsync<string>(StorageConstants.Local.AuthToken);
var tokenContent = _jwtSecurityTokenHandler.ReadJwtToken(savedToken);
var claims = tokenContent.Claims.ToList();
return claims;
}
When I try to access this.UserName = user.Identity.Name; it is always null. Am I doing something wrong here or is there a explicit conversion required?
3 replies
CC#
Created by Avalari on 11/4/2022 in #help
[Entity Framework] Issues with .Include()
Hi all! I have some issues trying to get data from my SQL Db. Having 3 models (Set, SetContent and Item):
public class Set
{
public int Id { get; set; }
public string Name { get; set; }
public string Code { get; set; }
public DateTime? ReleaseDate { get; set; }
public string Type { get; set; }
public string? Series { get; set; }
public string? Description { get; set; }

public ICollection<SetContent> Content { get; set; }
}

--------------------------

public class SetContent
{
public int Id { get; set; }
public int SetId { get; set; }
public string? SetCode { get; set; }
public string? SetRarity { get; set; }
public string? SetRarityCode { get; set; }
public int ItemId { get; set; }

public virtual Item Item { get; set; }
}

--------------------------

public class Item
{
public int Id { get; set; }
public string Name { get; set; }
public string Type { get; set; }
public string Desc { get; set; }
public string ImageBig { get; set; }
public string ImageSmall { get; set; }

public List<SetContent> Sets { get; set; } = new List<SetContent>();
}
public class Set
{
public int Id { get; set; }
public string Name { get; set; }
public string Code { get; set; }
public DateTime? ReleaseDate { get; set; }
public string Type { get; set; }
public string? Series { get; set; }
public string? Description { get; set; }

public ICollection<SetContent> Content { get; set; }
}

--------------------------

public class SetContent
{
public int Id { get; set; }
public int SetId { get; set; }
public string? SetCode { get; set; }
public string? SetRarity { get; set; }
public string? SetRarityCode { get; set; }
public int ItemId { get; set; }

public virtual Item Item { get; set; }
}

--------------------------

public class Item
{
public int Id { get; set; }
public string Name { get; set; }
public string Type { get; set; }
public string Desc { get; set; }
public string ImageBig { get; set; }
public string ImageSmall { get; set; }

public List<SetContent> Sets { get; set; } = new List<SetContent>();
}
I have 3 pages: - one to display all Sets - one to display Content of specific Set - one to display the specific Item details The issue that I have is with the third one. For the Item view page I would like to have a segment showing in what <Set> you can find it. So my question is how should I form the call in order to get something like Item with SetContent with Set (name and releaseDate):
{
"id": 0,
"name": "string",
"type": "string",
"desc": "string",
"imageBig": "string",
"imageSmall": "string",
"sets": [
{
"id": 0,
"setId": 0,
"setCode": "string",
"setRarity": "string",
"setRarityCode": "string",

"Name": "string",
"ReleaseDate": "DateTime"
}
]
}
{
"id": 0,
"name": "string",
"type": "string",
"desc": "string",
"imageBig": "string",
"imageSmall": "string",
"sets": [
{
"id": 0,
"setId": 0,
"setCode": "string",
"setRarity": "string",
"setRarityCode": "string",

"Name": "string",
"ReleaseDate": "DateTime"
}
]
}
28 replies