NonInventPurchasingSystem/CPRNIMS.Infrastructure/Database/NonInventoryDbContext.cs
2026-06-18 16:51:31 +08:00

326 lines
14 KiB
C#

using CPRNIMS.Infrastructure.Dto.Canvass.Response;
using CPRNIMS.Infrastructure.Dto.Inventory.Response;
using CPRNIMS.Infrastructure.Entities.Account;
using CPRNIMS.Infrastructure.Entities.Canvass;
using CPRNIMS.Infrastructure.Entities.Common;
using CPRNIMS.Infrastructure.Entities.Finance;
using CPRNIMS.Infrastructure.Entities.Inventory;
using CPRNIMS.Infrastructure.Entities.Items;
using CPRNIMS.Infrastructure.Entities.PO;
using CPRNIMS.Infrastructure.Entities.Purchasing;
using CPRNIMS.Infrastructure.Entities.SMTP;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CPRNIMS.Infrastructure.Database
{
public class NonInventoryDbContext : IdentityDbContext<ApplicationUser>
{
public NonInventoryDbContext(DbContextOptions<NonInventoryDbContext> options) : base(options) { }
#region Common
public DbSet<Departments> Departments { get; set; }
public DbSet<IdentityRole> IdentityRoles { get; set; }
public DbSet<AuthorizeRoles> AuthorizeRoles { get; set; }
public DbSet<UserRights> UserRights { get; set; }
public DbSet<IdentityUserRole<string>> IdentityUserRoles { get; set; }
public DbSet<ForgotPassword> ForgotPasswords { get; set; }
public virtual DbSet<Otps> Otps { get; set; }
public virtual DbSet<ErrorMessage> ErrorMessages { get; set; }
public virtual DbSet<ControllerAccess> ControllerAccess { get; set; }
public virtual DbSet<SMTPCredential> SMTPCredentials { get; set; }
#endregion
#region Item
public virtual DbSet<ItemCode> ItemCodes { get; set; }
public virtual DbSet<ItemList> ItemList { get; set; }
public virtual DbSet<Item> Items { get; set; }
public DbSet<Attachment> Attachments { get; set; }
public virtual DbSet<AttachmentExtension> AttachmentExtensions { get; set; }
public virtual DbSet<AttachmentFileType> AttachmentFileTypes { get; set; }
public virtual DbSet<ItemAttachement> ItemAttachements { get; set; }
public virtual DbSet<ItemCategory> ItemCategories { get; set; }
public virtual DbSet<UnitOfMessure> UnitOfMessures { get; set; }
public virtual DbSet<ItemColor> ItemColors { get; set; }
public virtual DbSet<ItemLocalization> ItemLocalizations { get; set; }
public virtual DbSet<ItemCart> ItemCarts { get; set; }
public virtual DbSet<ItemApproval> ItemApprovals { get; set; }
public virtual DbSet<Entities.Inventory.ItemDetail> ItemDetails { get; set; }
#endregion
#region PR
public virtual DbSet<PR> PRs { get; set; }
public virtual DbSet<Approved> Approved { get; set; }
public virtual DbSet<ApprovedPR> ApprovedPrs { get; set; }
public virtual DbSet<DeletedPR> DeletedPRs { get; set; }
public virtual DbSet<PRDetails> PRDetails { get; set; }
public virtual DbSet<PRItemList> PRItemLists { get; set; }
public DbSet<PRAttachments> PRAttachments { get; set; }
public DbSet<ProjectCodes> ProjectCodes { get; set; }
public virtual DbSet<Entities.Purchasing.PRList> PRLists { get; set; }
public virtual DbSet<Entities.Canvass.PRList> PRItemList { get; set; }
public virtual DbSet<PRWOCanvass> PRWOCanvasses { get; set; }
public virtual DbSet<Entities.PO.ItemDetail> PRItemDetails { get; set; }
public virtual DbSet<DetailedPRTracking> DetailedPRTrackings { get; set; }
public virtual DbSet<PRTracking> PRTrackings { get; set; }
public virtual DbSet<Dashboard> Dashboards { get; set; }
#endregion
#region Canvassing
public virtual DbSet<NotificationById> NotificationByIds { get; set; }
public virtual DbSet<AlternativeOffer> AlternativeOffers { get; set; }
public virtual DbSet<AlternativeOfferDetails> AlternativeOfferDetails { get; set; }
public virtual DbSet<MyPRWOCanvass> MyPRWOCanvass { get; set; }
public virtual DbSet<Canvass> Canvasses { get; set; }
public DbSet<SupplierForCanvass> SupplierForCanvass { get; set; }
public DbSet<SupplierResponseDto> SupplierResponses { get; set; }
public DbSet<SupplierItems> SupplierItems { get; set; }
public DbSet<ItemsForTagging> ItemsForTaggings { get; set; }
public virtual DbSet<ForCanvassFollowUp> ForCanvassFollowUps { get; set; }
public virtual DbSet<WOResponse> WOResponses { get; set; }
public virtual DbSet<WOResponseById> WOResponseByIds { get; set; }
public virtual DbSet<ItemListWOEmail> ItemListWOEmails { get; set; }
public virtual DbSet<Suppliers> Suppliers { get; set; }
public virtual DbSet<RFQ> RFQs { get; set; }
public virtual DbSet<BiddingItem> BiddingItems { get; set; }
public virtual DbSet<SupplierBidById> SupplierBidByIds { get; set; }
public virtual DbSet<RFQPerSupplier> RFQPerSuppliers { get; set; }
public virtual DbSet<PerSupplier> PerSuppliers { get; set; }
public virtual DbSet<CanvassSupplier> CanvassSuppliers { get; set; }
public virtual DbSet<RFQReference> RFQReferences { get; set; }
public virtual DbSet<CanvassDetail> CanvassDetails { get; set; }
public virtual DbSet<PRCanvassDetail> PRCanvassDetails { get; set; }
public DbSet<ForAISearchingTagging> ForAISearchingTaggings { get; set; }
public virtual DbSet<CanvassGroupByPRNo> CanvassGroupByPRNos { get; set; }
public virtual DbSet<ForCanvass> ForCanvasses { get; set; }
#endregion
#region PO
public virtual DbSet<ForPO> ForPOs { get; set; }
public virtual DbSet<CreatedPO> CreatedPOs { get; set; }
public virtual DbSet<CustomPO> CustomPOs { get; set; }
public virtual DbSet<IndexCard> IndexCards { get; set; }
public virtual DbSet<ForPOApproval> ForPOApprovals { get; set; }
public virtual DbSet<ApprovedPO> ApprovedPOs { get; set; }
public virtual DbSet<PurchaseOrder> PurchaseOrders { get; set; }
public virtual DbSet<ForPayment> ForPayments { get; set; }
public virtual DbSet<PO> POs { get; set; }
public DbSet<PODetails> PODetails { get; set; }
public virtual DbSet<PRPOSummaryCount> PRPOSummaryCounts { get; set; }
public virtual DbSet<PRPOSummaryItem> PRPOSummaryItems { get; set; }
public virtual DbSet<POItemDetail> POItemDetails { get; set; }
public virtual DbSet<OtherCharges> OtherCharges { get; set; }
public virtual DbSet<PortOfDischarges> PortOfDischarges { get; set; }
public virtual DbSet<DocRequired> DocRequireds { get; set; }
public virtual DbSet<BiddingApproval> BiddingApprovals { get; set; }
public virtual DbSet<NotifUserKey> NotifUserKeys { get; set; }
public virtual DbSet<ItemListForPO> ItemListForPOs { get; set; }
public virtual DbSet<CreatedPOPerSupId> CreatedPOPerSupIds { get; set; }
public DbSet<IncomingShipment> IncomingShipments { get; set; }
public virtual DbSet<IncomingShipmentDto> IncomingShipmentDtos { get; set; }
public virtual DbSet<PaymentTerm> PaymentTerms { get; set; }
public virtual DbSet<Incoterm> Incoterms { get; set; }
public virtual DbSet<CentralPONo> CentralPONos { get; set; }
#endregion
#region Inventory
public virtual DbSet<Inventory> Inventories { get; set; }
public virtual DbSet<Lot> Lots { get; set; }
public virtual DbSet<LotType> LotTypes { get; set; }
public virtual DbSet<LotQtyByItem> LotQtyByItems { get; set; }
public virtual DbSet<RequestItem> RequestItems { get; set; }
public virtual DbSet<RequestItemDetail> RequestItemDetails { get; set; }
public virtual DbSet<RIS> RIS { get; set; }
public virtual DbSet<MRS> MRS { get; set; }
public virtual DbSet<Discipline> Disciplines { get; set; }
public virtual DbSet<InventTrans> InventTrans { get; set; }
public virtual DbSet<InventTransDetail> InventTransDetails { get; set; }
public DbSet<InventoryByIdResponse> InventoryByIdResponses { get; set; }
#endregion
#region RR
public virtual DbSet<ForReceiving> ForReceivings { get; set; }
public virtual DbSet<Infrastructure.Entities.Receiving.RRReport> RRReports { get; set; }
public virtual DbSet<ReceivingDetail> ReceivingDetails { get; set; }
public virtual DbSet<RRDetail> RRDetails { get; set; }
public virtual DbSet<ForRR> ForRRs { get; set; }
public virtual DbSet<RR> RRs { get; set; }
public virtual DbSet<Entities.Receiving.RRDetail> RRDetailss { get; set; }
public virtual DbSet<RRSeries> RRSeries { get; set; }
#endregion
#region Automation Part
public virtual DbSet<AllForCanvass> AllForCanvasses { get; set; }
public DbSet<ItemWithoutSupplier> ItemWithoutSuppliers { get; set; }
public DbSet<ErrorLog> ErrorLogs { get; set; }
#endregion
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<Incoterm>()
.Property(e => e.IncotermsId)
.ValueGeneratedOnAdd();
modelBuilder.Entity<CanvassSupplier>()
.Property(e => e.CanvassSupplierId)
.ValueGeneratedNever();
modelBuilder.Entity<DetailedPRTracking>(b =>
{
b.ToTable("DetailsedPRTracking");
b.HasNoKey();
});
modelBuilder.Entity<PRPOSummaryCount>(b =>
{
b.ToTable("PRPOSummaryCount");
b.HasNoKey();
});
modelBuilder.Entity<PRPOSummaryItem>(b =>
{
b.ToTable("PRPOSummaryItem");
b.HasNoKey();
});
modelBuilder.Entity<RR>(b =>
{
b.ToTable("RR");
b.HasNoKey();
});
modelBuilder.Entity<ApplicationUser>(b =>
{
b.ToTable("Users");
b.Property(u => u.Address).HasMaxLength(255);
b.HasOne(u => u.Attachment)
.WithOne(a => a.ApplicationUser)
.HasForeignKey<Attachment>(a => a.AttachmentId)
.IsRequired(false);
});
modelBuilder.Entity<Attachment>(b =>
{
b.ToTable("Attachments");
b.HasOne(a => a.AttachmentExtention)
.WithOne()
.HasForeignKey<Attachment>(a => a.ExtensionId)
.IsRequired(false);
});
modelBuilder.Entity<ApplicationUser>(b =>
{
b.HasOne(u => u.Department)
.WithMany()
.HasForeignKey(u => u.DepartmentId)
.IsRequired(false);
});
modelBuilder.Entity<ForPO>(entity =>
{
entity.ToTable("ForPO");
entity.HasNoKey();
});
modelBuilder.Entity<Departments>(b =>
{
b.ToTable("Departments");
});
modelBuilder.Entity<ControllerAccess>(b =>
{
b.ToTable("ControllerAccess");
});
modelBuilder.Entity<AttachmentExtension>(b =>
{
b.ToTable("AttachmentExtensions");
});
modelBuilder.Entity<IdentityUserClaim<string>>(b =>
{
b.ToTable("UserClaims");
});
modelBuilder.Entity<IdentityUserLogin<string>>(b =>
{
b.ToTable("UserLogins");
});
modelBuilder.Entity<IdentityRoleClaim<string>>(b =>
{
b.ToTable("RoleClaims");
});
modelBuilder.Entity<IdentityUserToken<string>>(b =>
{
b.ToTable("UserTokens");
});
modelBuilder.Entity<IdentityRole>(b =>
{
b.ToTable("Roles");
});
modelBuilder.Entity<IdentityUserRole<string>>(b =>
{
b.ToTable("UserRoles");
});
modelBuilder.Entity<Inventory>()
.HasOne(i => i.Lot)
.WithMany()
.HasForeignKey(i => i.LotId)
.OnDelete(DeleteBehavior.Restrict);
modelBuilder.Entity<Inventory>()
.HasOne(i => i.Item)
.WithMany()
.HasForeignKey(i => i.ItemNo)
.OnDelete(DeleteBehavior.Restrict);
modelBuilder.Entity<Item>()
.HasOne(i => i.ItemCode)
.WithMany()
.HasForeignKey(i => i.ItemCodeId)
.OnDelete(DeleteBehavior.Restrict);
modelBuilder.Entity<ItemCode>()
.HasOne(i => i.ItemCategory)
.WithMany()
.HasForeignKey(i => i.ItemCategoryId)
.OnDelete(DeleteBehavior.Restrict);
modelBuilder.Entity<InventTransDetail>(e =>
{
e.HasOne(i => i.PRDetails)
.WithMany()
.HasForeignKey(t => t.PRDetailId)
.OnDelete(DeleteBehavior.Restrict);
});
modelBuilder.Entity<PRDetails>(e =>
{
e.HasOne(i => i.PRs)
.WithMany()
.HasForeignKey(t => t.PRId)
.OnDelete(DeleteBehavior.Restrict);
});
modelBuilder.Entity<RIS>(e => {
e.HasOne(r => r.Inventory)
.WithMany()
.HasForeignKey(r => r.InventoryId)
.OnDelete(DeleteBehavior.Restrict);
e.HasOne(r => r.Discipline)
.WithMany()
.HasForeignKey(r => r.DisciplineId);
});
modelBuilder.Entity<MRS>(e => {
e.HasOne(m => m.RIS)
.WithMany(r => r.MaterialReturns)
.HasForeignKey(m => m.RISId)
.OnDelete(DeleteBehavior.Restrict);
});
}
}
}