Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🍒 extend identityUser with a Tenant foreign key #604

Merged
merged 1 commit into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public Mapping()
{
CreateMap<ApplicationUser, ApplicationUserDto>(MemberList.None)
.ForMember(x => x.SuperiorName, s => s.MapFrom(y => y.Superior!.UserName))
.ForMember(x => x.TenantName, s => s.MapFrom(y => y.Tenant!.Name))
.ForMember(x => x.AssignedRoles, s => s.MapFrom(y => y.UserRoles.Select(r => r.Role.Name)));
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/Domain/Identity/ApplicationUser.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.ComponentModel.DataAnnotations.Schema;
Expand All @@ -18,6 +18,7 @@ public ApplicationUser()
public string? DisplayName { get; set; }
public string? Provider { get; set; } = "Local";
public string? TenantId { get; set; }
public virtual Tenant? Tenant { get; set; }
public string? TenantName { get; set; }

[Column(TypeName = "text")] public string? ProfilePictureDataUrl { get; set; }
Expand All @@ -32,6 +33,5 @@ public ApplicationUser()
public virtual ICollection<ApplicationUserToken> Tokens { get; set; }

public string? SuperiorId { get; set; } = null;

[ForeignKey("SuperiorId")] public ApplicationUser? Superior { get; set; } = null;
public ApplicationUser? Superior { get; set; } = null;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using CleanArchitecture.Blazor.Domain.Identity;
Expand All @@ -10,13 +10,6 @@ public class ApplicationUserConfiguration : IEntityTypeConfiguration<Application
{
public void Configure(EntityTypeBuilder<ApplicationUser> builder)
{
// Each User can have many UserClaims
// duplicate definition
//builder.HasMany(e => e.UserClaims)
// .WithOne()
// .HasForeignKey(uc => uc.UserId)
// .IsRequired();

// Each User can have many UserLogins
builder.HasMany(e => e.Logins)
.WithOne()
Expand All @@ -34,6 +27,10 @@ public void Configure(EntityTypeBuilder<ApplicationUser> builder)
.WithOne()
.HasForeignKey(ur => ur.UserId)
.IsRequired();

builder.HasOne(x => x.Superior).WithMany().HasForeignKey(u => u.SuperiorId);
builder.HasOne(x => x.Tenant).WithMany().HasForeignKey(u => u.TenantId);
builder.Navigation(e => e.Tenant).AutoInclude();
}
}

Expand Down
Loading
Loading