Skip to content

Commit

Permalink
[#24, #28] update link & fileItems user column (add, rename to Owner)
Browse files Browse the repository at this point in the history
  • Loading branch information
philipphoeninger committed Oct 29, 2024
1 parent ff94487 commit e7112cc
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ public void Configure(EntityTypeBuilder<FileItem> builder)
.HasConstraintName("FK_FileItems_Parents");
// TODO: parentId item isFolder=true constraint

//builder.HasIndex(f => new { f.Name, f.ParentId }, "IX_FileItems_Folder").IsUnique();
builder.HasOne(f => f.OwnerNavigation)
.WithMany(u => u.FileItems)
.HasForeignKey(f => f.Owner)
.IsRequired()
.OnDelete(DeleteBehavior.Restrict)
.HasConstraintName("FK_FileItems_User");

// temporal
builder.ToTable(b => b.IsTemporal(tb =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace MODELS.FileSharing.Entities.Configuration;
namespace MODELS.FileSharing.Entities.Configuration;

public class LinkConfiguration : IEntityTypeConfiguration<Link>
{
Expand All @@ -20,9 +20,9 @@ public void Configure(EntityTypeBuilder<Link> builder)
.OnDelete(DeleteBehavior.Cascade)
.HasConstraintName("FK_Links_FileItem");

builder.HasOne(l => l.UserNavigation)
builder.HasOne(l => l.OwnerNavigation)
.WithMany(u => u.Links)
.HasForeignKey(l => l.UserId)
.HasForeignKey(l => l.Owner)
.IsRequired()
.OnDelete(DeleteBehavior.Cascade)
.HasConstraintName("FK_Links_User");
Expand Down
9 changes: 8 additions & 1 deletion DAL/MODELS.FileSharing/Entities/FileItem.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace MODELS.FileSharing.Entities;
namespace MODELS.FileSharing.Entities;

[Table("FileItems", Schema = "dbo")]
[EntityTypeConfiguration(typeof(FileItemConfiguration))]
Expand Down Expand Up @@ -29,6 +29,13 @@ public partial class FileItem : BaseEntity
[InverseProperty(nameof(Link.FileItemNavigation))]
public virtual IEnumerable<Link> Links { get; set; } = new List<Link>();

[Required]
public string Owner { get; set; }

[ForeignKey(nameof(Owner))]
[InverseProperty(nameof(User.FileItems))]
public virtual User OwnerNavigation { get; set; }

private bool? _isFolder;
[DisplayName("Is Folder")]
public bool IsFolder
Expand Down
15 changes: 7 additions & 8 deletions DAL/MODELS.FileSharing/Entities/Link.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace MODELS.FileSharing.Entities;
namespace MODELS.FileSharing.Entities;

[Table("Links", Schema = "dbo")]
[EntityTypeConfiguration(typeof(LinkConfiguration))]
Expand Down Expand Up @@ -26,12 +26,11 @@ public partial class Link : BaseEntity
public DateTime LastChanged { get; set; }

[Required]
[DisplayName("Owner")]
public string UserId { get; set; }
public string Owner { get; set; }

[ForeignKey(nameof(UserId))]
[ForeignKey(nameof(Owner))]
[InverseProperty(nameof(User.Links))]
public virtual User UserNavigation { get; set; }
public virtual User OwnerNavigation { get; set; }

public bool IsActive { get; set; }

Expand All @@ -52,15 +51,15 @@ public Link(string pUrl, FileItem pFileItem, User pUser)
Url = pUrl;
FileItemId = pFileItem.Id;
FileItemNavigation = pFileItem;
UserId = pUser.Id;
UserNavigation = pUser;
Owner = pUser.Id;
OwnerNavigation = pUser;
}
#endregion

#region methods
public override string ToString()
{
return $"{Name} is a Link from {UserNavigation.UserName} with ID {Id}";
return $"{Name} is a Link from {OwnerNavigation.UserName} with ID {Id}";
}
#endregion
}
5 changes: 4 additions & 1 deletion DAL/MODELS.FileSharing/Entities/User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

public class User : IdentityUser
{
[InverseProperty(nameof(Link.UserNavigation))]
[InverseProperty(nameof(Link.OwnerNavigation))]
public virtual IEnumerable<Link> Links { get; set; } = new List<Link>();

[InverseProperty(nameof(FileItem.OwnerNavigation))]
public virtual IEnumerable<FileItem> FileItems { get; set; } = new List<FileItem>();
}

0 comments on commit e7112cc

Please sign in to comment.