Suppression code inutile

merged_APE
Antoine PINAGOT 1 year ago
parent f223bd6a79
commit bb4e8620f1

@ -3,25 +3,13 @@
using Microsoft.AspNetCore.Localization;
using Microsoft.AspNetCore.Mvc;
/// <summary>
/// The culture controller.
/// </summary>
[Route("[controller]/[action]")]
public class CultureController : Controller
{
/// <summary>
/// Sets the culture.
/// </summary>
/// <param name="culture">The culture.</param>
/// <param name="redirectUri">The redirect URI.</param>
/// <returns>
/// The action result.
/// </returns>
public IActionResult SetCulture(string culture, string redirectUri)
{
if (culture != null)
{
// Define a cookie with the selected culture
this.HttpContext.Response.Cookies.Append(
CookieRequestCultureProvider.DefaultCookieName,
CookieRequestCultureProvider.MakeCookieValue(

@ -1,32 +0,0 @@
using HeartTrack.Models;
using static MudBlazor.CategoryTypes;
namespace HeartTrack.Factories
{
public static class TicketFactory
{
public static TicketModel ToModel(Ticket item)
{
return new TicketModel
{
Id = item.Id,
Username = item.Username,
Contexte = item.Contexte,
Description = item.Description,
Urgence = Convert.ToBoolean(item.Urgence)
};
}
public static Ticket Create(TicketModel model)
{
return new Ticket
{
Id = model.Id,
Username = model.Username,
Contexte = model.Contexte,
Description = model.Description,
Urgence = Convert.ToString(model.Urgence)
};
}
}
}

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
@ -20,12 +20,8 @@
<ItemGroup>
<Folder Include="Services\ActivityDataService\" />
<Folder Include="Models\Activity\" />
<Folder Include="Services\DataLocalService\" />
<Folder Include="Services\ReportDataService\" />
<Folder Include="Services\UserDataService\" />
<Folder Include="wwwroot\data\" />
<Folder Include="Services\TicketDataService\" />
<Folder Include="Components\" />
</ItemGroup>
<ItemGroup>

@ -5,8 +5,8 @@
public int IdActivity { get; set; }
public string Type { get; set; }
public DateOnly Date { get; set; }
public TimeOnly StartTime { get; set; }
public DateTime EndTime { get; set; }
public DateOnly StartTime { get; set; }
public DateOnly EndTime { get; set; }
public int EffortRessenti { get; set; }
public float Variability { get; set; }
public float Variance { get; set; }

@ -17,37 +17,9 @@ namespace HeartTrack.Pages
[Inject]
private IActivityDataService ActivitiesDataService { get; set; }
[Inject]
public IStringLocalizer<BannedUsers> Localizer { get; set; }
public IStringLocalizer<Activities> Localizer { get; set; }
private async Task OnReadData()
{
//if (e.CancellationToken.IsCancellationRequested)
//{
// return;
//}
//// When you use a real API, we use this follow code
////var response = await Http.GetJsonAsync<Item[]>( $"http://my-api/api/data?page={e.Page}&pageSize={e.PageSize}" );
////var response = await Http.GetStringAsync("http://localhost:8080/api");
////var activityList = JsonConvert.DeserializeObject<List<Activity>>(response);
//var response = (await Http.GetFromJsonAsync<Activity[]>("http://localhost:8080/api")).Skip((e.Page - 1) * e.PageSize).Take(e.PageSize).ToList();
////await Http.GetFromJsonAsync<Activity[]>("http://localhost:8080/api");
////Console.WriteLine(response);
////var response = (await Http.GetFromJsonAsync<Activity[]>($"{NavigationManager.BaseUri}fake-activities.json")).Skip((e.Page - 1) * e.PageSize).Take(e.PageSize).ToList();
//if (!e.CancellationToken.IsCancellationRequested)
//{
// totalActivity = (await Http.GetFromJsonAsync<List<Activity>>("http://localhost:8080/api")).Count;
// //(await Http.GetFromJsonAsync<List<Activity>>($"{NavigationManager.BaseUri}fake-data-activity.json")).Count;
// activities = new List<Activity>(response); // an actual data for the current page
// //Console.WriteLine(totalActivity);
//}
//Console.WriteLine("Passage dans le OnInitializedAsync...");
this.activities = await this.ActivitiesDataService.getAllActivities();
this.totalActivity = activities.Count();
}

@ -1,7 +1,5 @@
@page "/tickets/add"
@* <AuthorizeView Context="authContext" Roles="admin">
<Authorized > *@
<h3>Add Ticket</h3>
<EditForm Model="@ticketModel" OnValidSubmit="@HandleValidSubmit">
@ -37,12 +35,3 @@
<button type="submit">Submit</button>
</EditForm>
@* </Authorized>
<Authorizing>
<h1>Loading ...</h1>
</Authorizing>
<NotAuthorized>
<h1>Authentication Failure!</h1>
<p>You're not signed in.</p>
</NotAuthorized>
</AuthorizeView> *@

@ -23,13 +23,9 @@ namespace HeartTrack.Pages
private async void HandleValidSubmit()
{
// Get the current data
var currentData = await TicketStorage.getAllTickets();
// Simulate the Id
ticketModel.Id = currentData.Max(s => s.Id) + 1;
// Add the item to the current data
currentData.Add(new Ticket
{
Id = ticketModel.Id,
@ -39,9 +35,7 @@ namespace HeartTrack.Pages
Urgence = ticketModel.Urgence*/
});
// Save the data
await TicketStorage.SaveAllTickets(currentData);
NavigationManager.NavigateTo("tickets");
}

@ -1,4 +0,0 @@
@page "/admin-manager"
@attribute [Authorize(Roles = "superadmin")]
<h3>Admin Page</h3>

@ -1,30 +0,0 @@
@page "/banned-users"
@using HeartTrack.Models
<PageTitle>Banned Users</PageTitle>
<h1>Banned Users</h1>
This is banned users list of this website.
<div>
<NavLink class="btn btn-primary" href="banned-users/add" Match="NavLinkMatch.All">
<i class="fa fa-plus"></i> Ajouter
</NavLink>
</div>
<SurveyPrompt Title="How is Blazor working for you?" />
<DataGrid TItem="User"
Data="@users"
ReadData="@OnReadData"
TotalItems="@totalUser"
PageSize="10"
ShowPager
Responsive>
<DataGridColumn TItem="User" Field="@nameof(User.Id)" Caption="Id" />
<DataGridColumn TItem="User" Field="@nameof(User.Username)" Caption="@Localizer["Username"]" />
<DataGridColumn TItem="User" Field="@nameof(User.Nom)" Caption="@Localizer["FirstN"]" />
<DataGridColumn TItem="User" Field="@nameof(User.Prenom)" Caption="@Localizer["LastN"]" />
<DataGridColumn Caption="" />
</DataGrid>

@ -1,66 +0,0 @@
using Blazored.LocalStorage;
using Blazorise;
using Blazorise.DataGrid;
using HeartTrack.Models;
using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.Localization;
namespace HeartTrack.Pages
{
public partial class BannedUsers
{
private List<User> users;
private int totalUser;
[Inject]
public HttpClient Http { get; set; }
[Inject]
public NavigationManager NavigationManager { get; set; }
[Inject]
public ILocalStorageService LocalStorage { get; set; }
[Inject]
public IStringLocalizer<BannedUsers> Localizer { get; set; }
protected override async Task OnAfterRenderAsync(bool firstRender)
{
// Do not treat this action if is not the first render
if (!firstRender)
{
return;
}
var currentData = await LocalStorage.GetItemAsync<User[]>("data");
// Check if data exist in the local storage
if (currentData == null)
{
// this code add in the local storage the fake data (we load the data sync for initialize the data before load the OnReadData method)
var originalData = Http.GetFromJsonAsync<User[]>($"{NavigationManager.BaseUri}fake-data.json").Result;
await LocalStorage.SetItemAsync("data", originalData);
}
}
private async Task OnReadData(DataGridReadDataEventArgs<User> e)
{
if (e.CancellationToken.IsCancellationRequested)
{
return;
}
// When you use a real API, we use this follow code
//var response = await Http.GetJsonAsync<Data[]>( $"http://my-api/api/data?page={e.Page}&pageSize={e.PageSize}" );
var response = (await LocalStorage.GetItemAsync<User[]>("data")).Skip((e.Page - 1) * e.PageSize).Take(e.PageSize).ToList();
if (!e.CancellationToken.IsCancellationRequested)
{
totalUser = (await LocalStorage.GetItemAsync<List<User>>("data")).Count;
users = new List<User>(response); // an actual data for the current page
}
}
}
}

@ -1,22 +0,0 @@
@page "/reports"
@using HeartTrack.Models
<PageTitle>Reports</PageTitle>
<h1>Report list</h1>
This is the report list of users.
<DataGrid TItem="Report"
Data="@reports"
ReadData="@OnReadData"
TotalItems="@totalReport"
PageSize="10"
ShowPager
Responsive>
<DataGridColumn TItem="Report" Field="@nameof(Report.Id)" Caption="Id" />
<DataGridColumn TItem="Report" Field="@nameof(Report.Username)" Caption="@Localizer["Username"]" />
<DataGridColumn TItem="Report" Field="@nameof(Report.Raison)" Caption="@Localizer["Raison"]" />
<DataGridColumn TItem="Report" Field="@nameof(Report.Description)" Caption="@Localizer["Description"]" />
<DataGridColumn Caption="" />
</DataGrid>

@ -1,63 +0,0 @@
using Blazored.LocalStorage;
using Blazorise.DataGrid;
using HeartTrack.Models;
using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.Localization;
namespace HeartTrack.Pages
{
public partial class Reports
{
private List<Report> reports;
private int totalReport;
[Inject]
public HttpClient Http { get; set; }
[Inject]
public NavigationManager NavigationManager { get; set; }
[Inject]
public ILocalStorageService LocalStorage { get; set; }
[Inject]
public IStringLocalizer<Report> Localizer { get; set; }
protected override async Task OnAfterRenderAsync(bool firstRender)
{
// Do not treat this action if is not the first render
if (!firstRender)
{
return;
}
var currentData = await LocalStorage.GetItemAsync<Report[]>("data");
// Check if data exist in the local storage
if (currentData == null)
{
// this code add in the local storage the fake data (we load the data sync for initialize the data before load the OnReadData method)
var originalData = Http.GetFromJsonAsync<Report[]>($"{NavigationManager.BaseUri}fake-data.json").Result;
await LocalStorage.SetItemAsync("data", originalData);
}
}
private async Task OnReadData(DataGridReadDataEventArgs<Report> e)
{
if (e.CancellationToken.IsCancellationRequested)
{
return;
}
// When you use a real API, we use this follow code
//var response = await Http.GetJsonAsync<Data[]>( $"http://my-api/api/data?page={e.Page}&pageSize={e.PageSize}" );
var response = (await LocalStorage.GetItemAsync<Report[]>("data")).Skip((e.Page - 1) * e.PageSize).Take(e.PageSize).ToList();
if (!e.CancellationToken.IsCancellationRequested)
{
totalReport = (await LocalStorage.GetItemAsync<List<User>>("data")).Count;
reports = new List<Report>(response); // an actual data for the current page
}
}
}
}

@ -1,20 +0,0 @@
@page "/test"
<div class="text-center bg-blue-100">
<input class="border-4 w-1/3 rounded m-6 p-6 h-8
border-blue-300" @bind-value="SearchText"
@bind-value:event="oninput" placeholder="Search by title" />
</div>
@if (!Users.Any())
{
<p>Loading some images...</p>
}
else
{
<div class="p-2 grid grid-cols-1 sm:grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-3">
@foreach (var user in FilteredUsers)
{
<p>feur</p>
}
</div>
}

@ -1,28 +0,0 @@
using Blazorise;
using HeartTrack.Models;
using HeartTrack.Services;
using Microsoft.AspNetCore.Components;
namespace HeartTrack.Pages
{
partial class Test : ComponentBase
{
public IEnumerable<User> Users { get; set; } = new List<User>();
public string SearchText = "";
[Inject]
public IDataService DataService { get; set; }
[Inject]
public IWebHostEnvironment WebHostEnvironment { get; set; }
protected override async Task OnInitializedAsync()
{
Users = await DataService.List(1, 50); ;
}
List<User> FilteredUsers => Users.Where(
user => user.Username.ToLower().Contains(SearchText.ToLower())).ToList();
}
}

@ -12,8 +12,6 @@ This is the ticket list of users.
<MudButtonGroup Color="Color.Primary" Variant="Variant.Filled" Style="margin-top:50px; margin-bottom:5px;">
<MudButton OnClick="OnNavigateOnAddClicked">Add</MudButton>
<MudButton >Reset DATA</MudButton>
<MudButton >Shows Open Tickets</MudButton>
</MudButtonGroup>
</div>

@ -5,22 +5,11 @@ using Microsoft.AspNetCore.Localization;
using System.Globalization;
using Microsoft.Extensions.Options;
using Blazored.LocalStorage;
using HeartTrack.Services;
using HeartTrack.Services.ActivityDataService;
using HeartTrack.Services.ReportDataService;
using HeartTrack.Services.UserDataService;
using HeartTrack.Services.TicketDataService;
using Blazorise;
using Blazorise.Bootstrap;
using Blazorise.Icons.FontAwesome;
using Microsoft.AspNetCore.Localization;
using System.Globalization;
using Microsoft.Extensions.Options;
using Blazored.LocalStorage;
using HeartTrack.Services;
using Microsoft.AspNetCore.Components.Authorization;
using MudBlazor.Services;
using HeartTrack.Services.TicketDataServiceFactice;
using HeartTrack.Services.ActivityDataServiceFactice;
var builder = WebApplication.CreateBuilder(args);
@ -33,11 +22,8 @@ builder.Services.AddServerSideBlazor();
builder.Services.AddHttpClient();
// Add Services
builder.Services.AddScoped<IDataService, DataLocalService>();
builder.Services.AddScoped<IActivityDataService, ActivityDataServiceAPI>();
builder.Services.AddScoped<IReportDataService, ReportDataServiceAPI>();
builder.Services.AddScoped<IActivityDataService, ActivityDataServiceFactice>();
builder.Services.AddScoped<ITicketDataService, TicketDataServiceFactice>();
builder.Services.AddScoped<IUserDataService, UserDataServiceAPI>();
builder.Services.AddBlazorise()
@ -65,8 +51,6 @@ builder.Services.AddBlazoredLocalStorage();
builder.Services.AddHttpClient();
builder.Services.AddScoped<IDataService, DataLocalService>();
builder.Services.AddBlazorise()
.AddBootstrapProviders()
.AddFontAwesomeIcons();

@ -1,133 +0,0 @@
using Blazored.LocalStorage;
using HeartTrack.Models;
using Microsoft.AspNetCore.Components;
using static MudBlazor.CategoryTypes;
namespace HeartTrack.Services
{
public class DataLocalService : IDataService
{
private readonly HttpClient _http;
private readonly ILocalStorageService _localStorage;
private readonly NavigationManager _navigationManager;
private readonly IWebHostEnvironment _webHostEnvironment;
public DataLocalService(
ILocalStorageService localStorage,
HttpClient http,
IWebHostEnvironment webHostEnvironment,
NavigationManager navigationManager)
{
_localStorage = localStorage;
_http = http;
_webHostEnvironment = webHostEnvironment;
_navigationManager = navigationManager;
}
public async Task Add(UserModel model)
{
// Get the current data
var currentData = await _localStorage.GetItemAsync<List<User>>("data");
// Simulate the Id
model.Id = currentData.Max(s => s.Id) + 1;
// Add the item to the current data
currentData.Add(new User
{
Id = model.Id,
Username = model.Username,
Nom = model.FirstName,
Prenom = model.LastName,
Email = model.Email,
Password = model.Password,
Sexe = model.Sexe,
Taille = model.Taille,
Poids = model.Poids,
BirthDate = model.BirthDate
});
// Save the data
await _localStorage.SetItemAsync("data", currentData);
}
public async Task<int> Count()
{
// Load data from the local storage
var currentData = await _localStorage.GetItemAsync<User[]>("data");
// Check if data exist in the local storage
if (currentData == null)
{
// this code add in the local storage the fake data
var originalData = await _http.GetFromJsonAsync<User[]>($"{_navigationManager.BaseUri}fake-data.json");
await _localStorage.SetItemAsync("data", originalData);
}
return (await _localStorage.GetItemAsync<User[]>("data")).Length;
}
public async Task<List<User>> List(int currentPage, int pageSize)
{
// Load data from the local storage
var currentData = await _localStorage.GetItemAsync<User[]>("data");
// Check if data exist in the local storage
if (currentData == null)
{
// this code add in the local storage the fake data
var originalData = await _http.GetFromJsonAsync<User[]>($"{_navigationManager.BaseUri}fake-data.json");
await _localStorage.SetItemAsync("data", originalData);
}
return (await _localStorage.GetItemAsync<User[]>("data")).Skip((currentPage - 1) * pageSize).Take(pageSize).ToList();
}
public async Task Close(int id)
{
// Get the current data
var currentData = await _localStorage.GetItemAsync<List<Ticket>>("data");
// Get the item int the list
var item = currentData.FirstOrDefault(w => w.Id == id);
// Update item status
item.isCheck = true;
// Save the data
await _localStorage.SetItemAsync("data", currentData);
}
public async Task Delete(int id)
{
// Get the current data
var currentData = await _localStorage.GetItemAsync<List<Ticket>>("data");
// Get the item int the list
var item = currentData.FirstOrDefault(w => w.Id == id);
// Delete item in
currentData.Remove(item);
// Save the data
await _localStorage.SetItemAsync("data", currentData);
}
public async Task<Ticket> GetByID(int id)
{
// Get the current data
var currentData = await _localStorage.GetItemAsync<List<Ticket>>("data");
// Get the item int the list
var item = currentData.FirstOrDefault(w => w.Id == id);
// Check if item exist
if (item == null)
{
throw new Exception($"Unable to found the item with ID: {id}");
}
return item;
}
}
}

@ -1,17 +0,0 @@
using HeartTrack.Models;
using static MudBlazor.CategoryTypes;
namespace HeartTrack.Services
{
public interface IDataService
{
Task Add(UserModel model);
Task<List<User>> List(int currentPage, int pageSize);
Task<Ticket> GetByID(int id);
Task Close(int id);
Task Delete(int id);
}
}

@ -1,20 +0,0 @@
using System;
using HeartTrack.Models;
namespace HeartTrack.Services.ReportDataService
{
public interface IReportDataService
{
public Task<List<Report>> getAllReports();
public Task SaveAllReports(List<Report> list);
public Task AddReport(Report r);
public Task RemoveReport(Report r);
public Task UpdateReport(Report r);
public Task<Report> getReportById(int id);
}
}

@ -1,86 +0,0 @@
using System;
using HeartTrack.Models;
using Microsoft.AspNetCore.Components;
namespace HeartTrack.Services.ReportDataService
{
public class ReportDataServiceAPI : IReportDataService
{
[Inject]
private HttpClient _clientHttp { get; set; }
public ReportDataServiceAPI(HttpClient clientHttp)
{
this._clientHttp = clientHttp;
}
public async Task AddReport(Report r)
{
HttpResponseMessage response = await _clientHttp.PostAsJsonAsync("http://localhost:8080/api/reports", r);
if (response.IsSuccessStatusCode)
{
Console.WriteLine("API - Report avec l'id " + r.Id + " ajouté avec succès");
}
else
{
Console.WriteLine("API - Problème ajout Report");
}
}
public async Task<Report> getReportById(int id)
{
Report Report = await _clientHttp.GetFromJsonAsync<Report>("http://localhost:8080/api/reports/{id}");
return Report;
}
public async Task<List<Report>> getAllReports()
{
List<Report> lReports = await _clientHttp.GetFromJsonAsync<List<Report>>("http://localhost:8080/api/reports");
return lReports;
}
public async Task RemoveReport(Report r)
{
HttpResponseMessage response = await _clientHttp.DeleteAsync($"http://localhost:8080/api/reports/{r.Id}");
if (response.IsSuccessStatusCode)
{
Console.WriteLine("API - Report avec l'id " + r.Id + " supprimé avec succès");
}
else
{
Console.WriteLine("API - Problème suppression Report");
}
}
public async Task SaveAllReports(List<Report> list)
{
HttpResponseMessage response = await _clientHttp.PutAsJsonAsync("http://localhost:8080/api/reports", list);
if (response.IsSuccessStatusCode)
{
Console.WriteLine("API - List de reports sauvegardé avec succès");
}
else
{
Console.WriteLine("API - Problème sauvegarde List de reports");
}
}
public async Task UpdateReport(Report r)
{
HttpResponseMessage response = await _clientHttp.PutAsJsonAsync($"http://localhost:8080/api/reports/{r.Id}", r);
if (response.IsSuccessStatusCode)
{
Console.WriteLine("API - Report avec l'id " + r.Id + " mis à jour avec succès");
}
else
{
Console.WriteLine("API - Problème mise à jour Report");
}
}
}
}

@ -1,139 +0,0 @@
using System;
using Blazored.LocalStorage;
using HeartTrack.Models;
using HeartTrack.Services.ReportDataService;
using Microsoft.AspNetCore.Components;
namespace HeartTrack.Services.ReportDataServiceFactice
{
public class ReportDataServiceFactice : IReportDataService
{
[Inject]
private HttpClient _clientHttp { get; set; }
[Inject]
public ILocalStorageService _localStorage { get; set; }
[Inject]
public NavigationManager _navigationManager { get; set; }
private String EmplacementLocalStorage { get; set; }
private String EmplacementJson { get; set; }
public ReportDataServiceFactice(HttpClient clientHttp, ILocalStorageService localStorage, NavigationManager navigationManager)
{
this._clientHttp = clientHttp;
this._localStorage = localStorage;
this._navigationManager = navigationManager;
this.EmplacementLocalStorage = "reportsData";
this.EmplacementJson = $"{_navigationManager.BaseUri}data/fake-reports.json";
}
public async Task AddReport(Report a)
{
List<Report> data = await getAllReports();
data.Add(a);
await this.SaveAllReports(data);
}
public async Task<Report> getReportById(int id)
{
List<Report> reports = await getAllReports();
Report? temp = null;
foreach (Report r in reports)
{
if (r.Id == id)
{
temp = r;
}
}
return temp;
}
public async Task<List<Report>> getAllReports()
{
List<Report> lReports = new List<Report>();
lReports = await this.getReportsFromLocalStorage();
if (lReports.Count == 0)
{
lReports = await this.getReportsFromJson(this.EmplacementJson);
await this.saveReportsLocalStorage(lReports);
}
return lReports;
}
private async Task<List<Report>> getReportsFromJson(String cheminVersJson)
{
List<Report> ReportsDeserialiser = new List<Report>();
var data = await _clientHttp.GetFromJsonAsync<Report[]>(cheminVersJson);
ReportsDeserialiser = data.ToList();
return ReportsDeserialiser;
}
private async Task<List<Report>> getReportsFromLocalStorage()
{
List<Report> ReportsFromLocalStorage = null;
var data = await _localStorage.GetItemAsync<Report[]>(EmplacementLocalStorage);
if (data == null)
{
ReportsFromLocalStorage = new List<Report>();
}
else
{
ReportsFromLocalStorage = data.ToList();
}
return ReportsFromLocalStorage;
}
public async Task RemoveReport(Report r)
{
List<Report> data = await getAllReports();
int index = -1;
foreach (Report temp in data)
{
if (temp.Id == r.Id)
{
index = data.IndexOf(temp);
}
}
if (index != -1)
{
data.RemoveAt(index);
}
await this.SaveAllReports(data);
data = await this.getAllReports();
}
public async Task SaveAllReports(List<Report> list)
{
await this.saveReportsLocalStorage(list);
}
private async Task saveReportsLocalStorage(List<Report> lReports)
{
await _localStorage.SetItemAsync(this.EmplacementLocalStorage, lReports);
}
public async Task UpdateReport(Report r)
{
await this.RemoveReport(r);
await this.AddReport(r);
}
}
}

@ -1,21 +0,0 @@
using System;
using HeartTrack.Models;
namespace HeartTrack.Services.UserDataService
{
public interface IUserDataService
{
public Task<List<User>> getAllUsers();
public Task SaveAllUsers(List<User> list);
public Task AddUser(User u);
public Task RemoveUser(User u);
public Task UpdateUser(User u);
public Task<User> getUserById(int id);
}
}

@ -1,86 +0,0 @@
using System;
using HeartTrack.Models;
using Microsoft.AspNetCore.Components;
namespace HeartTrack.Services.UserDataService
{
public class UserDataServiceAPI : IUserDataService
{
[Inject]
private HttpClient _clientHttp { get; set; }
public UserDataServiceAPI(HttpClient clientHttp)
{
this._clientHttp = clientHttp;
}
public async Task AddUser(User u)
{
HttpResponseMessage response = await _clientHttp.PostAsJsonAsync("http://localhost:8080/api/users", u);
if (response.IsSuccessStatusCode)
{
Console.WriteLine("API - User avec l'id " + u.Id + " ajouté avec succès");
}
else
{
Console.WriteLine("API - Problème ajout User");
}
}
public async Task<User> getUserById(int id)
{
User User = await _clientHttp.GetFromJsonAsync<User>("http://localhost:8080/api/users/{id}");
return User;
}
public async Task<List<User>> getAllUsers()
{
List<User> lUsers = await _clientHttp.GetFromJsonAsync<List<User>>("http://localhost:8080/api/users");
return lUsers;
}
public async Task RemoveUser(User u)
{
HttpResponseMessage response = await _clientHttp.DeleteAsync($"http://localhost:8080/api/users/{u.Id}");
if (response.IsSuccessStatusCode)
{
Console.WriteLine("API - User avec l'id " + u.Id + " supprimé avec succès");
}
else
{
Console.WriteLine("API - Problème suppression User");
}
}
public async Task SaveAllUsers(List<User> list)
{
HttpResponseMessage response = await _clientHttp.PutAsJsonAsync("http://localhost:8080/api/users", list);
if (response.IsSuccessStatusCode)
{
Console.WriteLine("API - List de users sauvegardé avec succès");
}
else
{
Console.WriteLine("API - Problème sauvegarde List de users");
}
}
public async Task UpdateUser(User u)
{
HttpResponseMessage response = await _clientHttp.PutAsJsonAsync($"http://localhost:8080/api/users/{u.Id}", u);
if (response.IsSuccessStatusCode)
{
Console.WriteLine("API - User avec l'id " + u.Id + " mis à jour avec succès");
}
else
{
Console.WriteLine("API - Problème mise à jour User");
}
}
}
}

@ -1,139 +0,0 @@
using System;
using Blazored.LocalStorage;
using HeartTrack.Models;
using HeartTrack.Services.UserDataService;
using Microsoft.AspNetCore.Components;
namespace HeartTrack.Services.UserDataServiceFactice
{
public class UserDataServiceFactice : IUserDataService
{
[Inject]
private HttpClient _clientHttp { get; set; }
[Inject]
public ILocalStorageService _localStorage { get; set; }
[Inject]
public NavigationManager _navigationManager { get; set; }
private String EmplacementLocalStorage { get; set; }
private String EmplacementJson { get; set; }
public UserDataServiceFactice(HttpClient clientHttp, ILocalStorageService localStorage, NavigationManager navigationManager)
{
this._clientHttp = clientHttp;
this._localStorage = localStorage;
this._navigationManager = navigationManager;
this.EmplacementLocalStorage = "usersData";
this.EmplacementJson = $"{_navigationManager.BaseUri}data/fake-users.json";
}
public async Task AddUser(User u)
{
List<User> data = await getAllUsers();
data.Add(u);
await this.SaveAllUsers(data);
}
public async Task<User> getUserById(int id)
{
List<User> users = await getAllUsers();
User? temp = null;
foreach (User u in users)
{
if (u.Id == id)
{
temp = u;
}
}
return temp;
}
public async Task<List<User>> getAllUsers()
{
List<User> lUsers = new List<User>();
lUsers = await this.getUsersFromLocalStorage();
if (lUsers.Count == 0)
{
lUsers = await this.getUsersFromJson(this.EmplacementJson);
await this.saveUsersLocalStorage(lUsers);
}
return lUsers;
}
private async Task<List<User>> getUsersFromJson(String cheminVersJson)
{
List<User> UsersDeserialiser = new List<User>();
var data = await _clientHttp.GetFromJsonAsync<User[]>(cheminVersJson);
UsersDeserialiser = data.ToList();
return UsersDeserialiser;
}
private async Task<List<User>> getUsersFromLocalStorage()
{
List<User> UsersFromLocalStorage = null;
var data = await _localStorage.GetItemAsync<User[]>(EmplacementLocalStorage);
if (data == null)
{
UsersFromLocalStorage = new List<User>();
}
else
{
UsersFromLocalStorage = data.ToList();
}
return UsersFromLocalStorage;
}
public async Task RemoveUser(User u)
{
List<User> data = await getAllUsers();
int index = -1;
foreach (User temp in data)
{
if (temp.Id == u.Id)
{
index = data.IndexOf(temp);
}
}
if (index != -1)
{
data.RemoveAt(index);
}
await this.SaveAllUsers(data);
data = await this.getAllUsers();
}
public async Task SaveAllUsers(List<User> list)
{
await this.saveUsersLocalStorage(list);
}
private async Task saveUsersLocalStorage(List<User> lUsers)
{
await _localStorage.SetItemAsync(this.EmplacementLocalStorage, lUsers);
}
public async Task UpdateUser(User u)
{
await this.RemoveUser(u);
await this.AddUser(u);
}
}
}

@ -1,42 +1,12 @@
@using System.Globalization
@inject NavigationManager NavigationManager
<p>
<label>
<select @bind="Culture">
@foreach (var culture in supportedCultures)
@foreach (var culture in @supportedCultures)
{
<option value="@culture">@culture.DisplayName</option>
}
</select>
</label>
</p>
@code
{
private CultureInfo[] supportedCultures = new[]
{
new CultureInfo("en-US"),
new CultureInfo("fr-FR")
};
private CultureInfo Culture
{
get => CultureInfo.CurrentCulture;
set
{
if (CultureInfo.CurrentUICulture == value)
{
return;
}
var culture = value.Name.ToLower(CultureInfo.InvariantCulture);
var uri = new Uri(this.NavigationManager.Uri).GetComponents(UriComponents.PathAndQuery, UriFormat.Unescaped);
var query = $"?culture={Uri.EscapeDataString(culture)}&" + $"redirectUri={Uri.EscapeDataString(uri)}";
// Redirect the user to the culture controller to set the cookie
this.NavigationManager.NavigateTo("/Culture/SetCulture" + query, forceLoad: true);
}
}
}

@ -0,0 +1,37 @@
using Microsoft.AspNetCore.Components;
using System.Globalization;
namespace HeartTrack.Shared
{
public partial class CultureSelector
{
[Inject]
private NavigationManager NavigationManager { get; set; }
private CultureInfo[] supportedCultures = new[]
{
new CultureInfo("en-US"),
new CultureInfo("fr-FR")
};
private CultureInfo Culture
{
get => CultureInfo.CurrentCulture;
set
{
if (CultureInfo.CurrentUICulture == value)
{
return;
}
var culture = value.Name.ToLower(CultureInfo.InvariantCulture);
var uri = new Uri(this.NavigationManager.Uri).GetComponents(UriComponents.PathAndQuery, UriFormat.Unescaped);
var query = $"?culture={Uri.EscapeDataString(culture)}&" + $"redirectUri={Uri.EscapeDataString(uri)}";
// Redirect the user to the culture controller to set the cookie
this.NavigationManager.NavigateTo("/Culture/SetCulture" + query, forceLoad: true);
}
}
}
}

@ -36,19 +36,4 @@
@Body
</article>
</main>
</div>
@code {
private bool collapseNavMenu = true;
private string? NavMenuCssClass => collapseNavMenu ? "collapse" : null;
private void ToggleNavMenu()
{
collapseNavMenu = !collapseNavMenu;
}
private void ToggleProfilMenu()
{
}
}
</div>

@ -6,27 +6,20 @@ namespace HeartTrack.Shared
{
public partial class MainLayout
{
/*[Inject]
public CustomStateProvider AuthStateProvider { get; set; }*/
[Inject]
public NavigationManager NavigationManager { get; set; }
[CascadingParameter]
private Task<AuthenticationState> AuthenticationState { get; set; }
private bool collapseNavMenu = true;
/*protected override async Task OnParametersSetAsync()
{
if (!(await AuthenticationState).User.Identity.IsAuthenticated)
{
NavigationManager.NavigateTo("/login");
}
}*/
private string? NavMenuCssClass => collapseNavMenu ? "collapse" : null;
/*private async Task LogoutClick()
private void ToggleNavMenu()
{
await AuthStateProvider.Logout();
NavigationManager.NavigateTo("/login");
}*/
collapseNavMenu = !collapseNavMenu;
}
private void ToggleProfilMenu()
{
}
}
}

@ -11,40 +11,16 @@
<span class="oi oi-home" aria-hidden="true"></span> @Localizer["Global"]
</NavLink>
</div>
@* <AuthorizeView Roles="admin"> *@
<div class="nav-item px-3">
<NavLink class="nav-link" href="reports">
<span class="oi oi-list-rich" aria-hidden="true"></span> @Localizer["Report"]
</NavLink>
</div>
@* </AuthorizeView>
<AuthorizeView Roles="admin"> *@
<div class="nav-item px-3">
<NavLink class="nav-link" href="activities">
<span class="oi oi-list-rich" aria-hidden="true"></span> @Localizer["Activity"]
</NavLink>
</div>
@* </AuthorizeView>
<AuthorizeView Roles="admin"> *@
<div class="nav-item px-3">
<NavLink class="nav-link" href="banned-users">
<span class="oi oi-list-rich" aria-hidden="true"></span> @Localizer["Ban"]
</NavLink>
</div>
@* </AuthorizeView>
<AuthorizeView Roles="admin"> *@
<div class="nav-item px-3">
<NavLink class="nav-link" href="tickets">
<span class="oi oi-plus" aria-hidden="true"></span> @Localizer["Ticket"]
</NavLink>
</div>
@* </AuthorizeView>
<AuthorizeView Roles="owner"> *@
<div class="nav-item px-3">
<NavLink class="nav-link" href="admin">
<span class="oi oi-plus" aria-hidden="true"></span> @Localizer["Admin"]
</NavLink>
</div>
@* </AuthorizeView> *@
</nav>
</div>

@ -1,17 +0,0 @@
<div class="alert alert-secondary mt-4">
<span class="oi oi-pencil me-2" aria-hidden="true"></span>
<strong>@Title</strong>
<span class="text-nowrap">
Please take our
<a target="_blank" class="font-weight-bold link-dark" href="https://go.microsoft.com/fwlink/?linkid=2149017">brief survey</a>
</span>
and tell us what you think.
</div>
@code {
// Demonstrates how a parent component can supply parameters
[Parameter]
public string? Title { get; set; }
}
Loading…
Cancel
Save