From 575888267ad9c11c79db7d38c1a4006bbd4a2d40 Mon Sep 17 00:00:00 2001 From: etudiant Date: Wed, 21 Dec 2022 16:11:26 +0100 Subject: [PATCH] mvvm --- src/CalculateurMoyanne/BSN/IBlocDbManager.cs | 12 ++ src/CalculateurMoyanne/BSN/IDataManager.cs | 2 +- .../BSN/IMatiereDbManager.cs | 10 + .../BSN/IUeDbDataManager.cs | 12 ++ src/CalculateurMoyanne/BSN/Manager.cs | 113 ++++++++--- .../CalculateurApp/App.xaml.cs | 11 +- .../CalculateurApp/CalculateurApp.csproj | 17 +- .../CalculateurApp/MauiProgram.cs | 3 +- .../CalculateurApp/View/BlockView.xaml | 17 +- .../CalculateurApp/View/BlockView.xaml.cs | 18 +- .../CalculateurApp/View/HomePage.xaml | 13 +- .../CalculateurApp/View/Maquette.xaml | 2 +- .../CalculateurApp/View/Maquette.xaml.cs | 5 + .../CalculateurApp/View/MatiereView.xaml | 102 ++++++++++ .../CalculateurApp/View/MatiereView.xaml.cs | 27 +++ .../CalculateurApp/View/Start.xaml.cs | 2 +- .../CalculateurApp/View/UeView.xaml | 102 ++++++++++ .../CalculateurApp/View/UeView.xaml.cs | 34 ++++ .../CalculateurApp/ViewModel/BlocViewModel.cs | 144 ++++++++----- .../ViewModel/MaquetteViewModel.cs | 191 ++++++++---------- .../ViewModel/MatiereViewModel.cs | 11 + .../ViewModel/PageAjoutMaquette.cs | 25 +-- .../CalculateurApp/ViewModel/UeViewModel.cs | 103 +++++++--- .../CalculateurEF/Entities/MatiereEntity.cs | 5 +- .../CalculateurMapping/BlocDbDataManager.cs | 114 ++++++++--- .../MaquetteDbDataManager.cs | 42 +--- .../MatiereDbDataManager.cs | 42 +++- .../CalculateurMapping/UeDbDataManager.cs | 84 ++++++-- .../CalculateurStub/Stub/StubBloc.cs | 12 +- .../CalculateurStub/Stub/stubUE.cs | 12 +- .../Modele/BlocModel.cs | 16 +- .../ClassCalculateurMoyenne/Modele/Matiere.cs | 82 ++++++-- .../ClassCalculateurMoyenne/Modele/UE.cs | 12 +- .../TestCalculateurMoyanne/LesTests/TEST.cs | 58 +----- .../LesTests/TestManager.cs | 2 - .../LesTests/UnitTestBloc.cs | 20 -- .../LesTests/UnitTestMaquette.cs | 20 +- .../LesTests/UnitTestUE.cs | 2 +- 38 files changed, 1013 insertions(+), 486 deletions(-) create mode 100644 src/CalculateurMoyanne/BSN/IBlocDbManager.cs create mode 100644 src/CalculateurMoyanne/BSN/IMatiereDbManager.cs create mode 100644 src/CalculateurMoyanne/BSN/IUeDbDataManager.cs create mode 100644 src/CalculateurMoyanne/CalculateurApp/View/MatiereView.xaml create mode 100644 src/CalculateurMoyanne/CalculateurApp/View/MatiereView.xaml.cs create mode 100644 src/CalculateurMoyanne/CalculateurApp/View/UeView.xaml create mode 100644 src/CalculateurMoyanne/CalculateurApp/View/UeView.xaml.cs create mode 100644 src/CalculateurMoyanne/CalculateurApp/ViewModel/MatiereViewModel.cs diff --git a/src/CalculateurMoyanne/BSN/IBlocDbManager.cs b/src/CalculateurMoyanne/BSN/IBlocDbManager.cs new file mode 100644 index 0000000..1219bb2 --- /dev/null +++ b/src/CalculateurMoyanne/BSN/IBlocDbManager.cs @@ -0,0 +1,12 @@ +using System; +using ClassCalculateurMoyenne; +namespace Bussness +{ + public interface IBlocDbManager:IDataManager + { + Task> GetByMaquette(MaquetteModel maquetteModel); + Task AddUeBloc(BlocModel bloc, UE uE); + + } +} + diff --git a/src/CalculateurMoyanne/BSN/IDataManager.cs b/src/CalculateurMoyanne/BSN/IDataManager.cs index 03a6730..e02a491 100644 --- a/src/CalculateurMoyanne/BSN/IDataManager.cs +++ b/src/CalculateurMoyanne/BSN/IDataManager.cs @@ -14,7 +14,7 @@ namespace Bussness Task Update(Data data); Task GetDataWithName(string name); Task> GetAll(); - Task AddUEBloc(UE data, int blocId); + } } diff --git a/src/CalculateurMoyanne/BSN/IMatiereDbManager.cs b/src/CalculateurMoyanne/BSN/IMatiereDbManager.cs new file mode 100644 index 0000000..fda77e9 --- /dev/null +++ b/src/CalculateurMoyanne/BSN/IMatiereDbManager.cs @@ -0,0 +1,10 @@ +using System; +using ClassCalculateurMoyenne; +namespace Bussness +{ + public interface IMatiereDbManager : IDataManager + { + Task> GetAllMatiereUE(UE ue); + } +} + diff --git a/src/CalculateurMoyanne/BSN/IUeDbDataManager.cs b/src/CalculateurMoyanne/BSN/IUeDbDataManager.cs new file mode 100644 index 0000000..9164bb7 --- /dev/null +++ b/src/CalculateurMoyanne/BSN/IUeDbDataManager.cs @@ -0,0 +1,12 @@ +using System; +using ClassCalculateurMoyenne; + +namespace Bussness +{ + public interface IUeDbDataManager:IDataManager + { + Task> GetAllUEBloc(BlocModel bloc); + Task AddMatiereUe(UE uE, Matiere matiere); + } +} + diff --git a/src/CalculateurMoyanne/BSN/Manager.cs b/src/CalculateurMoyanne/BSN/Manager.cs index fca785c..5dd28d8 100644 --- a/src/CalculateurMoyanne/BSN/Manager.cs +++ b/src/CalculateurMoyanne/BSN/Manager.cs @@ -21,17 +21,19 @@ namespace Bussness private readonly List matieres = new(); public MaquetteModel SelectedMaquetteModel { get; set; } + public BlocModel SelecteBlocModel { get; set; } + public UE SelectedUe { get; set; } public IDataManager MaquetteDbDataManager => maquetteDbDataManager; private readonly IMaquetteDbManager maquetteDbDataManager; - public IDataManager BlocDbDataManager => blocDbDataManager; - private readonly IDataManager blocDbDataManager; - public IDataManager UeDbDataManager => ueDbDataManager; - private readonly IDataManager ueDbDataManager; - public IDataManager MatiereDbDataManager => matiereDbDataManager; - private readonly IDataManager matiereDbDataManager; + public IBlocDbManager BlocDbDataManager => blocDbDataManager; + private readonly IBlocDbManager blocDbDataManager; + public IUeDbDataManager UeDbDataManager => ueDbDataManager; + private readonly IUeDbDataManager ueDbDataManager; + public IMatiereDbManager MatiereDbDataManager => matiereDbDataManager; + private readonly IMatiereDbManager matiereDbDataManager; #endregion @@ -44,23 +46,23 @@ namespace Bussness maquette = new ReadOnlyCollection(maquettes); } - public Manager(IDataManagerblocmanager) + public Manager( IBlocDbManager blocmanager) { this.blocDbDataManager = blocmanager; bloc = new ReadOnlyCollection(blocs); } - public Manager(IDataManager UeManager) + public Manager(IUeDbDataManager UeManager) { this.ueDbDataManager = UeManager; ue = new ReadOnlyCollection(ues); } - public Manager(IDataManager matiereDbDataManager) + public Manager(IMatiereDbManager matiereDbDataManager) { this.matiereDbDataManager = matiereDbDataManager; matiere = new ReadOnlyCollection(matieres); } - public Manager(IDataManager matiereManager,IDataManager UeManager, IDataManager blocmanager, IMaquetteDbManager maquettemanager) + public Manager(IMatiereDbManager matiereManager, IUeDbDataManager UeManager, IBlocDbManager blocmanager, IMaquetteDbManager maquettemanager) { this.matiereDbDataManager = matiereManager; matiere = new ReadOnlyCollection(matieres); @@ -127,28 +129,60 @@ namespace Bussness return blocDbDataManager.Add(bloc); } - public async Task AddBlocmaquette(MaquetteModel mqt, BlocModel blocModel) + public async Task > GetByMaquette(MaquetteModel maquetteModel) { - var response = maquetteDbDataManager == null; - if (response) + //if (BlocDbDataManager==null) + //{ + // return false; GetAllUEBloc + + //} + return await blocDbDataManager.GetByMaquette(maquetteModel); + } + public async Task> GetAllUEBloc(BlocModel bloc) + { + + return await ueDbDataManager.GetAllUEBloc(bloc); + } + public async Task> GetAllMatiereUE(UE ue) + { + + return await matiereDbDataManager.GetAllMatiereUE(ue); + } + public async Task AddBlocmaquette(MaquetteModel mqt, BlocModel blocModel) + { + + if (maquetteDbDataManager == null) { return false; } return await maquetteDbDataManager.AddBlocmaquette(mqt, blocModel); } + public async Task AddUeBloc(BlocModel bloc, UE uE) + { + + if (BlocDbDataManager == null) + { + return false; + } + + return await blocDbDataManager.AddUeBloc(bloc, uE); + } + + + public async Task AddMatiereUe(UE uE, Matiere matiere) + { + + if (UeDbDataManager == null) + { + return false; + } + + return await ueDbDataManager.AddMatiereUe(uE, matiere); + } - //public Task Adddansbloc(BlocModel bloc) - //{ - // if (blocDbDataManager == null) - // { - // return Task.FromResult(false); - // } - // return blocDbDataManager.Add(bloc); - //} - //Delete bloc public async Task DeleteBloc(BlocModel bl) { if (BlocDbDataManager == null) @@ -157,12 +191,24 @@ namespace Bussness } return await BlocDbDataManager.Delete(bl); } - //public async Task DeleteBlocById(int id) - //{ - - //} + public async Task Deletee(Matiere bl) + { + if (MatiereDbDataManager == null) + { + return false; + } + return await MatiereDbDataManager.Delete(bl); + } + + public async Task DeleteUe(UE data) + { + if (UeDbDataManager == null) + { + return false; + } + return await UeDbDataManager.Delete(data); + } - //Update bloc public async Task UpdateBloc(BlocModel bl) { if (BlocDbDataManager == null) @@ -176,6 +222,19 @@ namespace Bussness { return await BlocDbDataManager.GetAll(); } + //getAllue + public async Task> GetAllue() + { + return await ueDbDataManager.GetAll(); + } + //getallmatieredansue + public async Task> GetAllMatUE() + { + + return await matiereDbDataManager.GetAll(); + } + + #endregion } } diff --git a/src/CalculateurMoyanne/CalculateurApp/App.xaml.cs b/src/CalculateurMoyanne/CalculateurApp/App.xaml.cs index 50eefee..bbd8e83 100644 --- a/src/CalculateurMoyanne/CalculateurApp/App.xaml.cs +++ b/src/CalculateurMoyanne/CalculateurApp/App.xaml.cs @@ -16,17 +16,18 @@ namespace CalculateurApp // MainPage = new NavigationPage(new HomePage()); //MainPage = new AppShell(BlocViewModel c); - // MainPage = new EXE (); + // MainPage = new MatiereView (); - - MainPage = new AppShell(); - // MainPage = new BlockView(); + // MainPage = new AppShell(); + + + MainPage = new HomePage(); } - public Manager manager { get; set; } = new Manager( null, null, new BlocDbDataManager(), new MaquetteDbDataManager()) + public Manager manager { get; set; } = new Manager( new MatiereDbDataManager(), new UeDbDataManager(), new BlocDbDataManager(), new MaquetteDbDataManager()) { }; diff --git a/src/CalculateurMoyanne/CalculateurApp/CalculateurApp.csproj b/src/CalculateurMoyanne/CalculateurApp/CalculateurApp.csproj index 4faf263..6e29791 100644 --- a/src/CalculateurMoyanne/CalculateurApp/CalculateurApp.csproj +++ b/src/CalculateurMoyanne/CalculateurApp/CalculateurApp.csproj @@ -84,24 +84,21 @@ MSBuild:Compile - - MSBuild:Compile - - - MSBuild:Compile - MSBuild:Compile - - MSBuild:Compile - + + + + + + @@ -109,11 +106,13 @@ + + diff --git a/src/CalculateurMoyanne/CalculateurApp/MauiProgram.cs b/src/CalculateurMoyanne/CalculateurApp/MauiProgram.cs index 0e5ce4b..fd6a204 100644 --- a/src/CalculateurMoyanne/CalculateurApp/MauiProgram.cs +++ b/src/CalculateurMoyanne/CalculateurApp/MauiProgram.cs @@ -26,8 +26,9 @@ namespace CalculateurApp builder.Services.AddSingleton(); builder.Services.AddTransient(); builder.Services.AddTransient(); + builder.Services.AddTransient(); - return builder.Build(); + return builder.Build(); } } } \ No newline at end of file diff --git a/src/CalculateurMoyanne/CalculateurApp/View/BlockView.xaml b/src/CalculateurMoyanne/CalculateurApp/View/BlockView.xaml index d0f9d6f..d3f593f 100644 --- a/src/CalculateurMoyanne/CalculateurApp/View/BlockView.xaml +++ b/src/CalculateurMoyanne/CalculateurApp/View/BlockView.xaml @@ -4,8 +4,9 @@ x:Class="CalculateurApp.View.BlockView" xmlns:viewmodel="clr-namespace:CalculateurApp.ViewModel" x:DataType="viewmodel:MaquetteViewModel" - xmlns:model="clr-namespace:ClassCalculateurMoyenne;assembly=ClassCalculateurMoyenne" - Title="BlockView"> + xmlns:model="clr-namespace:ClassCalculateurMoyenne;assembly=ClassCalculateurMoyenne" + Title="BlockView" + Loaded="ContentPage_Loaded"> - + - - + @@ -42,8 +42,7 @@ Command="{Binding Source={RelativeSource AncestorType={x:Type viewmodel:MaquetteViewModel}}, Path=DeleteCommand}" CommandParameter="{Binding .}" /> - - + diff --git a/src/CalculateurMoyanne/CalculateurApp/View/BlockView.xaml.cs b/src/CalculateurMoyanne/CalculateurApp/View/BlockView.xaml.cs index 4f241f9..33bd03c 100644 --- a/src/CalculateurMoyanne/CalculateurApp/View/BlockView.xaml.cs +++ b/src/CalculateurMoyanne/CalculateurApp/View/BlockView.xaml.cs @@ -6,21 +6,33 @@ using Bussness; namespace CalculateurApp.View; -public partial class BlockView : ContentPage +public partial class BlockView : ContentPage, IQueryAttributable { public Manager Manager => (Application.Current as App).manager; + public MaquetteViewModel mvm { get; set; } public BlockView() { InitializeComponent(); - var mvm = new MaquetteViewModel(); + mvm = new MaquetteViewModel(); mvm.manager = Manager; - mvm.init1(); + //mvm.init1(); BindingContext = mvm; } + private async void Aer(object sender, EventArgs e) { //Navigation.PushAsync(new BlockView()); } + + public void ApplyQueryAttributes(IDictionary query) + { + + } + + void ContentPage_Loaded(System.Object sender, System.EventArgs e) + { + mvm.init1(); + } } \ No newline at end of file diff --git a/src/CalculateurMoyanne/CalculateurApp/View/HomePage.xaml b/src/CalculateurMoyanne/CalculateurApp/View/HomePage.xaml index 0fd2032..79b7db4 100644 --- a/src/CalculateurMoyanne/CalculateurApp/View/HomePage.xaml +++ b/src/CalculateurMoyanne/CalculateurApp/View/HomePage.xaml @@ -1,4 +1,4 @@ - + - + --> - + diff --git a/src/CalculateurMoyanne/CalculateurApp/View/Maquette.xaml.cs b/src/CalculateurMoyanne/CalculateurApp/View/Maquette.xaml.cs index a9c1281..329ed1d 100644 --- a/src/CalculateurMoyanne/CalculateurApp/View/Maquette.xaml.cs +++ b/src/CalculateurMoyanne/CalculateurApp/View/Maquette.xaml.cs @@ -16,4 +16,9 @@ public partial class AjtMaquette : ContentPage BindingContext = vm; Routing.RegisterRoute(nameof(BlockView), typeof(BlockView)); } + + private void affichagedesbloks(object sender, EventArgs e) + { + Navigation.PushAsync(new BlockView()); + } } diff --git a/src/CalculateurMoyanne/CalculateurApp/View/MatiereView.xaml b/src/CalculateurMoyanne/CalculateurApp/View/MatiereView.xaml new file mode 100644 index 0000000..5ad0361 --- /dev/null +++ b/src/CalculateurMoyanne/CalculateurApp/View/MatiereView.xaml @@ -0,0 +1,102 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/CalculateurMoyanne/CalculateurApp/View/MatiereView.xaml.cs b/src/CalculateurMoyanne/CalculateurApp/View/MatiereView.xaml.cs new file mode 100644 index 0000000..5639cab --- /dev/null +++ b/src/CalculateurMoyanne/CalculateurApp/View/MatiereView.xaml.cs @@ -0,0 +1,27 @@ +using CalculateurApp.ViewModel; +namespace CalculateurApp.View; +using Bussness; + +public partial class MatiereView : ContentPage +{ + public Manager Manager => (Application.Current as App).manager; + public UeViewModel mvm { get; set; } + + public MatiereView() + { + InitializeComponent(); + mvm = new UeViewModel(); + mvm.manager = Manager; + mvm.init1(); + BindingContext = mvm; + } + + void ContentPage_Loaded(System.Object sender, System.EventArgs e) + { + //mvm.init1(); + } + //private async void pop(object sender, EventArgs e) + //{ + // string result = await DisplayPromptAsync("Question 2", "What's 5 + 5?", initialValue: "10", maxLength: 2, keyboard: Keyboard.Numeric); + //} +} diff --git a/src/CalculateurMoyanne/CalculateurApp/View/Start.xaml.cs b/src/CalculateurMoyanne/CalculateurApp/View/Start.xaml.cs index 37f3ab5..0040e0a 100644 --- a/src/CalculateurMoyanne/CalculateurApp/View/Start.xaml.cs +++ b/src/CalculateurMoyanne/CalculateurApp/View/Start.xaml.cs @@ -8,7 +8,7 @@ public partial class Start : TabbedPage public Start() { InitializeComponent(); - BindingContext = new BlocViewModel(); + //BindingContext = new BlocViewModel(); } public async void ok(object sender, EventArgs e) { diff --git a/src/CalculateurMoyanne/CalculateurApp/View/UeView.xaml b/src/CalculateurMoyanne/CalculateurApp/View/UeView.xaml new file mode 100644 index 0000000..d255d6c --- /dev/null +++ b/src/CalculateurMoyanne/CalculateurApp/View/UeView.xaml @@ -0,0 +1,102 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/CalculateurMoyanne/CalculateurApp/View/UeView.xaml.cs b/src/CalculateurMoyanne/CalculateurApp/View/UeView.xaml.cs new file mode 100644 index 0000000..1826507 --- /dev/null +++ b/src/CalculateurMoyanne/CalculateurApp/View/UeView.xaml.cs @@ -0,0 +1,34 @@ + +using Bussness; +using CalculateurApp.ViewModel; + +namespace CalculateurApp.View; + +public partial class UeView : ContentPage +{ + public Manager Manager => (Application.Current as App).manager; + public BlocViewModel mv { get; set; } + public UeView() + { + InitializeComponent(); + mv = new BlocViewModel(); + mv.manager = Manager; + BindingContext = mv; + mv.init1(); + + } + + + void ContentPage_Loaded(System.Object sender, System.EventArgs e) + { + mv.init1(); + } + + void ContentPage_Loaded_1(System.Object sender, System.EventArgs e) + { + } + + void ContentPage_Loaded_2(System.Object sender, System.EventArgs e) + { + } +} diff --git a/src/CalculateurMoyanne/CalculateurApp/ViewModel/BlocViewModel.cs b/src/CalculateurMoyanne/CalculateurApp/ViewModel/BlocViewModel.cs index 40846a0..3e8418d 100644 --- a/src/CalculateurMoyanne/CalculateurApp/ViewModel/BlocViewModel.cs +++ b/src/CalculateurMoyanne/CalculateurApp/ViewModel/BlocViewModel.cs @@ -6,78 +6,120 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; +using Bussness; using System.Threading.Tasks; +using System.Diagnostics; +using CalculateurApp.View; -namespace CalculateurApp.ViewModel +namespace CalculateurApp.ViewModel; + + +public partial class BlocViewModel:ObservableObject,IQueryAttributable { - - public partial class BlocViewModel:ObservableObject,IQueryAttributable + public UE ue { get; set; } + public Manager manager { get; set; } + public BlocViewModel() + { + Routing.RegisterRoute(nameof(MatiereView), typeof(MatiereView)); + //ue = new UE(); + // Items = new ObservableCollection(); + } + + public void init1() { + Items = new ObservableCollection(); - [ObservableProperty] - string nom; - public BlocModel blocModel { get; set; } - public UE ue { get; set; } - - public BlocViewModel() + try { - Items = new ObservableCollection(); - blocModel=new BlocModel(); - ue = new UE(); + GEtAllUE(); + ue = new UE(); } - [ObservableProperty] - ObservableCollection items; - [ObservableProperty] - string intitulé; - - - [RelayCommand] - void Add() + catch (Exception ex) { - if (string.IsNullOrEmpty(ue.Intitulé)&& string.IsNullOrEmpty(ue.Coefficient.ToString())) - return; - UE u = new UE(ue.Intitulé,ue.Coefficient); - //u.Intitulé = ue.Intitulé; - Items.Add(u); - ue.Intitulé = string.Empty; - ue.Coefficient = 0; + Debug.WriteLine(ex); } - [RelayCommand] - void Delete(UE bl) + + + ue = new UE(); + } + [ObservableProperty] + ObservableCollection items; + [ObservableProperty] + string intitulé; + + [RelayCommand] + async void Add() + { + if (string.IsNullOrEmpty(Intitulé)&& string.IsNullOrEmpty(ue.Coefficient.ToString())) + return; + // ue.Intitulé = Intitulé; + UE u = new UE(Intitulé, ue.Coefficient); + Items.Add(u); + await manager.AddUeBloc(manager.SelecteBlocModel, u); + + } + [RelayCommand] + async void Delete(UE bl) + { + if (Items.Contains(bl)) { - if (Items.Contains(bl)) - { - Items.Remove(bl); - } + Items.Remove(bl); + await manager.DeleteUe(bl); + var y = await manager.GetAllue(); } - [RelayCommand] - void GEtAllUE(UE bl) + + } + [RelayCommand] + async Task Tapp(UE ue) { - if (Items.Contains(bl)) - { - Items.Remove(bl); - } - } + // await Shell.Current.GoToAsync($"{nameof(UE)}?Nom={s}"); + //manager.SelecteBlocModel =blocModel; + //var parametre = new Dictionary + //{ + // {"ue",blocModel} + //}; + //await Shell.Current.GoToAsync($"{nameof(UeView)}",parametre); - [RelayCommand] - async Task GoBack() - { - await Shell.Current.GoToAsync(".."); - } + manager.SelectedUe = ue; + var parametre = new Dictionary + { + {"matiere",ue} + }; + await Shell.Current.GoToAsync($"{nameof(MatiereView)}", parametre); - public void ApplyQueryAttributes(IDictionary query) + } + [RelayCommand] + async Task GoBack() + { + await Shell.Current.GoToAsync(".."); + } + //page + public void ApplyQueryAttributes(IDictionary query) + { + var bloc = query["ue"] as BlocModel; + var ueList = bloc.ue; + ue.IDForeignKey = bloc.Id; + } + [RelayCommand] + void GEtAllUE() + { + items.Clear(); + var result = manager.GetAllUEBloc(manager.SelecteBlocModel); + foreach (var item in result.Result) { - var Maquette = query["maquette"]as MaquetteModel ; + items.Add(item); - blocModel.IDMaquetteFrk = Maquette.Id; } - } + } - - } + + + + + diff --git a/src/CalculateurMoyanne/CalculateurApp/ViewModel/MaquetteViewModel.cs b/src/CalculateurMoyanne/CalculateurApp/ViewModel/MaquetteViewModel.cs index cd5e734..8578945 100644 --- a/src/CalculateurMoyanne/CalculateurApp/ViewModel/MaquetteViewModel.cs +++ b/src/CalculateurMoyanne/CalculateurApp/ViewModel/MaquetteViewModel.cs @@ -15,138 +15,119 @@ using System.Reflection.Metadata; using System.Text; using System.Threading.Tasks; -namespace CalculateurApp.ViewModel; - -public partial class MaquetteViewModel:ObservableObject +namespace CalculateurApp.ViewModel { - - public BlocModel blocModel { get; set; } - // public ReadOnlyObservableCollectionlst { get; set; } - public Manager manager { get; set; } - - - public MaquetteViewModel() + public partial class MaquetteViewModel:ObservableObject { - //Items = new ObservableCollection(); - - //try - //{ - // foreach (var BB in manager.GetAllBloc().Result) - // Items.Add(BB); - //} - //catch (Exception ex) - //{ - // Debug.WriteLine(ex); - //} + public BlocModel blocModel { get; set; } + //public ReadOnlyObservableCollectionlst { get; set; } + public Manager manager { get; set; } - //blocModel = new BlocModel(); - } - public void init1() - { - Items = new ObservableCollection(); - try - { - foreach (var BB in manager.GetAllBloc().Result) - Items.Add(BB); + public MaquetteViewModel() + { //route + Routing.RegisterRoute(nameof(UeView), typeof(UeView)); } - catch (Exception ex) + public void init1() { - Debug.WriteLine(ex); - } + Items = new ObservableCollection(); + try + { + GetAllBloc(); + + blocModel = new BlocModel(); + } + catch (Exception ex) + { + Debug.WriteLine(ex); + } - blocModel = new BlocModel(); - } - [ObservableProperty] - ObservableCollection items; - [ObservableProperty] - ObservableCollection lstblc=new ObservableCollection(); - [ObservableProperty] - string nom; - -[RelayCommand] - async void Add() - { - // Manager blocDbDataManager = new Manager(new BlocDbDataManager()); - - if (string.IsNullOrEmpty(blocModel.Nom)) - return; - //BlocModel u = blocModel; - //MaquetteModel u = new MaquetteModel(); - Items.Add(blocModel); - await manager.AddBlocmaquette(manager.SelectedMaquetteModel, blocModel); - } - [RelayCommand] - async void Delete(BlocModel bl) - - { - if (Items.Contains(bl)) - { - Items.Remove(bl); - await manager.DeleteBloc(bl); - var o = await manager.GetAllBloc(); + blocModel = new BlocModel(); } + [ObservableProperty] + ObservableCollection items; + [ObservableProperty] + string nom; - - //if (Items.Contains(model)) - //{ - // Items.Remove(model); - // await manager.Deletemqt(model); + - // var v = await manager.GetAllMaquette(); - // Console.WriteLine(v); + [RelayCommand] + async void Add() + { + + if (string.IsNullOrEmpty(Nom)) + return; + blocModel.Nom = Nom; + Items.Add(blocModel); + await manager.AddBlocmaquette(manager.SelectedMaquetteModel, blocModel); + + } + [RelayCommand] + async void Delete(BlocModel bl) + + { + if (Items.Contains(bl)) + { + Items.Remove(bl); + await manager.DeleteBloc(bl); + var o = await manager.GetAllBloc(); + } - //} - } - [RelayCommand] - void AjoutUE(BlocModel bl) + } + + [RelayCommand] + void AjoutUE(BlocModel bl) - { - if (Items.Contains(bl)) { - Items.Remove(bl); + if (Items.Contains(bl)) + { + Items.Remove(bl); + } } - } - [RelayCommand] - async Task Tap(String s) - { - await Shell.Current.GoToAsync($"{nameof(UE)}?Nom={s}"); + [RelayCommand] + async Task Tap(BlocModel blocModel) + { + // await Shell.Current.GoToAsync($"{nameof(UE)}?Nom={s}"); + manager.SelecteBlocModel =blocModel; + var parametre = new Dictionary + { + {"ue",blocModel} + }; + await Shell.Current.GoToAsync($"{nameof(UeView)}",parametre); - } - [RelayCommand] - async Task GoBack() - { - await Shell.Current.GoToAsync(".."); - } + } + [RelayCommand] + async Task GoBack() + { + await Shell.Current.GoToAsync(".."); + } - public void ApplyQueryAttributes(IDictionary query) - { - var Maquette = query["maquette"] as MaquetteModel; + public void ApplyQueryAttributes(IDictionary query) - blocModel.IDMaquetteFrk = Maquette.Id; - } - [RelayCommand] - public void GetAllBloc() - { + { - var result = manager.GetAllBloc(); - foreach(var item in result.Result) - { - lstblc.Add(item); + var Maquette = query["maquette"] as MaquetteModel; + blocModel.IDMaquetteFrk = Maquette.Id; } - } + [RelayCommand] + public void GetAllBloc() + { + items.Clear(); - [RelayCommand] - public void Blocview(IEnumerable blocModels) - { - //items.Add + var result = manager.GetByMaquette(manager.SelectedMaquetteModel); + foreach(var item in result.Result) + { + items.Add(item); + + } + } } } diff --git a/src/CalculateurMoyanne/CalculateurApp/ViewModel/MatiereViewModel.cs b/src/CalculateurMoyanne/CalculateurApp/ViewModel/MatiereViewModel.cs new file mode 100644 index 0000000..4663ea3 --- /dev/null +++ b/src/CalculateurMoyanne/CalculateurApp/ViewModel/MatiereViewModel.cs @@ -0,0 +1,11 @@ +using System; +namespace CalculateurApp.ViewModel +{ + public class MatiereViewModel + { + public MatiereViewModel() + { + } + } +} + diff --git a/src/CalculateurMoyanne/CalculateurApp/ViewModel/PageAjoutMaquette.cs b/src/CalculateurMoyanne/CalculateurApp/ViewModel/PageAjoutMaquette.cs index 0c19493..fe0f664 100644 --- a/src/CalculateurMoyanne/CalculateurApp/ViewModel/PageAjoutMaquette.cs +++ b/src/CalculateurMoyanne/CalculateurApp/ViewModel/PageAjoutMaquette.cs @@ -14,16 +14,11 @@ namespace CalculateurApp.ViewModel { public MaquetteModel maquette { get; set; } public Manager manager { get; set; } - - public PageAjoutMaquette() { - //manager = new Manager(new MaquetteDbDataManager()); - - + } - public void Init() { Items = new ObservableCollection(); @@ -43,14 +38,12 @@ namespace CalculateurApp.ViewModel [RelayCommand] async void Add() { - //Manager maquetteDbDataManager = new Manager(new MaquetteDbDataManager()); - if (string.IsNullOrEmpty(NomMaquette)) return; MaquetteModel u = maquette; Items.Add(u); await manager.AddMaquette(maquette); - //maquette.NomMaquette = string.Empty; + } [RelayCommand] @@ -75,21 +68,17 @@ namespace CalculateurApp.ViewModel async void GetAllMaquette() { //Manager maquetteDbDataManager = new Manager(new MaquetteDbDataManager()); - await manager.GetAllMaquette(); } [RelayCommand] - async Task Tap(MaquetteModel maquetteName) - { - manager.SelectedMaquetteModel = maquetteName; - var maquette = manager.GetMaquetteByName(maquetteName.NomMaquette); - + async Task Tap(MaquetteModel maquette) + { + manager.SelectedMaquetteModel = maquette; var parametre = new Dictionary { - {"maquette",maquette} + {"blocs",maquette.BLOCS} }; - - await Shell.Current.GoToAsync($"{nameof(BlockView)}",parametre); + await Shell.Current.GoToAsync($"{nameof(BlockView)}",parametre); } } diff --git a/src/CalculateurMoyanne/CalculateurApp/ViewModel/UeViewModel.cs b/src/CalculateurMoyanne/CalculateurApp/ViewModel/UeViewModel.cs index 115e13f..bc00404 100644 --- a/src/CalculateurMoyanne/CalculateurApp/ViewModel/UeViewModel.cs +++ b/src/CalculateurMoyanne/CalculateurApp/ViewModel/UeViewModel.cs @@ -5,70 +5,107 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; +using Bussness; using System.Text; using System.Threading.Tasks; +using System.Diagnostics; namespace CalculateurApp.ViewModel { - //[QueryProperty("Nom", "Nom")] - public partial class UeViewModel:ObservableObject + + public partial class UeViewModel:ObservableObject, IQueryAttributable { - //[ObservableProperty] - //string nom; - - - public UE u { get; set; } - public Matiere ma { get; set; } + public Manager manager { get; set; } + + public Matiere ma { get; set; } public UeViewModel() { - Tems = new ObservableCollection(); + //Items = new ObservableCollection(); + // ma = new Matiere(); + + //init1(); + + } + public void init1() + { Items = new ObservableCollection(); - + + try + { + GEtAllMatiere(); + ma = new Matiere(); + } + catch (Exception ex) + { + Debug.WriteLine(ex); + } ma = new Matiere(); - u = new UE(); + } + public string Nommatiere + { + get => ma.Nommatiere; + set => SetProperty(ma.Nommatiere, value, ma, (u, v) => u.Nommatiere=v); } [ObservableProperty] ObservableCollection items; + [ObservableProperty] - ObservableCollection tems; - - [ObservableProperty] - string coefficient; + int coefficient; [ObservableProperty] - string nommatiere; + int note; + [RelayCommand] - void Add() + async void Add() { - if (string.IsNullOrEmpty(ma.Nommatiere)) - return; - Matiere m = new Matiere(ma.Nommatiere); - + + Matiere m = new Matiere(ma.Note, ma.Nommatiere, ma.Coef); Items.Add(m); - ma.Nommatiere = string.Empty; + await manager.AddMatiereUe(manager.SelectedUe, m); + + } [RelayCommand] - void AddCoefUE() + async void Delete(Matiere bl) { - - + if (Items.Contains(bl)) + { + Items.Remove(bl); + await manager.Deletee(bl); + var y = await manager.GetAllMatUE(); + } + } + [RelayCommand] - void Delete(Matiere bl) + void GEtAllMatiere() { - if (Items.Contains(bl)) + items.Clear(); + var result = manager.GetAllMatiereUE(manager.SelectedUe); + foreach (var item in result.Result) { - Items.Remove(bl); + items.Add(item); + } + } - //[RelayCommand] - //async Task GoBack() - //{ - // await Shell.Current.GoToAsync(".."); - //} + + + public void ApplyQueryAttributes(IDictionary query) + { + var Ue = query["matiere"] as UE; + var MATList = Ue.Matieres; + ma.IDUEForeignKey = Ue.Id; + + + //var bloc = query["ue"] as BlocModel; + //var ueList = bloc.ue; + //ue.IDForeignKey = bloc.Id; + + } } } diff --git a/src/CalculateurMoyanne/CalculateurEF/Entities/MatiereEntity.cs b/src/CalculateurMoyanne/CalculateurEF/Entities/MatiereEntity.cs index d37c751..e96c8ec 100644 --- a/src/CalculateurMoyanne/CalculateurEF/Entities/MatiereEntity.cs +++ b/src/CalculateurMoyanne/CalculateurEF/Entities/MatiereEntity.cs @@ -10,9 +10,10 @@ namespace CalculateurEF.Entities public class MatiereEntity { public string Nommatiere { get; set; } - public long id { get; set; } + public long Id { get; set; } public int Note { get; set; } public int Coef { get; set; } + public long IDUEForeignKey { get; set; @@ -23,5 +24,7 @@ namespace CalculateurEF.Entities get; set; } + + } } diff --git a/src/CalculateurMoyanne/CalculateurMapping/BlocDbDataManager.cs b/src/CalculateurMoyanne/CalculateurMapping/BlocDbDataManager.cs index d444526..c7d306c 100644 --- a/src/CalculateurMoyanne/CalculateurMapping/BlocDbDataManager.cs +++ b/src/CalculateurMoyanne/CalculateurMapping/BlocDbDataManager.cs @@ -4,6 +4,7 @@ using CalculateurEF.Entities; using ClassCalculateurMoyenne; using Microsoft.EntityFrameworkCore; using System; +using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Linq; @@ -12,7 +13,7 @@ using System.Threading.Tasks; namespace CalculateurMapping { - public class BlocDbDataManager: IDataManager where TContext :CalculContext,new() + public class BlocDbDataManager: IBlocDbManager where TContext :CalculContext,new() {//ajout de bloc public async Task Add(BlocModel blc) { @@ -57,14 +58,28 @@ namespace CalculateurMapping } return true; } - public async TaskGetByMaquette(MaquetteModel maquette) { + public async Task>GetByMaquette(MaquetteModel maquetteModel) { - + List blocModels = new List(); using (var context = new TContext()) { - // + + var maq = await context.Maquettes.Include(m => m.Bloc) + .SingleOrDefaultAsync(x => x.Id == maquetteModel.Id); + if (maq == null) return new List(); + + foreach (var e in maq.Bloc) + { + blocModels.Add(new BlocModel + { + Id = e.Id, + Nom = e.Nom, + IDMaquetteFrk = e.IDMaquetteFrk, + }); + } + return blocModels.AsEnumerable(); } - return true; + } @@ -81,24 +96,25 @@ namespace CalculateurMapping return temp; } }//getUEdansblc - public async Task> GetAllUEBloc(int id) - { - List ls=new List(); - using (var context = new TContext()) - { - var temp = context.Bloc.Where(x=>x.Id==id).Select(e => e.UeEntityId).ToList(); - foreach (var item in temp) - { - foreach (var i in item) - { - UE ue = new UE(i.Id, i.Coefficient, i.intitulé, i.mat.Select(m => new Matiere(m.id, m.Note, m.Nommatiere, m.Coef)).ToArray()); - ls.Add(ue); - } - } + //public async Task> GetAllUEBloc(int id) + //{ + // List ls=new List(); + // using (var context = new TContext()) + // { + // var temp = context.Bloc.Where(x=>x.Id==id).Select(e => e.UeEntityId).ToList(); + // foreach (var item in temp) + // { + // foreach (var i in item) + // { + // UE ue = new UE(i.Id, i.Coefficient, i.intitulé, i.mat.Select(m => new Matiere(m.id, m.Note, m.Nommatiere, m.Coef)).ToArray()); + // ls.Add(ue); + // } + // } - return ls; - } - } + // return ls; + // } + + //} public async Task GetDataWithName(string name) { @@ -129,21 +145,53 @@ namespace CalculateurMapping return result; } - public async Task AddUEBloc(UE data,int blocId) - {//addUedansbloc - bool resultat = false; + //public async Task AddUEBloc(UE data,int blocId) + //{//addUedansbloc + // bool resultat = false; + // using (var context = new TContext()) + // { + // UEentity entity = new UEentity + // { + // intitulé = data.Intitulé, + // IDForeignKey = blocId, + // }; + // context.Ue.Add(entity); + // await context.SaveChangesAsync(); + // resultat = true; + // return resultat; + // } + //} + public async Task AddUeBloc(BlocModel bloc, UE uE) + { + bool result = false; using (var context = new TContext()) { - UEentity entity = new UEentity + BlocEntity data = await context.Bloc.FindAsync(bloc.Id); + if (data != null) { - intitulé = data.Intitulé, - IDForeignKey = blocId, - }; - context.Ue.Add(entity); - await context.SaveChangesAsync(); - resultat = true; - return resultat; + UEentity entity = new UEentity + { + Id=uE.Id, + intitulé = uE.Intitulé, + Coefficient=uE.Coefficient, + BlocEntity = new BlocEntity + { + Id = bloc.Id, + Nom = bloc.Nom + }, + }; + if (!data.UeEntityId.Contains(entity)) + { + data.UeEntityId.Add(entity); + context.Bloc.Update(data); + result = await context.SaveChangesAsync() > 0; + } + } + return result; } + } + + } } diff --git a/src/CalculateurMoyanne/CalculateurMapping/MaquetteDbDataManager.cs b/src/CalculateurMoyanne/CalculateurMapping/MaquetteDbDataManager.cs index cbfb3cf..64845d1 100644 --- a/src/CalculateurMoyanne/CalculateurMapping/MaquetteDbDataManager.cs +++ b/src/CalculateurMoyanne/CalculateurMapping/MaquetteDbDataManager.cs @@ -40,8 +40,7 @@ namespace CalculateurMapping //ajt de bloc public async Task AddBlocmaquette(MaquetteModel mqt,BlocModel blocModel) - { //Add mqt - + { bool result = false; using (var context = new TContext()) { @@ -57,21 +56,15 @@ namespace CalculateurMapping Id = mqt.Id, NomMaquette = mqt.NomMaquette }, - }; - if (!data.Bloc.Contains(entity)) { - data.Bloc.Add(entity); - // await context.Maquettes.AddAsync(data); - // Console.WriteLine("jyij"); - context.Maquettes.Update(data); - - result = await context.SaveChangesAsync() > 0; + data.Bloc.Add(entity); + context.Maquettes.Update(data); + result = await context.SaveChangesAsync() > 0; } } - //context.Database.EnsureCreated(); - + return result; } @@ -114,25 +107,7 @@ namespace CalculateurMapping return result; } - //public async Task> GetAll() - //{ - // using (var context = new CalculContext()) - // { - // return await context.Maquettes.Select(I => new MaquetteModel - // ( - // I.Id, - // I.NomMaquette, - // I.Bloc.Select(u => - // u.ue.Select(uee => new UE(uee.Id, uee.Coefficient, uee.intitulé, - // uee.mat.Select(ma => new Matiere(ma.id, ma.Note,ma.Nommatiere,ma.Coef)).ToArray() - // )).ToList() - // ), - // I.Bloc.Select(j => new BlocModel(j.Nom)).ToArray() - // )).ToListAsync(); - // } - // return null; - // } - + public async Task GetDataWithName(string name) { @@ -177,9 +152,6 @@ namespace CalculateurMapping } } - public Task AddUEBloc(UE data, int blocId) - { - throw new NotImplementedException(); - } + } } diff --git a/src/CalculateurMoyanne/CalculateurMapping/MatiereDbDataManager.cs b/src/CalculateurMoyanne/CalculateurMapping/MatiereDbDataManager.cs index 4fa8a43..e0f4249 100644 --- a/src/CalculateurMoyanne/CalculateurMapping/MatiereDbDataManager.cs +++ b/src/CalculateurMoyanne/CalculateurMapping/MatiereDbDataManager.cs @@ -11,7 +11,7 @@ using System.Threading.Tasks; namespace CalculateurMapping { - public class MatiereDbDataManager : IDataManager + public class MatiereDbDataManager :IMatiereDbManager where TContext : CalculContext, new() { //Maping entre la classe Matier et MatiereEntity public async Task Add(Matiere data) { @@ -20,7 +20,7 @@ namespace CalculateurMapping { MatiereEntity entity = new MatiereEntity { - Nommatiere = data.GetNommatiere(), + Nommatiere = data.Nommatiere, }; context.matier.Add(entity); @@ -39,27 +39,30 @@ namespace CalculateurMapping public async Task Delete(Matiere mat) { bool result = false; - using (var Context = new CalculContext()) + using (var Context = new TContext()) { - MatiereEntity entity = Context.matier.Find(mat.GetNommatiere()); + MatiereEntity entity = Context.matier.Find(mat.Id); Context.matier.Remove(entity); result = await Context.SaveChangesAsync() > 0; } return result; } + + public async Task> GetAll() { - using (var context = new CalculContext()) + using (var context = new TContext()) { return await context.matier.Select(e => new Matiere - (e.id, + (e.Id, e.Note, e.Nommatiere, e.Coef )).ToListAsync(); } } + public Task GetDataWithName(string name) { @@ -82,5 +85,32 @@ namespace CalculateurMapping } + public async Task> GetAllMatiereUE(UE ue) + { + List ls = new List(); + using (var context = new TContext()) + { + var BLC = await context.Ue.Include(m => m.mat) + .SingleOrDefaultAsync(x => x.Id == ue.Id); + + if (BLC == null) return new List(); + foreach (var e in BLC.mat) + { + ls.Add(new Matiere + { + Id=e.Id, + Note=e.Note, + Nommatiere=e.Nommatiere, + Coef=e.Coef + + + }); + + } + } + return ls; + + } + } } diff --git a/src/CalculateurMoyanne/CalculateurMapping/UeDbDataManager.cs b/src/CalculateurMoyanne/CalculateurMapping/UeDbDataManager.cs index 0a38093..5453cc6 100644 --- a/src/CalculateurMoyanne/CalculateurMapping/UeDbDataManager.cs +++ b/src/CalculateurMoyanne/CalculateurMapping/UeDbDataManager.cs @@ -12,12 +12,49 @@ using System.Threading.Tasks; namespace CalculateurMapping { - public class UeDbDataManager : IDataManager + public class UeDbDataManager : IUeDbDataManager where TContext:CalculContext,new () { + + public async Task AddMatiereUe( UE uE,Matiere matiere) + { + bool result = false; + using (var context = new TContext()) + { + UEentity data = await context.Ue.FindAsync(uE.Id); + if (data != null) + { + MatiereEntity entity = new MatiereEntity + { + Id = matiere.Id, + Note=matiere.Note, + Nommatiere = matiere.Nommatiere, + Coef = matiere.Coef, + UEentity = new UEentity + { + Id = uE.Id, + intitulé = uE.Intitulé + }, + }; + if (!data.mat.Contains(entity)) + { + data.mat.Add(entity); + context.Ue.Update(data); + result = await context.SaveChangesAsync() > 0; + } + } + return result; + } + + } + + + + + public async Task Add(UE data) { bool resultat = false; - using (var context = new CalculContext()) + using (var context = new TContext()) { UEentity entity = new UEentity { @@ -36,29 +73,22 @@ namespace CalculateurMapping } return resultat; } - } - - public Task AddUEBloc(UE data, int blocId) - { - throw new NotImplementedException(); - } - + } public async Task Delete(UE data) { bool result = false; - using (var context = new CalculContext()) + using (var context = new TContext()) { - UEentity entity = context.Ue.Find(data.Intitulé); + UEentity entity = context.Ue.Find(data.Id); context.Ue.Remove(entity); result = await context.SaveChangesAsync() > 0; } return true; } - public async Task> GetAll() { - using (var context = new CalculContext()) + using (var context = new TContext()) { return await context.Ue.Select(e => new UE ( @@ -69,7 +99,6 @@ namespace CalculateurMapping )).ToListAsync(); } } - public Task GetDataWithName(string name) { throw new NotImplementedException(); @@ -78,7 +107,7 @@ namespace CalculateurMapping public async Task Update(UE data) { bool result = false; - using (var context = new CalculContext()) + using (var context = new TContext()) { UEentity entity = context.Ue.Find(data.Id); entity.intitulé = data.Intitulé; @@ -90,5 +119,30 @@ namespace CalculateurMapping } return result; } + + public async Task> GetAllUEBloc(BlocModel bloc) + { + List ls=new List(); + using (var context = new TContext()) + { + var BLC = await context.Bloc.Include(m => m.UeEntityId) + .SingleOrDefaultAsync(x => x.Id == bloc.Id); + + if (BLC == null) return new List(); + foreach (var e in BLC.UeEntityId) + { + ls.Add(new UE + { + Id = e.Id, + Intitulé = e.intitulé, + Coefficient=e.Coefficient, + IDForeignKey = e.IDForeignKey, + }); + + } + } + return ls; + + } } } diff --git a/src/CalculateurMoyanne/CalculateurStub/Stub/StubBloc.cs b/src/CalculateurMoyanne/CalculateurStub/Stub/StubBloc.cs index dced14d..76aa0b1 100644 --- a/src/CalculateurMoyanne/CalculateurStub/Stub/StubBloc.cs +++ b/src/CalculateurMoyanne/CalculateurStub/Stub/StubBloc.cs @@ -10,7 +10,7 @@ using System.Threading.Tasks; namespace StubCalculateur.Stub { - public class StubBloc: IDataManager + public class StubBloc: IBlocDbManager { private List listb = new List(); public List ue = new List(); @@ -86,6 +86,16 @@ namespace StubCalculateur.Stub { throw new NotImplementedException(); } + + public Task> GetByMaquette(MaquetteModel maquetteModel) + { + throw new NotImplementedException(); + } + + public Task AddUeBloc(BlocModel bloc, UE uE) + { + throw new NotImplementedException(); + } } diff --git a/src/CalculateurMoyanne/CalculateurStub/Stub/stubUE.cs b/src/CalculateurMoyanne/CalculateurStub/Stub/stubUE.cs index ef36ee9..695040c 100644 --- a/src/CalculateurMoyanne/CalculateurStub/Stub/stubUE.cs +++ b/src/CalculateurMoyanne/CalculateurStub/Stub/stubUE.cs @@ -9,7 +9,7 @@ using System.Threading.Tasks; namespace StubCalculateur.Stub { - public class stubUE : IDataManager + public class stubUE : IUeDbDataManager { private List listUE = new List(); private List mat = new List(); @@ -81,5 +81,15 @@ namespace StubCalculateur.Stub { throw new NotImplementedException(); } + + public Task> GetAllUEBloc(BlocModel bloc) + { + throw new NotImplementedException(); + } + + public Task AddMatiereUe(UE uE, Matiere matiere) + { + throw new NotImplementedException(); + } } } diff --git a/src/CalculateurMoyanne/ClassCalculateurMoyenne/Modele/BlocModel.cs b/src/CalculateurMoyanne/ClassCalculateurMoyenne/Modele/BlocModel.cs index 9864e98..bca90e3 100644 --- a/src/CalculateurMoyanne/ClassCalculateurMoyenne/Modele/BlocModel.cs +++ b/src/CalculateurMoyanne/ClassCalculateurMoyenne/Modele/BlocModel.cs @@ -21,7 +21,7 @@ namespace ClassCalculateurMoyenne public int Id { get; - private set; + set; } public void setNom(string value) { @@ -73,19 +73,7 @@ namespace ClassCalculateurMoyenne Id = id; this.uEs = uEs; } - //public int ueForeignKey - //{ - // get; set; - //} - //[ForeignKey("ueForeignKey")] - //public UE UE - //{ - // get; set; - //} - - //public BlocModel(string v) - //{ - //} + public BlocModel() { diff --git a/src/CalculateurMoyanne/ClassCalculateurMoyenne/Modele/Matiere.cs b/src/CalculateurMoyanne/ClassCalculateurMoyenne/Modele/Matiere.cs index db09489..1cc8a59 100644 --- a/src/CalculateurMoyanne/ClassCalculateurMoyenne/Modele/Matiere.cs +++ b/src/CalculateurMoyanne/ClassCalculateurMoyenne/Modele/Matiere.cs @@ -7,26 +7,51 @@ using System.Threading.Tasks; namespace ClassCalculateurMoyenne { - public class Matiere + public partial class Matiere : ObservableObject, IEquatable { public long Id { get; set; } - - public string Nommatiere; - public int Note { get; private set; } - public int Coef { get; private set; } - public string GetNommatiere() + public long IDUEForeignKey { get; set; } + [ObservableProperty] + private int note; + [ObservableProperty] + private int coef; + private string nommatiere; + public string Nommatiere { - return Nommatiere; - } + get { return nommatiere; } + set + { + if (string.IsNullOrWhiteSpace(value)) - private void SetNomMaquette(string value) - { - this.Nommatiere = value; - + { + throw new ArgumentException("Le Nom de la maquette est obligatoire"); + } + + nommatiere = value; + } } + //public void setNomMatier(string value) + //{ + // Nommatiere = value; + + //} + + + //private void SetNomMaquette(string value) + //{ + // if (string.IsNullOrEmpty(value)) - public Matiere(long id ,int note, string nommatiere, int coef) + // { + // throw new ArgumentException("Nommatiere est obligatoire"); + // } + + // this.Nommatiere = value; + + //} + + + public Matiere(long id, int note, string nommatiere, int coef) { Id = id; Coef = coef; @@ -34,6 +59,16 @@ namespace ClassCalculateurMoyenne Note = note; } + + public Matiere( int note, string nommatiere, int coef) + { + + Coef = coef; + Nommatiere = nommatiere; + Note = note; + + } + public Matiere(string nommatiere) { Nommatiere = nommatiere; @@ -45,7 +80,26 @@ namespace ClassCalculateurMoyenne public override string ToString() { - return $"{Nommatiere},{Note},{Coef}"; + return $"{Id},{Nommatiere},{Note},{Coef}"; + } + + + public bool Equals(Matiere other) + { + return Nommatiere.Equals(other.Nommatiere); + } + public override bool Equals(object obj) + { + if (ReferenceEquals(obj, null)) return false; + if (ReferenceEquals(obj, this)) return true; + if (GetType() != obj.GetType()) return false; + return Equals(obj as Matiere); } + public override int GetHashCode() + { + return Nommatiere.GetHashCode(); + } + + } } diff --git a/src/CalculateurMoyanne/ClassCalculateurMoyenne/Modele/UE.cs b/src/CalculateurMoyanne/ClassCalculateurMoyenne/Modele/UE.cs index 5a100ec..5bb84a3 100644 --- a/src/CalculateurMoyanne/ClassCalculateurMoyenne/Modele/UE.cs +++ b/src/CalculateurMoyanne/ClassCalculateurMoyenne/Modele/UE.cs @@ -10,7 +10,6 @@ namespace ClassCalculateurMoyenne [ObservableProperty] private int coefficient; [ObservableProperty] - private string intitulé; public int IDForeignKey { get; set; } @@ -67,7 +66,7 @@ namespace ClassCalculateurMoyenne public bool Equals(UE other) { - return matieres.Equals(other.matieres); + return Intitulé.Equals(other.GetIntitulé()); } public override bool Equals(object obj) { @@ -78,7 +77,7 @@ namespace ClassCalculateurMoyenne } public override int GetHashCode() { - return Matieres.GetHashCode(); + return intitulé.GetHashCode(); } public IEnumerable AjouterMatiere(params Matiere[] matieres) { @@ -108,11 +107,8 @@ namespace ClassCalculateurMoyenne { matieres.Remove(matiere); } - //public void ajtCoef(int Coefficient) - //{ - // UE.Add(Coefficient); - //} - + + } } diff --git a/src/Tests/TestCalculateurMoyanne/LesTests/TEST.cs b/src/Tests/TestCalculateurMoyanne/LesTests/TEST.cs index a0b7013..c5801d8 100644 --- a/src/Tests/TestCalculateurMoyanne/LesTests/TEST.cs +++ b/src/Tests/TestCalculateurMoyanne/LesTests/TEST.cs @@ -6,57 +6,21 @@ using Xunit; namespace TestCalculateurMoyanne.LesTests { - public class TestManager + public class Test { - [Fact] - public void TestAddMaquette() - { - MaquetteModel maquette = new MaquetteModel("B1"); - Manager manager = new Manager(new StubMaquette()); - manager.AddMaquette(maquette); - Assert.Single(manager.MaquetteDbDataManager.GetAll().Result); - } - [Fact] - public void TestAddBloc() - { - BlocModel bloc = new BlocModel("B1"); - Manager manager = new Manager(new StubBloc()); - manager.AddBloc (bloc); - Assert.Single(manager.BlocDbDataManager.GetAll().Result); - } - [Fact] - public void TestGetUEBloc() - { - BlocModel bloc = new BlocModel("B1"); - Manager manager = new Manager(new StubBloc()); - manager.AddBloc(bloc); + Matiere m = new Matiere(2, "ALGO", 3); - } [Fact] - public void TestDELETEBloc() + public void TestONS() { - BlocModel bloc = new BlocModel("B1"); - Manager manager = new Manager(new StubBloc()); - manager.DeleteBloc(bloc); - + Assert.NotNull(m); + Assert.Equal(2, m.Note); + Assert.Equal("ALGO", m.Nommatiere); + Assert.Equal(3, m.Coef); + Assert.NotEqual(21, m.Note); + Assert.NotEqual("GO", m.Nommatiere); + Assert.NotEqual(33, m.Coef); } - public void TestUpdateBloc() - { - BlocModel bloc = new BlocModel("B1"); - Manager manager = new Manager(new StubBloc()); - manager.UpdateBloc( bloc); - - } - [Fact] - public void TestGetAllTEBloc() - { - BlocModel bloc = new BlocModel("B1"); - Manager manager = new Manager(new StubBloc()); - manager.GetAllBloc(); - - } - - } -} +} \ No newline at end of file diff --git a/src/Tests/TestCalculateurMoyanne/LesTests/TestManager.cs b/src/Tests/TestCalculateurMoyanne/LesTests/TestManager.cs index 8206070..a0b7013 100644 --- a/src/Tests/TestCalculateurMoyanne/LesTests/TestManager.cs +++ b/src/Tests/TestCalculateurMoyanne/LesTests/TestManager.cs @@ -4,8 +4,6 @@ using ClassCalculateurMoyenne; using Bussness; using Xunit; - - namespace TestCalculateurMoyanne.LesTests { public class TestManager diff --git a/src/Tests/TestCalculateurMoyanne/LesTests/UnitTestBloc.cs b/src/Tests/TestCalculateurMoyanne/LesTests/UnitTestBloc.cs index 05ece9c..c89db22 100644 --- a/src/Tests/TestCalculateurMoyanne/LesTests/UnitTestBloc.cs +++ b/src/Tests/TestCalculateurMoyanne/LesTests/UnitTestBloc.cs @@ -27,26 +27,6 @@ namespace TestCalculateurMoyanne.LesTests } - // public class Bloc_InlineData - // { - // [Theory] - // [InlineData(false, "L6", 2, "L3", 2)] - // [InlineData(false, "", 0, "", 0)] - // [InlineData(true, "M1", 0, "M1", 0)] - - // public void TestConstructeur(bool isValid, string expectedNom, int expectedId, - // string Nom, int id) - // { - // if (!isValid) - // { - // Assert.Throws(() => new MaquetteModel(Nom, id)); - // return; - // } - // BlocModel m = new BlocModel(Nom, id); - // Assert.Equal(expectedNom, m.Nom); - // Assert.Equal(expectedId, m.Id); - // } - // } [Fact] public void TestBlocStub() { diff --git a/src/Tests/TestCalculateurMoyanne/LesTests/UnitTestMaquette.cs b/src/Tests/TestCalculateurMoyanne/LesTests/UnitTestMaquette.cs index 571978c..c2375f3 100644 --- a/src/Tests/TestCalculateurMoyanne/LesTests/UnitTestMaquette.cs +++ b/src/Tests/TestCalculateurMoyanne/LesTests/UnitTestMaquette.cs @@ -25,25 +25,7 @@ namespace TestCalculateurMoyanne.LesTests Assert.Throws(() => new MaquetteModel(null)); } - //[Theory] - //[InlineData(false, "L6" ,"L3")] - //[InlineData(false, "", "")] - //[InlineData(true, "M1", "M1" )] - //public void TestConstructor(bool isValid, string expectedNomMaquette, - // string NomMaquette) - //{ - // if (!isValid) - // { - // Assert.Throws( () => new MaquetteModel(NomMaquette)); - // return; - // } - - // MaquetteModel m = new MaquetteModel(NomMaquette); - // Assert.Equal(expectedNomMaquette, m.GetNomMaquette()); - - //} - // test avec stub - + [Fact] public void TestMaquetteStub() { diff --git a/src/Tests/TestCalculateurMoyanne/LesTests/UnitTestUE.cs b/src/Tests/TestCalculateurMoyanne/LesTests/UnitTestUE.cs index bae48f9..5e6a63c 100644 --- a/src/Tests/TestCalculateurMoyanne/LesTests/UnitTestUE.cs +++ b/src/Tests/TestCalculateurMoyanne/LesTests/UnitTestUE.cs @@ -17,7 +17,7 @@ namespace TestCalculateurMoyanne.LesTests [Fact] public void Test() { - Assert.NotNull(u); + Assert.NotNull(u); Assert.Equal("f", u.Intitulé); Assert.NotEqual("oo", u.Intitulé); }