<pre lang="c#"><pre> public class Invoice
{
public int InvoiceId { get; set; }
public DateTimeOffset InvoiceDate { get; set; } = DateTimeOffset.UtcNow;
public string InvoiceNote { get; set; }
public int CustomerId { get; set; }
public Customer Customer { get; set; }
public int AdminId { get; set; }
public Admin Admin { get; set; }
public int CompanyStoresId { get; set; }
public CompanyStore CompanyStores { get; set; }
public ICollection<CustomerInvoice> CustomerInvoices { get; set; }
= new List<CustomerInvoice>();
public ICollection<ProductsReturn> ProductsReturn { get; set; }
= new List<ProductsReturn>();
}
<pre lang="c#"><pre> public class Product
{
public int ProductId { get; set; }
public string ProductName { get; set; }
public string Company { get; set; }
public float Price { get; set; }
public int Quantity { get; set; }
public string Description { get; set; }
public string ProductImage { get; set; }
public string BarCode { get; set; }
public float BuyPrice { get; set; }
public ICollection<ProductAndCategory> ProductCategory { get; set; }
= new List<ProductAndCategory>();
public ICollection<TransportInvoice> transportInvoices { get; set; }
= new List<TransportInvoice>();
public ICollection<CustomerInvoice> CustomerInvoices { get; set; }
= new List<CustomerInvoice>();
public ICollection<ProductsReturn> ProductsReturn { get; set; }
= new List<ProductsReturn>();
public int CompanyStoresId { get; set; }
public CompanyStore CompanyStores { get; set; }
public ICollection<OfficeInvoice> OfficeInvoices { get; set; }
= new List<OfficeInvoice>();
public ICollection<OfficeReturn> OfficeReturns { get; set; }
= new List<OfficeReturn>();
}
<pre lang="c#"><pre>public class CustomerInvoice
{
public int CustomerInvoiceId { get; set; }
public int Quantity { get; set; }
public float Discount { get; set; }
public float TotalPrice { get; set; }
public int InvoiceId { get; set; }
public Invoice Invoice { get; set; }
public int ProductId { get; set; }
public Product Products { get; set; }
public ICollection<ProductsReturn> ProductsReturn { get; set; }
= new List<ProductsReturn>();
}
<pre lang="c#"><pre> modelBuilder.Entity<CustomerInvoice>(entity =>
{
modelBuilder.Entity<CustomerInvoice>().HasKey(ci => new { ci.ProductId, ci.InvoiceId });
entity.HasKey(c => c.CustomerInvoiceId);
entity.Property(c => c.Quantity).IsRequired();
entity.Property(c => c.TotalPrice).IsRequired();
});
modelBuilder.Entity<CustomerInvoice>(entity =>
{
entity.HasOne(c => c.Products)
.WithMany(p => p.CustomerInvoices)
.HasForeignKey(c => c.ProductId)
.IsRequired(false)
.OnDelete(DeleteBehavior.NoAction);
});
modelBuilder.Entity<CustomerInvoice>(entity =>
{
entity.HasOne(c => c.Invoice)
.WithMany(i => i.CustomerInvoices)
.HasForeignKey(c => c.InvoiceId)
.IsRequired(false)
.OnDelete(DeleteBehavior.NoAction);
});
<pre lang="c#"><pre>public class AddCustomerInvoice
{
public ICollection<Product> products { get; set; }
= new List<Product>();
public DateTime InvoiceDate { get; set; }
public string InvoiceNote { get; set; }
public int CustomerId { get; set; }
public int AdminId { get; set; }
public int CompanyStoresId { get; set; }
}