Skip to content

Commit

Permalink
book borrowed returned tested
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyasbozdemir committed May 1, 2024
1 parent d451838 commit bd5166f
Show file tree
Hide file tree
Showing 9 changed files with 21,448 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class BorrowLend : BaseEntity<Guid>, IAuditable<Guid>
{
public Guid Id { get; set; }
public Guid WorkCatalogId { get; set; }
public Guid? WorkInventoryId { get; set; }
public Guid MemberId { get; set; }
public Guid StaffLenderId { get; set; }
public DateTime BorrowDate { get; set; }
Expand All @@ -26,6 +27,7 @@ public class BorrowLend : BaseEntity<Guid>, IAuditable<Guid>
public int? LateDurationInDays { get; set; }


public WorkInventory? WorkInventory { get; set; }
public WorkCatalog WorkCatalog { get; set; }
public Member Member { get; set; }
public Staff StaffLender { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ unix seconds olarak saklanacaktır sonra ki güncellemede.
public class Member : BaseEntity<Guid>, IAuditable<Guid>
{
public Guid UserId { get; set; }
public Guid? BorrowId { get; set; }
public DateTime MembershipDate { get; set; } // Üyelik Tarihi
public GenderType Gender { get; set; }
public string Occupation { get; set; } //Meslek
Expand All @@ -24,11 +25,10 @@ public class Member : BaseEntity<Guid>, IAuditable<Guid>
public bool IsExtensionAllowed { get; set; } // Uzatma izni
public int ExtensionDurationInDays { get; set; } // Uzatma süresi (gün cinsinden)

public Guid BorrowId { get; set; }
public Guid LibraryBranchId { get; set; }
public AppUser User { get; set; }


public virtual ICollection<LibraryBranch> LibraryBranches { get; set; }
public virtual ICollection<BorrowLend> Borrows { get; set; }
public virtual ICollection<BorrowLend>? Borrows { get; set; }
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
namespace LibraryTrackingApp.Domain.Entities.Library;


//bookstock tablosu kalkıcaktır. stokları teker teker aynı kitapta da verilen numaralar ile ayırarak burda da bunu girerek
// yapılcaktır stok adedi bu şekilde olucaktır.
public class WorkInventory : BaseEntity<Guid>, IAuditable<Guid>
{
public Guid Id { get; set; }
public Guid BookId { get; set; }
public Guid BorrowLendId { get; set; }
public Guid? BorrowLendId { get; set; }
public Guid EditionId { get; set; } // Eserin türü
public Guid? ShelfId { get; set; }
public Guid? BookCompartmentId { get; set; }
Expand All @@ -27,7 +25,7 @@ public class WorkInventory : BaseEntity<Guid>, IAuditable<Guid>

public ICollection<Edition> Editions { get; set; } // Baskılar

public virtual ICollection<BorrowLend> BorrowLends { get; set; }
public virtual ICollection<BorrowLend>? BorrowLends { get; set; }

public virtual WorkCompartment BookCompartment { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,19 @@ public void Configure(EntityTypeBuilder<BorrowLend> builder)
.HasConversion(new EnumToStringConverter<BorrowStatus>());


builder.HasOne(l => l.WorkCatalog)
.WithMany(b => b.Borrows)
.HasForeignKey(l => l.WorkCatalogId)
.IsRequired();

builder.HasOne(b => b.WorkCatalog)
.WithMany(b => b.Borrows)
.HasForeignKey(b => b.WorkCatalogId)
.OnDelete(DeleteBehavior.Restrict);



builder.HasOne(b => b.WorkInventory)
.WithMany(b => b.BorrowLends)
.HasForeignKey(b => b.WorkInventoryId)
.OnDelete(DeleteBehavior.Restrict);


builder.HasOne(b => b.Member)
.WithMany(m => m.Borrows)
.HasForeignKey(b => b.MemberId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,6 @@ public void Configure(EntityTypeBuilder<WorkCatalog> builder)

builder.Property(b => b.WorkFormat).HasConversion(new EnumToStringConverter<WorkFormat>());

// WorkCatalog - Borrows ilişkisi ... kalkıcak ...
builder
.HasMany(b => b.Borrows)
.WithOne(br => br.WorkCatalog)
.HasForeignKey(br => br.WorkCatalogId)
.OnDelete(DeleteBehavior.Cascade);

//WorkInventory ile olan ilişkiyi tanımlama bir katalogun birden fazla örneği olabilir.
builder
.HasMany(b => b.WorkInventories)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public static void Seed(ModelBuilder modelBuilder)


List<Shelf> shelves = new List<Shelf>();
List<WorkCompartment> bookCompartments = new List<WorkCompartment>();
List<WorkCompartment> workCompartments = new List<WorkCompartment>();

for (int i = 0; i < shelfCountPerLibrary; i++)
{
Expand Down Expand Up @@ -274,7 +274,7 @@ public static void Seed(ModelBuilder modelBuilder)
LastModifiedById = systemUser.Id,
};

bookCompartments.Add(compartment);
workCompartments.Add(compartment);
}
}

Expand Down Expand Up @@ -304,6 +304,7 @@ public static void Seed(ModelBuilder modelBuilder)
}

// Kitapları raf ve bölmelere dağıtma işlemi

int bookIndex = 0;


Expand All @@ -317,7 +318,7 @@ public static void Seed(ModelBuilder modelBuilder)
int compartmentIndex = ((bookSequence - 1) / compartmentCountPerBook) % compartmentCountPerShelf;

Guid shelfId = shelves[shelfIndex].Id;
Guid compartmentId = bookCompartments[compartmentIndex].Id;
Guid compartmentId = workCompartments[compartmentIndex].Id;


workInventory.ShelfId = shelfId;
Expand Down Expand Up @@ -678,14 +679,18 @@ public static void Seed(ModelBuilder modelBuilder)
};


//BorrowLend bunları da harryPotterBook ile değil bunun kopyası olan
// envantor entity'si ile ilişkilendirilcektir.

var hp5Inventory = workInventories.FirstOrDefault(item => item.BookNumber == "HP-5");
var hp10Inventory = workInventories.FirstOrDefault(item => item.BookNumber == "HP-10");
var hp15Inventory = workInventories.FirstOrDefault(item => item.BookNumber == "HP-15");


var borrow = new BorrowLend
{
Id = Guid.NewGuid(),
MemberId = member1.Id,
WorkCatalogId = harryPotterBook.Id,
WorkInventoryId = hp5Inventory.Id,
StaffLenderId = staff.Id,
BorrowDate = DateTime.Now - TimeSpan.FromDays(10),
BorrowStatus = BorrowStatus.Borrowed,
Expand All @@ -707,6 +712,7 @@ public static void Seed(ModelBuilder modelBuilder)
Id = Guid.NewGuid(),
MemberId = member2.Id,
WorkCatalogId = harryPotterBook.Id,
WorkInventoryId = hp10Inventory.Id,
StaffLenderId = staff.Id,
BorrowDate = DateTime.Now - TimeSpan.FromDays(10),
BorrowStatus = BorrowStatus.Borrowed,
Expand All @@ -723,6 +729,35 @@ public static void Seed(ModelBuilder modelBuilder)
borrow2.LateDurationInDays =
borrow2.IsLate == true ? (int?)(borrow2.ReturnDate - borrow2.DueDate)?.TotalDays : 0;



var borrow3 = new BorrowLend // iade edilmemiş olan için.
{
Id = Guid.NewGuid(),
MemberId = member2.Id,
WorkCatalogId = harryPotterBook.Id,
WorkInventoryId = hp15Inventory.Id,
StaffLenderId = staff.Id,
BorrowDate = DateTime.Now - TimeSpan.FromDays(10),
BorrowStatus = BorrowStatus.Borrowed,
CreatedById = systemUser.Id,
CreatedDateUnix = BaseEntity.ToUnixTimestamp(DateTime.Now),
LastModifiedById = systemUser.Id
};

borrow3.DueDate = DateTime.Now + TimeSpan.FromDays(1);

borrow3.IsLate = borrow3.ReturnDate > borrow3.DueDate;
borrow3.LateDurationInDays =
borrow3.IsLate == true ? (int?)(borrow3.ReturnDate - borrow3.DueDate)?.TotalDays : 0;








SeedEntities<AppRole>(modelBuilder, systemRole, adminRole, staffRole, memberRole);
SeedEntities<AppUser>(
modelBuilder,
Expand Down Expand Up @@ -756,14 +791,14 @@ public static void Seed(ModelBuilder modelBuilder)
SeedEntities<WorkCatalog>(modelBuilder, harryPotterBook);
SeedEntities<WorkTag>(modelBuilder, harryPotterTag1, harryPotterTag2, harryPotterTag3);
SeedEntities<Member>(modelBuilder, member1, member2);
SeedEntities<BorrowLend>(modelBuilder, borrow, borrow2);
SeedEntities<BorrowLend>(modelBuilder, borrow, borrow2, borrow3);
SeedEntities<Staff>(modelBuilder, staff);
SeedEntities<AuthorWorkCatalog>(modelBuilder, bookAuthor);


SeedEntities<WorkInventory>(modelBuilder, workInventories.ToArray());
SeedEntities<Shelf>(modelBuilder, shelves.ToArray());
SeedEntities<WorkCompartment>(modelBuilder, bookCompartments.ToArray());
SeedEntities<WorkCompartment>(modelBuilder, workCompartments.ToArray());
SeedEntities<EditionWorkInventory>(modelBuilder, editionWorkInventoryList.ToArray());

SeedEntities<WorkCatalogTag>(modelBuilder, bookTag1, bookTag2, bookTag3);
Expand Down
Loading

0 comments on commit bd5166f

Please sign in to comment.