Fixed all relationship and write errors in all entities

This commit is contained in:
2025-10-07 23:28:16 +01:00
parent 9a5c83161a
commit 89be35ecb0
31 changed files with 124 additions and 104 deletions

12
PyroFetes/Models/City.cs Normal file
View File

@@ -0,0 +1,12 @@
using System.ComponentModel.DataAnnotations;
namespace PyroFetes.Models;
public class City
{
[Key] public int Id { get; set; }
[Required, MaxLength(100)] public string? Name { get; set; }
[Required] public int ZipCode { get; set; }
public List<Show>? Shows { get; set; }
}

View File

@@ -5,7 +5,7 @@ namespace PyroFetes.Models;
public class Classification
{
[Key] public int Id { get; set; }
[Required] public string? Label { get; set; }
[Required, MaxLength(100)] public string? Label { get; set; }
[Required] public List<Product>? Products { get; set; }
public List<Product>? Products { get; set; }
}

View File

@@ -5,6 +5,7 @@ namespace PyroFetes.Models;
public class Color
{
[Key] public int Id { get; set; }
[Required] public string? Label { get; set; }
[Required, MaxLength(100)] public string? Label { get; set; }
public List<ProductColor>? ProductColors { get; set; }
}

View File

@@ -5,8 +5,10 @@ namespace PyroFetes.Models;
public class Communication
{
[Key] public int Id { get; set; }
[Required] public string? Calling { get; set; }
[Required] public string? Email { get; set; }
[Required] public string? Meeting { get; set; }
[Required, MaxLength(100)] public string? Calling { get; set; }
[Required, MaxLength(100)] public string? Email { get; set; }
[Required, MaxLength(300)] public string? Meeting { get; set; }
[Required] public int ContactId { get; set; }
public Contact? Contact { get; set; }
}

View File

@@ -7,15 +7,15 @@ public class Contact
[Key] public int Id { get; set; }
[Required, MaxLength(100)] public string? LastName { get; set; }
[Required, MaxLength(100)] public string? FirstName { get; set; }
[Required] public string? Email { get; set; }
[Required] public string? PhoneNumber { get; set; }
[Required] public string? Address { get; set; }
[Required] public string? ZipCode { get; set; }
[Required] public string? City { get; set; }
[Required] public string? Role { get; set; }
[Required, MaxLength(100)] public string? Email { get; set; }
[Required, MaxLength(30)] public string? PhoneNumber { get; set; }
[Required, MaxLength(100)] public string? Address { get; set; }
[Required] public int ZipCode { get; set; }
[Required, MaxLength(100)] public string? City { get; set; }
[Required, MaxLength(100)] public string? Role { get; set; }
public int CommunicationId { get; set; }
public Communication? Communication { get; set; }
public Customer? Customer { get; set; }
[Required] public int CustomerId { get; set; }
public List<CustomerContact>? CustomerContacts { get; set; }
public List<Communication>? Communications { get; set; }
}

View File

@@ -5,14 +5,11 @@ namespace PyroFetes.Models;
public class Customer
{
[Key] public int Id { get; set; }
[Required] public string? Note { get; set; }
[Required, MaxLength(200)] public string? Note { get; set; }
//Relations
public int CustomerTypeId { get; set; }
[Required] public int CustomerTypeId { get; set; }
public CustomerType? CustomerType { get; set; }
public int ContactId { get; set; }
public Contact? Contact { get; set; }
public List<CustomerContact>? CustomerContacts { get; set; }
public List<Contact>? Contacts { get; set; }
}

View File

@@ -1,13 +0,0 @@
using System.ComponentModel.DataAnnotations;
using Microsoft.EntityFrameworkCore;
namespace PyroFetes.Models;
[PrimaryKey(nameof(ContactId), nameof(CustomerId))]
public class CustomerContact
{
public int CustomerId { get; set; }
public Customer? Customer { get; set; }
public int ContactId { get; set; }
public Contact? Contact { get; set; }
}

View File

@@ -5,7 +5,7 @@ namespace PyroFetes.Models;
public class Deliverer
{
[Key] public int Id { get; set; }
[Required] public string? Transporter { get; set; }
[Required, MaxLength(100)] public string? Transporter { get; set; }
public List<DeliveryNote>? DeliveryNotes { get; set; }
}

View File

