From c20cdf7761ef5873669bb2c866cce09b881dd018 Mon Sep 17 00:00:00 2001 From: Alexis DRAI Date: Wed, 1 Feb 2023 17:04:15 +0100 Subject: [PATCH] Finish dekete an item --- blazor_lab/App.razor | 26 +++++++------ blazor_lab/Modals/DeleteConfirmation.razor | 10 +++++ blazor_lab/Modals/DeleteConfirmation.razor.cs | 38 +++++++++++++++++++ blazor_lab/Pages/List.razor | 3 ++ blazor_lab/Pages/List.razor.cs | 33 +++++++++++++++- blazor_lab/Pages/_Layout.cshtml | 2 + blazor_lab/Program.cs | 2 + blazor_lab/_Imports.razor | 2 + blazor_lab/blazor_lab.csproj | 1 + new 1.txt | 36 ++++++++++++++++++ 10 files changed, 139 insertions(+), 14 deletions(-) create mode 100644 blazor_lab/Modals/DeleteConfirmation.razor create mode 100644 blazor_lab/Modals/DeleteConfirmation.razor.cs create mode 100644 new 1.txt diff --git a/blazor_lab/App.razor b/blazor_lab/App.razor index 623580d..6346f35 100644 --- a/blazor_lab/App.razor +++ b/blazor_lab/App.razor @@ -1,12 +1,14 @@ - - - - - - - Not found - -

Sorry, there's nothing at this address.

-
-
-
+ + + + + + + + Not found + +

Sorry, there's nothing at this address.

+
+
+
+
\ No newline at end of file diff --git a/blazor_lab/Modals/DeleteConfirmation.razor b/blazor_lab/Modals/DeleteConfirmation.razor new file mode 100644 index 0000000..93f7a46 --- /dev/null +++ b/blazor_lab/Modals/DeleteConfirmation.razor @@ -0,0 +1,10 @@ +
+ +

+ Are you sure you want to delete @item.DisplayName ? +

