From 659e36cf8b7856bda47a5cf8cd26f719d9e85b49 Mon Sep 17 00:00:00 2001 From: Annamaria Sassi Date: Thu, 19 Jun 2025 18:11:10 +0200 Subject: [PATCH] - aggiunto inizializzazione - corretti nomi variabili --- Lux.Data/Controllers/LuxController.cs | 12 ++++----- Lux.Data/DataLayerContext.cs | 5 +++- Lux.Data/DbModel/OfferRowModel.cs | 4 +-- Lux.Data/ModelBuilderExtensions.cs | 39 ++++++++++++++++++++++----- TestApp/Program.cs | 4 +-- 5 files changed, 47 insertions(+), 17 deletions(-) diff --git a/Lux.Data/Controllers/LuxController.cs b/Lux.Data/Controllers/LuxController.cs index 2e148a30..58e1973e 100644 --- a/Lux.Data/Controllers/LuxController.cs +++ b/Lux.Data/Controllers/LuxController.cs @@ -16,7 +16,7 @@ namespace Lux.Data.Controllers #region Public Methods - public List ArticoliGetAll() + public List ItemGetAll() { List dbResult = new List(); //using (DataLayerContext dbCtx = new DataLayerContext(_configuration)) @@ -30,13 +30,13 @@ namespace Lux.Data.Controllers } catch (Exception exc) { - Log.Error($"Eccezione durante ArticoliGetAll{Environment.NewLine}{exc}"); + Log.Error($"Eccezione durante ItemGetAll{Environment.NewLine}{exc}"); } } return dbResult; } - public List ArticoliGetSearch(string term) + public List ItemGetSearch(string term) { List dbResult = new List(); //using (DataLayerContext dbCtx = new DataLayerContext(_configuration)) @@ -51,13 +51,13 @@ namespace Lux.Data.Controllers } catch (Exception exc) { - Log.Error($"Eccezione durante ArticoliGetSearch{Environment.NewLine}{exc}"); + Log.Error($"Eccezione durante ItemGetSearch{Environment.NewLine}{exc}"); } } return dbResult; } - public bool ArticoliUpsert(ItemModel newRec) + public bool ItemUpsert(ItemModel newRec) { bool answ = false; //using (DataLayerContext dbCtx = new DataLayerContext(_configuration)) @@ -93,7 +93,7 @@ namespace Lux.Data.Controllers } catch (Exception exc) { - Log.Error($"Eccezione durante ArticoliGetSearch{Environment.NewLine}{exc}"); + Log.Error($"Eccezione durante ItemGetSearch{Environment.NewLine}{exc}"); } } return answ; ; diff --git a/Lux.Data/DataLayerContext.cs b/Lux.Data/DataLayerContext.cs index 28165669..5b74f8ba 100644 --- a/Lux.Data/DataLayerContext.cs +++ b/Lux.Data/DataLayerContext.cs @@ -42,7 +42,10 @@ namespace Lux.Data public virtual DbSet DbSetItem { get; set; } public virtual DbSet DbSetRole { get; set; } - public virtual DbSet DbSetPerson { get; set; } + public virtual DbSet DbSetCustomer { get; set; } + public virtual DbSet DbSetDealer { get; set; } + public virtual DbSet DbSetSupplier { get; set; } + public virtual DbSet DbSetOffer { get; set; } partial void OnModelCreatingPartial(ModelBuilder modelBuilder); diff --git a/Lux.Data/DbModel/OfferRowModel.cs b/Lux.Data/DbModel/OfferRowModel.cs index 58e4194a..386924b7 100644 --- a/Lux.Data/DbModel/OfferRowModel.cs +++ b/Lux.Data/DbModel/OfferRowModel.cs @@ -13,8 +13,8 @@ namespace Lux.Data.DbModel // This is here so CodeMaid doesn't reorganize this document // - [Table("RegOffer")] - public class OfferModel + [Table("RegOfferRow")] + public class OfferRowModel { /// /// ID del record diff --git a/Lux.Data/ModelBuilderExtensions.cs b/Lux.Data/ModelBuilderExtensions.cs index 30310089..5ae0878a 100644 --- a/Lux.Data/ModelBuilderExtensions.cs +++ b/Lux.Data/ModelBuilderExtensions.cs @@ -25,13 +25,40 @@ namespace Lux.Data new RoleModel { RoleID = 5, Description = "Dealer" } ); - // inizializzazione dei valori di default x Person + // inizializzazione dei valori di default x Customer modelBuilder.Entity().HasData( - new CustomerModel { PersonID = 1, RoleID = 1, FirstName = "Admin", LastName = "Egalware", VAT = "1234567890123456" }, - new CustomerModel { PersonID = 2, RoleID = 2, FirstName = "Standard", LastName = "User", VAT = "1234567890123456" }, - new CustomerModel { PersonID = 3, RoleID = 3, FirstName = "Customer A", LastName = "User Test", VAT = "1234567890123456" }, - new CustomerModel { PersonID = 4, RoleID = 4, FirstName = "Supplier B", LastName = "User Test", VAT = "1234567890123456" }, - new CustomerModel { PersonID = 5, RoleID = 5, FirstName = "Dealer C", LastName = "User Test", VAT = "1234567890123456" } + new CustomerModel { CustomerID = 1, FirstName = "Customer A", LastName = "Egalware", VAT = "1234567890123456" }, + new CustomerModel { CustomerID = 2, FirstName = "Customer B", LastName = "User", VAT = "1234567890123456" }, + new CustomerModel { CustomerID = 3, FirstName = "Customer C", LastName = "User Test", VAT = "1234567890123456" } + ); + + // inizializzazione dei valori di default x Dealer + modelBuilder.Entity().HasData( + new DealerModel { DealerID = 1, CompanyName = "Company First",FirstName = "Dealer A", LastName = "Egalware", VAT = "9587362514671527" }, + new DealerModel { DealerID = 2, CompanyName = "Company First", FirstName = "Dealer B", LastName = "User", VAT = "9587362514671527" }, + new DealerModel { DealerID = 3, CompanyName = "Company Second", FirstName = "Dealer C", LastName = "User Test", VAT = "9587362514671527" } + ); + + // inizializzazione dei valori di default x Supplier + modelBuilder.Entity().HasData( + new SupplierModel { SupplierID = 1, CompanyName = "Company One", FirstName = "Supplier A", LastName = "Egalware", VAT = "7294857103879254" }, + new SupplierModel { SupplierID = 2, CompanyName = "Company Two", FirstName = "Supplier B", LastName = "User", VAT = "7294857103879254" }, + new SupplierModel { SupplierID = 3, CompanyName = "Company Two", FirstName = "Supplier C", LastName = "User Test", VAT = "7294857103879254" } + ); + + // inizializzazione dei valori di default x Item + modelBuilder.Entity().HasData( + new ItemModel { ItemID = 1, IsService = false, IsMake = true, Description = "Telaio", Cost = 820, Margin = 0.2 }, + new ItemModel { ItemID = 2, IsService = false, IsMake = false, Description = "Persiana anta singola", Cost = 935, Margin = 0.1 }, + new ItemModel { ItemID = 3, IsService = true, IsMake = true, Description = "Installazione", Cost = 1279, Margin = 0.3 } + ); + + // inizializzazione dei valori di default x Offer + modelBuilder.Entity().HasData( + new OfferModel { OfferID = 1, RefYear = 2024, RefNum = 1, RefRev = 1, Description = "Offerta per tre serramenti", CustomerID = 2, DealerID = 2 }, + new OfferModel { OfferID = 2, RefYear = 2025, RefNum =2, RefRev = 1, Description = "Offerta per un serramento + installazione", CustomerID = 1, DealerID = 1 }, + new OfferModel { OfferID = 3, RefYear = 2025, RefNum = 3, RefRev = 1, Description = "Offerta per tre serramenti", CustomerID = 2, DealerID = 1 }, + new OfferModel { OfferID = 5, RefYear = 2025, RefNum = 4, RefRev = 2, Description = "Offerta per cinque serramenti + installazione", CustomerID = 3, DealerID = 2 } ); } diff --git a/TestApp/Program.cs b/TestApp/Program.cs index 43f5b821..12d2a458 100644 --- a/TestApp/Program.cs +++ b/TestApp/Program.cs @@ -7,7 +7,7 @@ Console.WriteLine("--------------"); LuxController lControl = new LuxController(); -var listRec = lControl.ArticoliGetAll(); +var listRec = lControl.ItemGetAll(); foreach (var item in listRec) { Console.WriteLine($"{item.ItemID} | {item.Description} | {item.Cost}"); @@ -19,7 +19,7 @@ while (!string.IsNullOrEmpty(search)) { Console.WriteLine("inserire una ricerca, enter per chiudere"); search = Console.ReadLine(); - listRec = lControl.ArticoliGetSearch($"{search}"); + listRec = lControl.ItemGetSearch($"{search}"); foreach (var item in listRec) { Console.WriteLine($"{item.ItemID} | {item.Description} | {item.Cost}");