@@ -5,11 +5,12 @@ namespace PyroFetes.Models;
public class DeliveryNote
{
[Key] public int Id { get; set; }
[Required] public string? TrackingNumber { get; set; }
[Required, MaxLength(100)] public string? TrackingNumber { get; set; }
public int DelivererId { get; set; }
[Required] public DateOnly EstimateDeliveryDate { get; set; }
[Required] public DateOnly ExpeditionDate { get; set; }
[Required] public DateOnly RealDeliveryDate { get; set; }
public Deliverer? Deliverer { get; set; }
public List<ProductDelivery>? ProductDeliveries { get; set; }
}

View File

@@ -5,5 +5,7 @@ namespace PyroFetes.Models;
public class Effect
{
[Key] public int Id { get; set; }
[Required] public string? Label { get; set; }
[Required, MaxLength(200)] public string? Label { get; set; }
public List<ProductEffect>? ProductEffects { get; set; }
}

View File

@@ -10,9 +10,7 @@ public class Movement
[Required] public DateTime Arrival {get; set;}
[Required] public int Quantity {get; set;}
[Required] public int ProductId {get; set;}
[Required] public Product? Product {get; set;}
public List<Product>? Products { get; set; }
public int? SourceWarehouseId {get; set;}
public Warehouse? SourceWarehouse {get; set;}

View File

@@ -1,4 +1,5 @@
using System.ComponentModel.DataAnnotations;
using System.Runtime.CompilerServices;
using Microsoft.EntityFrameworkCore;
namespace PyroFetes.Models;

View File

@@ -14,19 +14,29 @@ namespace PyroFetes.Models
[Required] public decimal Nec { get; set; }
[Required] public decimal SellingPrice { get; set; }
[Required] public string? Image { get; set; }
[Required] public string? Link { get; set; }
[Required, MaxLength(200)] public string? Link { get; set; }
[Required] public int MinimalQuantity { get; set; }
// Relations
[Required] public int ClassificationId { get; set; }
[Required] public Classification? Classification { get; set; }
public Classification? Classification { get; set; }
[Required] public int ProductCategoryId { get; set; }
[Required] public ProductCategory? ProductCategory { get; set; }
[Required] public List<Brand>? Brands { get; set; }
public ProductCategory? ProductCategory { get; set; }
[Required] public int MovementId {get; set;}
public Movement? Movement {get; set;}
public List<ProductDelivery>? ProductDeliveries { get; set; }
public List<Brand>? Brands { get; set; }
public List<Movement>? Movements { get; set; }
public List<ProductEffect>? ProductEffects { get; set; }
public List<ProductColor>? ProductColors { get; set; }
public List<PurchaseProduct>? PurchaseProducts { get; set; }
public List<Price>? Prices { get; set; }
public List<QuotationProduct>? QuotationProducts { get; set; }
public List<WarehouseProduct>? WarehouseProducts { get; set; }
[Required] public List<Movement>? Movements { get; set; }
}
}

View File

@@ -5,7 +5,7 @@ namespace PyroFetes.Models;
public class ProductCategory
{
[Key] public int Id { get; set; }
[Required] public string? Label { get; set; }
[Required, MaxLength(100)] public string? Label { get; set; }
[Required] public List<Product>? Products { get; set; }
public List<Product>? Products { get; set; }
}

View File

@@ -6,9 +6,9 @@ namespace PyroFetes.Models;
[PrimaryKey(nameof(ProductId), nameof(ColorId))]
public class ProductColor
{
[Required] public Product? Product { get; set; }
public Product? Product { get; set; }
[Required] public int ProductId { get; set; }
[Required] public Color? Color { get; set; }
public Color? Color { get; set; }
[Required] public int ColorId { get; set; }
}

View File

@@ -12,5 +12,4 @@ public class ProductDelivery
public Product? Product { get; set; }
public DeliveryNote? DeliveryNote { get; set; }
}
}

View File

@@ -9,7 +9,7 @@ public class ProductEffect
[Required] public Product? Product { get; set; }
[Required] public int ProductId { get; set; }
[Required] public Effect? Effect { get; set; }
public Effect? Effect { get; set; }
[Required] public int EffectId { get; set; }
}

View File

@@ -6,7 +6,7 @@ namespace PyroFetes.Models;
public class ProviderContact
{
public int ProviderId { get; set; }
public Provider? Provider { get; set; }
public ServiceProvider? Provider { get; set; }
public int ContactId { get; set; }
public Contact? Contact { get; set; }
}