+ + + + +
\ No newline at end of file diff --git a/blazor_lab/Modals/DeleteConfirmation.razor.cs b/blazor_lab/Modals/DeleteConfirmation.razor.cs new file mode 100644 index 0000000..26d6c66 --- /dev/null +++ b/blazor_lab/Modals/DeleteConfirmation.razor.cs @@ -0,0 +1,38 @@ +using blazor_lab.Models; +using blazor_lab.Services; +using Blazored.Modal.Services; +using Blazored.Modal; +using Microsoft.AspNetCore.Components; + +namespace blazor_lab.Modals +{ + public partial class DeleteConfirmation + { + [CascadingParameter] + public BlazoredModalInstance ModalInstance { get; set; } + + [Inject] + public IDataService DataService { get; set; } + + [Parameter] + public int Id { get; set; } + + private Item item = new(); + + protected override async Task OnInitializedAsync() + { + // Get the item + item = await DataService.GetById(Id); + } + + void ConfirmDelete() + { + ModalInstance.CloseAsync(ModalResult.Ok(true)); + } + + void Cancel() + { + ModalInstance.CancelAsync(); + } + } +} diff --git a/blazor_lab/Pages/List.razor b/blazor_lab/Pages/List.razor index 4869c01..90d945b 100644 --- a/blazor_lab/Pages/List.razor +++ b/blazor_lab/Pages/List.razor @@ -55,6 +55,9 @@ Editer + diff --git a/blazor_lab/Pages/List.razor.cs b/blazor_lab/Pages/List.razor.cs index f5f5870..ab6c643 100644 --- a/blazor_lab/Pages/List.razor.cs +++ b/blazor_lab/Pages/List.razor.cs @@ -1,6 +1,8 @@ -using blazor_lab.Models; +using blazor_lab.Modals; +using blazor_lab.Models; using blazor_lab.Services; -using Blazored.LocalStorage; +using Blazored.Modal; +using Blazored.Modal.Services; using Blazorise.DataGrid; using Microsoft.AspNetCore.Components; @@ -18,6 +20,12 @@ namespace blazor_lab.Pages [Inject] public IWebHostEnvironment WebHostEnvironment { get; set; } + [Inject] + public NavigationManager NavigationManager { get; set; } + + [CascadingParameter] + public IModalService Modal { get; set; } + protected override async Task OnAfterRenderAsync(bool firstRender) { // Do not treat this action if is not the first render @@ -47,5 +55,26 @@ namespace blazor_lab.Pages { items = await DataService.List(1, 10); } + + private async Task OnDeleteAsync(int id) + { + var parameters = new ModalParameters + { + { nameof(Item.Id), id } + }; + + var modal = Modal.Show("Delete Confirmation", parameters); + var result = await modal.Result; + + if (result.Cancelled) + { + return; + } + + await DataService.Delete(id); + + // Reload the page + NavigationManager.NavigateTo("list", true); + } } } diff --git a/blazor_lab/Pages/_Layout.cshtml b/blazor_lab/Pages/_Layout.cshtml index e4979ec..44f8e88 100644 --- a/blazor_lab/Pages/_Layout.cshtml +++ b/blazor_lab/Pages/_Layout.cshtml @@ -28,6 +28,8 @@ + + diff --git a/blazor_lab/Program.cs b/blazor_lab/Program.cs index e04d440..6d7195f 100644 --- a/blazor_lab/Program.cs +++ b/blazor_lab/Program.cs @@ -4,6 +4,7 @@ using Blazorise.Bootstrap; using Blazorise.Icons.FontAwesome; using Blazored.LocalStorage; using blazor_lab.Services; +using Blazored.Modal; var builder = WebApplication.CreateBuilder(args); @@ -22,6 +23,7 @@ builder.Services builder.Services.AddBlazoredLocalStorage(); builder.Services.AddScoped(); +builder.Services.AddBlazoredModal(); var app = builder.Build(); diff --git a/blazor_lab/_Imports.razor b/blazor_lab/_Imports.razor index e00a243..3f34174 100644 --- a/blazor_lab/_Imports.razor +++ b/blazor_lab/_Imports.razor @@ -9,3 +9,5 @@ @using blazor_lab @using blazor_lab.Shared @using Blazorise.DataGrid +@using Blazored.Modal +@using Blazored.Modal.Services \ No newline at end of file diff --git a/blazor_lab/blazor_lab.csproj b/blazor_lab/blazor_lab.csproj index c45c8d4..4828a26 100644 --- a/blazor_lab/blazor_lab.csproj +++ b/blazor_lab/blazor_lab.csproj @@ -8,6 +8,7 @@ + diff --git a/new 1.txt b/new 1.txt new file mode 100644 index 0000000..ae90653 --- /dev/null +++ b/new 1.txt @@ -0,0 +1,36 @@ +TP2 + 1 + A +Le problème reader/writer est différent. +Dans notre cas, on veut que des clients et des patissiers accèdent à une ressource partagée ; l'une en "lecture", l'autre en "écriture" +Mais on veut aussi empêcher un client de prendre une patisserie s'il n'yen a aucune de prete, par exemple. +Ca ressemble beaucoup plus à un problème producer/consumer. + + B +La boutique peut jouer le role de moniteur, comme elle gère les inputs outputs et connait le stock +Elle définit un buffer de taille n, puis +put() { + if(getstock() == n) { + notFull.await(); // ne pas ajouter si plein + } + /* + do the putting ... + */ + // stock++ if necessary + notEmpty.signal(); // annoncer que non vide +} +Symmétriquement, +get() { + if(getstock() == 0) { + notEmpty.await(); // ne pas prendre si vide + } + /* + do the getting ... + */ + // stock-- if necessary + notFull.signal(); // annoncer que non plein +} + +Avec un arrayList, on pourra / devra implémenter un buffer circulaire, càd tracer la tete et la queue en indexes variables qu'on incrémente, modulo, tout le bazar + +Depuis le main, on start() les Customers et PastryChefs qui héritent de Runnable \ No newline at end of file