View File

@@ -5,5 +5,7 @@ namespace PyroFetes.Models;
public class PurchaseOrder
{
[Key] public int Id { get; set; }
[Required] public string? PurchaseConditions { get; set; }
[Required, MaxLength(300)] public string? PurchaseConditions { get; set; }
public List<PurchaseProduct>? PurchaseProducts { get; set; }
}

View File

@@ -5,6 +5,8 @@ namespace PyroFetes.Models;
public class Quotation
{
[Key] public int Id { get; set; }
[Required] public string? Message { get; set; }
[Required] public string? ConditionsSale { get; set; }
[Required, MaxLength(200)] public string? Message { get; set; }
[Required, MaxLength(300)] public string? ConditionsSale { get; set; }
public List<QuotationProduct>? QuotationProducts { get; set; }
}

View File

@@ -2,13 +2,12 @@ using System.ComponentModel.DataAnnotations;
namespace PyroFetes.Models;
public class Provider
public class ServiceProvider
{
[Key] public int Id { get; set; }
[Required] public decimal Price { get; set; }
//Relations
public int ProviderId { get; set; }
public int ProviderTypeId { get; set; }
public ProviderType? ProviderType { get; set; }
}

View File

@@ -10,11 +10,15 @@ public class Show
[MaxLength(500)] public string? Description { get; set; }
// Link (path/URL/file name) to the pyrotechnic implementation plan
[Required, MaxLength(500)]
public string? PyrotechnicImplementationPlan { get; set; }
public DateTime? Date { get; set; }
[Required, MaxLength(500)] public string? PyrotechnicImplementationPlan { get; set; }
public DateOnly? Date { get; set; }
[Required] public int CityId { get; set; }
public City? City { get; set; }
public ICollection<Staff>? Staff { get; set; }
public ICollection<Truck>? Trucks { get; set; }
public ICollection<SoundTimecode>? SoundCues { get; set; }
public List<SoundTimecode>? SoundTimecodes { get; set; }
}

View File

@@ -0,0 +1,9 @@
using System.ComponentModel.DataAnnotations;
namespace PyroFetes.Models;
public class ShowServiceProvider
{
[Key] public int Id { get; set; }
}

View File

@@ -12,7 +12,9 @@ public class Sound
[Required, MaxLength(40)] public string? Kind { get; set; }
[Required, MaxLength(40)] public string? Format { get; set; }
public DateTime? CreationDate { get; set; }
[Required] public int SoundCategoryId { get; set; }
public SoundCategory? Category { get; set; }
public ICollection<SoundTimecode>? ShowPlacements { get; set; }
public SoundCategory? SoundCategory { get; set; }
public List<SoundTimecode>? SoundTimecodes { get; set; }
}

View File

@@ -5,6 +5,7 @@ namespace PyroFetes.Models;
public class SoundCategory
{
[Key] public int Id { get; set; }
[Required, MaxLength(60)] public string Name { get; set; } = null!;
public ICollection<Sound>? Sounds { get; set; }
[Required, MaxLength(100)] public string Name { get; set; } = null!;
public List<Sound>? Sounds { get; set; }
}

View File

@@ -1,14 +1,16 @@
using System.ComponentModel.DataAnnotations;
using Microsoft.EntityFrameworkCore;
namespace PyroFetes.Models;
[PrimaryKey(nameof(ShowId), nameof(SoundId))]
public class SoundTimecode
{
[Key] public int Id { get; set; }
[Required] public int ShowId { get; set; }
public Show? Show { get; set; }
[Required] public int SoundId { get; set; }
public Sound? Sound { get; set; }
[Required, Range(0, int.MaxValue)] public int Start { get; set; }
[Required, Range(0, int.MaxValue)] public int End { get; set; }
[Required] public decimal Start { get; set; }
[Required] public decimal End { get; set; }
}

View File

@@ -6,10 +6,12 @@ public class Supplier
{
[Key] public int Id { get; set; }
[Required, MaxLength(100)] public string? Name { get; set; }
[Required] public string? Email { get; set; }
[Required] public string? Phone { get; set; }
[Required] public string? Address { get; set; }
[Required, MaxLength(100)] public string? Email { get; set; }
[Required, MaxLength(30)] public string? Phone { get; set; }
[Required, MaxLength(100)] public string? Address { get; set; }
[Required] public int ZipCode { get; set; }
[Required] public string? City { get; set; }
[Required, MaxLength(100)] public string? City { get; set; }
[Required] public int DeliveryDelay { get; set; }
public List<Price>? Prices { get; set; }
}

View File

@@ -6,8 +6,8 @@ public class User
{
[Key] public int Id { get; set; }
[Required, MaxLength(100)] public string? Name { get; set; }
[Required, MinLength(12)] public string? Password { get; set; }
[Required] public string? Salt { get; set; }
[Required] public string? Email { get; set; }
[Required] public string? Fonction { get; set; }
[Required, MinLength(12), MaxLength(50)] public string? Password { get; set; }
[Required, MaxLength(100)] public string? Salt { get; set; }
[Required, MaxLength(100)] public string? Email { get; set; }
[Required, MaxLength(100)] public string? Fonction { get; set; }
}

View File

@@ -9,10 +9,11 @@ public class Warehouse
[Required] public int MaxWeight {get; set;}
[Required] public int Current {get; set;}
[Required] public int MinWeight {get; set;}
[Required] public string? Address { get; set; }
[Required, MaxLength(100)] public string? Address { get; set; }
[Required] public int ZipCode { get; set; }
[Required] public string? City { get; set; }
[Required, MaxLength(100)] public string? City { get; set; }
public List<WarehouseProduct>? WarehouseProducts { get; set; }
public List<Material>? Materials {get; set;}
public List<Movement>? MovementsSource { get; set; }
public List<Movement>? MovementsDestination { get; set; }

View File

@@ -1,14 +1,15 @@
using System.ComponentModel.DataAnnotations;
using Microsoft.EntityFrameworkCore;
namespace PyroFetes.Models;
[PrimaryKey(nameof(ProductId), nameof(WarehouseId))]
public class WarehouseProduct
{
[Key] public int Quantity { get; set; }
[Required] public int ProductId { get; set; }
[Required] public Product? Product { get; set; }
public Product? Product { get; set; }
[Required] public int WarehouseId { get; set; }
[Required] public Warehouse? Warehouse { get; set; }
public Warehouse? Warehouse { get; set; }
[Required] public int Quantity { get; set; }
}

View File

@@ -1,5 +1,6 @@
using Microsoft.EntityFrameworkCore;
using PyroFetes.Models;
using ServiceProvider = PyroFetes.Models.ServiceProvider;
namespace PyroFetes;
@@ -13,7 +14,6 @@ public class PyroFetesDbContext : DbContext
public DbSet<Communication> Communications { get; set; }
public DbSet<Contact> Contacts { get; set; }
public DbSet<Customer> Customers { get; set; }
public DbSet<CustomerContact> CustomerContacts { get; set; }
public DbSet<CustomerType> CustomerTypes { get; set; }
public DbSet<Deliverer> Deliverers { get; set; }
public DbSet<DeliveryNote> DeliveryNotes { get; set; }
@@ -28,7 +28,7 @@ public class PyroFetesDbContext : DbContext
public DbSet<ProductColor> ProductColors { get; set; }
public DbSet<ProductDelivery> ProductDeliveries { get; set; }
public DbSet<ProductEffect> ProductEffects { get; set; }
public DbSet<Provider> Providers { get; set; }
public DbSet<ServiceProvider> Providers { get; set; }
public DbSet<ProviderContact> ProviderContacts { get; set; }
public DbSet<ProviderType> ProviderTypes { get; set; }
public DbSet<PurchaseOrder> PurchaseOrders { get; set; }
@@ -77,20 +77,5 @@ public class PyroFetesDbContext : DbContext
.WithMany(w => w.MovementsDestination)
.HasForeignKey(m => m.DestinationWarehouseId)
.OnDelete(DeleteBehavior.Restrict);
modelBuilder.Entity<CustomerContact>()
.HasKey(cc => new { cc.ContactId, cc.CustomerId });
modelBuilder.Entity<CustomerContact>()
.HasOne(cc => cc.Customer)
.WithMany(c => c.CustomerContacts)
.HasForeignKey(cc => cc.CustomerId)
.OnDelete(DeleteBehavior.NoAction);
modelBuilder.Entity<CustomerContact>()
.HasOne(cc => cc.Contact)
.WithMany(c => c.CustomerContacts)
.HasForeignKey(cc => cc.ContactId)
.OnDelete(DeleteBehavior.NoAction);
}
}