From 07704d3b0fafb19b24a48e0c535b8900fceff3df Mon Sep 17 00:00:00 2001 From: Totti Date: Tue, 26 Apr 2022 23:17:03 +0200 Subject: [PATCH] Fix Web Api Post, Update dll to last version, refactoring code. --- .../20220329200352_WeatherForecasts.cs | 55 +++--- .../Pages/Error.cshtml.cs | 33 ++-- BlazorDevIta.ERP.BlazorServer/Program.cs | 20 +- .../Properties/launchSettings.json | 2 +- .../Services/DataServices.cs | 118 ++++++------ .../appsettings.Development.json | 2 +- .../appsettings.json | 2 +- .../wwwroot/css/site.css | 2 +- .../BlazorDevIta.ERP.BlazorWasm.Client.csproj | 4 +- BlazorDevIta.ERP.BlazorWasm/Client/Program.cs | 3 +- .../Client/Properties/launchSettings.json | 2 +- .../Client/Services/DataServices.cs | 71 +++---- .../Client/wwwroot/css/app.css | 2 +- .../Client/wwwroot/index.html | 3 +- .../BlazorDevIta.ERP.BlazorWasm.Server.csproj | 2 +- .../Controllers/WeatherForecastController.cs | 178 ++++++++++-------- .../Server/Pages/Error.cshtml.cs | 33 ++-- BlazorDevIta.ERP.BlazorWasm/Server/Program.cs | 19 +- .../Server/Properties/launchSettings.json | 48 ++--- .../Server/appsettings.Development.json | 2 +- .../Server/appsettings.json | 2 +- .../Data/ERPDbContext.cs | 14 +- .../Data/WeatherForecast.cs | 21 ++- .../BlazorDevIta.ERP.Infrastructure.EF.csproj | 2 +- .../EFRepository.cs | 103 +++++----- .../Attributes/HiddenAttribute.cs | 7 +- BlazorDevIta.ERP.Infrastructure/IEntity.cs | 18 +- .../IRepository.cs | 31 ++- BlazorDevIta.Shared/WeatherForecastDetails.cs | 20 +- .../WeatherForecastListItem.cs | 21 +-- BlazorDevIta.UI/BlazorDevIta.UI.csproj | 2 +- BlazorDevIta.UI/Services/IDataServices.cs | 20 +- BlazorDevIta.UI/Shared/MainLayout.razor.css | 26 +-- BlazorDevIta.UI/Shared/NavMenu.razor.css | 18 +- 34 files changed, 462 insertions(+), 444 deletions(-) diff --git a/BlazorDevIta.ERP.BlazorServer/Migrations/20220329200352_WeatherForecasts.cs b/BlazorDevIta.ERP.BlazorServer/Migrations/20220329200352_WeatherForecasts.cs index 6a8f613..d0b351c 100644 --- a/BlazorDevIta.ERP.BlazorServer/Migrations/20220329200352_WeatherForecasts.cs +++ b/BlazorDevIta.ERP.BlazorServer/Migrations/20220329200352_WeatherForecasts.cs @@ -1,34 +1,33 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Migrations; #nullable disable namespace BlazorDevIta.ERP.BlazorServer.Migrations { - public partial class WeatherForecasts : Migration - { - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "WeatherForecasts", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - Date = table.Column(type: "datetime2", nullable: false), - TemperatureC = table.Column(type: "int", nullable: false), - Summary = table.Column(type: "nvarchar(50)", maxLength: 50, nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_WeatherForecasts", x => x.Id); - }); - } + public partial class WeatherForecasts : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "WeatherForecasts", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Date = table.Column(type: "datetime2", nullable: false), + TemperatureC = table.Column(type: "int", nullable: false), + Summary = table.Column(type: "nvarchar(50)", maxLength: 50, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_WeatherForecasts", x => x.Id); + }); + } - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "WeatherForecasts"); - } - } -} + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "WeatherForecasts"); + } + } +} \ No newline at end of file diff --git a/BlazorDevIta.ERP.BlazorServer/Pages/Error.cshtml.cs b/BlazorDevIta.ERP.BlazorServer/Pages/Error.cshtml.cs index d7ff6c1..42b3b86 100644 --- a/BlazorDevIta.ERP.BlazorServer/Pages/Error.cshtml.cs +++ b/BlazorDevIta.ERP.BlazorServer/Pages/Error.cshtml.cs @@ -1,27 +1,28 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; + using System.Diagnostics; namespace BlazorDevIta.ERP.BlazorServer.Pages { - [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] - [IgnoreAntiforgeryToken] - public class ErrorModel : PageModel - { - public string? RequestId { get; set; } + [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] + [IgnoreAntiforgeryToken] + public class ErrorModel : PageModel + { + public string? RequestId { get; set; } - public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); + public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); - private readonly ILogger _logger; + private readonly ILogger _logger; - public ErrorModel(ILogger logger) - { - _logger = logger; - } + public ErrorModel(ILogger logger) + { + _logger = logger; + } - public void OnGet() - { - RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier; - } - } + public void OnGet() + { + RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier; + } + } } \ No newline at end of file diff --git a/BlazorDevIta.ERP.BlazorServer/Program.cs b/BlazorDevIta.ERP.BlazorServer/Program.cs index dc3c3dd..d5d3422 100644 --- a/BlazorDevIta.ERP.BlazorServer/Program.cs +++ b/BlazorDevIta.ERP.BlazorServer/Program.cs @@ -1,10 +1,9 @@ -using BlazorDevIta.ERP.Business.Data; using BlazorDevIta.ERP.BlazorServer.Services; +using BlazorDevIta.ERP.Business.Data; using BlazorDevIta.ERP.Infrastructure; using BlazorDevIta.ERP.Infrastructure.EF; using BlazorDevIta.UI.Services; -using Microsoft.AspNetCore.Components; -using Microsoft.AspNetCore.Components.Web; + using Microsoft.EntityFrameworkCore; var builder = WebApplication.CreateBuilder(args); @@ -16,22 +15,21 @@ builder.Services.AddScoped(); builder.Services.AddDbContext(opt => - opt.UseSqlServer( - builder.Configuration.GetConnectionString("DefaultConnection"), - b => b.MigrationsAssembly("BlazorDevIta.ERP.BlazorServer"))); + opt.UseSqlServer( + builder.Configuration.GetConnectionString("DefaultConnection"), + b => b.MigrationsAssembly("BlazorDevIta.ERP.BlazorServer"))); builder.Services.AddScoped(); builder.Services.AddScoped(typeof(IRepository<,>), typeof(EFRepository<,>)); - var app = builder.Build(); // Configure the HTTP request pipeline. if (!app.Environment.IsDevelopment()) { - app.UseExceptionHandler("/Error"); - // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. - app.UseHsts(); + app.UseExceptionHandler("/Error"); + // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. + app.UseHsts(); } app.UseHttpsRedirection(); @@ -43,4 +41,4 @@ app.MapBlazorHub(); app.MapFallbackToPage("/_Host"); -app.Run(); +app.Run(); \ No newline at end of file diff --git a/BlazorDevIta.ERP.BlazorServer/Properties/launchSettings.json b/BlazorDevIta.ERP.BlazorServer/Properties/launchSettings.json index 2b6af27..d69c7a9 100644 --- a/BlazorDevIta.ERP.BlazorServer/Properties/launchSettings.json +++ b/BlazorDevIta.ERP.BlazorServer/Properties/launchSettings.json @@ -25,4 +25,4 @@ } } } -} +} \ No newline at end of file diff --git a/BlazorDevIta.ERP.BlazorServer/Services/DataServices.cs b/BlazorDevIta.ERP.BlazorServer/Services/DataServices.cs index efbea22..505cb0c 100644 --- a/BlazorDevIta.ERP.BlazorServer/Services/DataServices.cs +++ b/BlazorDevIta.ERP.BlazorServer/Services/DataServices.cs @@ -2,71 +2,75 @@ using BlazorDevIta.ERP.Infrastructure; using BlazorDevIta.ERP.Shared; using BlazorDevIta.UI.Services; + using Microsoft.EntityFrameworkCore; namespace BlazorDevIta.ERP.BlazorServer.Services { - public class DataServices : IDataServices - { - private readonly IRepository _repository; + public class DataServices : IDataServices + { + private readonly IRepository _repository; - public DataServices(IRepository repository) - { - _repository = repository; - } + public DataServices(IRepository repository) + { + _repository = repository; + } - public Task> GetWeatherForecastsAsync() - { - return _repository.GetAll() - .Select(x => - new WeatherForecastListItem() - { - Id = x.Id, - Date = x.Date, - TemperatureC = x.TemperatureC - }).ToListAsync(); - } + public Task> GetWeatherForecastsAsync() + { + return _repository.GetAll() + .Select(x => + new WeatherForecastListItem() + { + Id = x.Id, + Date = x.Date, + TemperatureC = x.TemperatureC + }).ToListAsync(); + } - public async Task GetWeatherForecastByIdAsync(int id) - { - var x = await _repository.GetByIdAsync(id); - if (x == null) return null; + public async Task GetWeatherForecastByIdAsync(int id) + { + var x = await _repository.GetByIdAsync(id); + if (x == null) + { + return null; + } - return new WeatherForecastDetails() - { - Id = x.Id, - Date = x.Date, - TemperatureC = x.TemperatureC, - Summary = x.Summary - }; - } + return new WeatherForecastDetails() + { + Id = x.Id, + Date = x.Date, + TemperatureC = x.TemperatureC, + Summary = x.Summary + }; + } - public Task Create(WeatherForecastDetails details) - { - var entity = new WeatherForecast() - { - Date = details.Date, - TemperatureC = details.TemperatureC, - Summary = details.Summary - }; - return _repository.CreateAsync(entity); - } + public Task Create(WeatherForecastDetails details) + { + var entity = new WeatherForecast() + { + Date = details.Date, + TemperatureC = details.TemperatureC, + Summary = details.Summary + }; + return _repository.CreateAsync(entity); + } - public Task Update(WeatherForecastDetails details) - { - var entity = new WeatherForecast() - { - Id = details.Id, - Date = details.Date, - TemperatureC = details.TemperatureC, - Summary = details.Summary - }; - return _repository.UpdateAsync(entity); - } + public Task Update(WeatherForecastDetails details) + { + var entity = new WeatherForecast() + { + Id = details.Id, + Date = details.Date, + TemperatureC = details.TemperatureC, + Summary = details.Summary + }; + return _repository.UpdateAsync(entity); + } - public Task Delete(int id) - { - return _repository.DeleteAsync(id); - } - } -} + public Task Delete(int id) + { + return _repository.DeleteAsync(id); + } + } +} \ No newline at end of file diff --git a/BlazorDevIta.ERP.BlazorServer/appsettings.Development.json b/BlazorDevIta.ERP.BlazorServer/appsettings.Development.json index 770d3e9..b6f634e 100644 --- a/BlazorDevIta.ERP.BlazorServer/appsettings.Development.json +++ b/BlazorDevIta.ERP.BlazorServer/appsettings.Development.json @@ -6,4 +6,4 @@ "Microsoft.AspNetCore": "Warning" } } -} +} \ No newline at end of file diff --git a/BlazorDevIta.ERP.BlazorServer/appsettings.json b/BlazorDevIta.ERP.BlazorServer/appsettings.json index 61994bb..dbed920 100644 --- a/BlazorDevIta.ERP.BlazorServer/appsettings.json +++ b/BlazorDevIta.ERP.BlazorServer/appsettings.json @@ -9,4 +9,4 @@ } }, "AllowedHosts": "*" -} +} \ No newline at end of file diff --git a/BlazorDevIta.ERP.BlazorServer/wwwroot/css/site.css b/BlazorDevIta.ERP.BlazorServer/wwwroot/css/site.css index 1f4b8cf..1ceb88f 100644 --- a/BlazorDevIta.ERP.BlazorServer/wwwroot/css/site.css +++ b/BlazorDevIta.ERP.BlazorServer/wwwroot/css/site.css @@ -61,4 +61,4 @@ a, .btn-link { .blazor-error-boundary::after { content: "An error has occurred." - } + } \ No newline at end of file diff --git a/BlazorDevIta.ERP.BlazorWasm/Client/BlazorDevIta.ERP.BlazorWasm.Client.csproj b/BlazorDevIta.ERP.BlazorWasm/Client/BlazorDevIta.ERP.BlazorWasm.Client.csproj index 6b500ab..fcc764d 100644 --- a/BlazorDevIta.ERP.BlazorWasm/Client/BlazorDevIta.ERP.BlazorWasm.Client.csproj +++ b/BlazorDevIta.ERP.BlazorWasm/Client/BlazorDevIta.ERP.BlazorWasm.Client.csproj @@ -7,8 +7,8 @@ - - + + diff --git a/BlazorDevIta.ERP.BlazorWasm/Client/Program.cs b/BlazorDevIta.ERP.BlazorWasm/Client/Program.cs index a262fb5..b3433e4 100644 --- a/BlazorDevIta.ERP.BlazorWasm/Client/Program.cs +++ b/BlazorDevIta.ERP.BlazorWasm/Client/Program.cs @@ -1,6 +1,7 @@ using BlazorDevIta.ERP.BlazorWasm.Client.Services; using BlazorDevIta.UI; using BlazorDevIta.UI.Services; + using Microsoft.AspNetCore.Components.Web; using Microsoft.AspNetCore.Components.WebAssembly.Hosting; @@ -11,4 +12,4 @@ builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); builder.Services.AddScoped(); -await builder.Build().RunAsync(); +await builder.Build().RunAsync(); \ No newline at end of file diff --git a/BlazorDevIta.ERP.BlazorWasm/Client/Properties/launchSettings.json b/BlazorDevIta.ERP.BlazorWasm/Client/Properties/launchSettings.json index 010d1eb..50907f2 100644 --- a/BlazorDevIta.ERP.BlazorWasm/Client/Properties/launchSettings.json +++ b/BlazorDevIta.ERP.BlazorWasm/Client/Properties/launchSettings.json @@ -27,4 +27,4 @@ } } } -} +} \ No newline at end of file diff --git a/BlazorDevIta.ERP.BlazorWasm/Client/Services/DataServices.cs b/BlazorDevIta.ERP.BlazorWasm/Client/Services/DataServices.cs index fde3989..0789431 100644 --- a/BlazorDevIta.ERP.BlazorWasm/Client/Services/DataServices.cs +++ b/BlazorDevIta.ERP.BlazorWasm/Client/Services/DataServices.cs @@ -1,41 +1,42 @@ using BlazorDevIta.ERP.Shared; using BlazorDevIta.UI.Services; + using System.Net.Http.Json; namespace BlazorDevIta.ERP.BlazorWasm.Client.Services { - public class DataServices : IDataServices - { - private readonly HttpClient _http; - - public DataServices(HttpClient http) - { - _http = http; - } - - public Task Create(WeatherForecastDetails details) - { - return _http.PostAsJsonAsync($"WeatherForecast", details); - } - - public Task Delete(int id) - { - return _http.DeleteAsync($"WeatherForecast/{id}"); - } - - public Task GetWeatherForecastByIdAsync(int id) - { - return _http.GetFromJsonAsync($"WeatherForecast/{id}")!; - } - - public Task> GetWeatherForecastsAsync() - { - return _http.GetFromJsonAsync>("WeatherForecast")!; - } - - public Task Update(WeatherForecastDetails details) - { - return _http.PutAsJsonAsync($"WeatherForecast/{details.Id}", details); - } - } -} + public class DataServices : IDataServices + { + private readonly HttpClient _http; + + public DataServices(HttpClient http) + { + _http = http; + } + + public Task Create(WeatherForecastDetails details) + { + return _http.PostAsJsonAsync($"WeatherForecast", details); + } + + public Task Delete(int id) + { + return _http.DeleteAsync($"WeatherForecast/{id}"); + } + + public Task GetWeatherForecastByIdAsync(int id) + { + return _http.GetFromJsonAsync($"WeatherForecast/{id}")!; + } + + public Task> GetWeatherForecastsAsync() + { + return _http.GetFromJsonAsync>("WeatherForecast")!; + } + + public Task Update(WeatherForecastDetails details) + { + return _http.PutAsJsonAsync($"WeatherForecast/{details.Id}", details); + } + } +} \ No newline at end of file diff --git a/BlazorDevIta.ERP.BlazorWasm/Client/wwwroot/css/app.css b/BlazorDevIta.ERP.BlazorWasm/Client/wwwroot/css/app.css index 9cd148f..9b1a178 100644 --- a/BlazorDevIta.ERP.BlazorWasm/Client/wwwroot/css/app.css +++ b/BlazorDevIta.ERP.BlazorWasm/Client/wwwroot/css/app.css @@ -61,4 +61,4 @@ a, .btn-link { .blazor-error-boundary::after { content: "An error has occurred." - } + } \ No newline at end of file diff --git a/BlazorDevIta.ERP.BlazorWasm/Client/wwwroot/index.html b/BlazorDevIta.ERP.BlazorWasm/Client/wwwroot/index.html index 33e244d..1254de1 100644 --- a/BlazorDevIta.ERP.BlazorWasm/Client/wwwroot/index.html +++ b/BlazorDevIta.ERP.BlazorWasm/Client/wwwroot/index.html @@ -21,5 +21,4 @@ - - + \ No newline at end of file diff --git a/BlazorDevIta.ERP.BlazorWasm/Server/BlazorDevIta.ERP.BlazorWasm.Server.csproj b/BlazorDevIta.ERP.BlazorWasm/Server/BlazorDevIta.ERP.BlazorWasm.Server.csproj index fe23697..7efdf60 100644 --- a/BlazorDevIta.ERP.BlazorWasm/Server/BlazorDevIta.ERP.BlazorWasm.Server.csproj +++ b/BlazorDevIta.ERP.BlazorWasm/Server/BlazorDevIta.ERP.BlazorWasm.Server.csproj @@ -7,7 +7,7 @@ - + all diff --git a/BlazorDevIta.ERP.BlazorWasm/Server/Controllers/WeatherForecastController.cs b/BlazorDevIta.ERP.BlazorWasm/Server/Controllers/WeatherForecastController.cs index b6e7d1b..e6857e0 100644 --- a/BlazorDevIta.ERP.BlazorWasm/Server/Controllers/WeatherForecastController.cs +++ b/BlazorDevIta.ERP.BlazorWasm/Server/Controllers/WeatherForecastController.cs @@ -1,101 +1,117 @@ using BlazorDevIta.ERP.Business.Data; using BlazorDevIta.ERP.Infrastructure; using BlazorDevIta.ERP.Shared; + using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; namespace BlazorDevIta.ERP.BlazorWasm.Server.Controllers { - [ApiController] - [Route("[controller]")] - public class WeatherForecastController : ControllerBase - { + [ApiController] + [Route("[controller]")] + public class WeatherForecastController : ControllerBase + { + private readonly ILogger _logger; + private readonly IRepository _repository; + + public WeatherForecastController( + IRepository repository, + ILogger logger) + { + _logger = logger; + _repository = repository; + } + + [HttpDelete("{id:int}")] + public async Task Delete(int id) + { + var entity = await _repository.GetByIdAsync(id); + if (entity == null) + { + return NotFound(); + } - private readonly ILogger _logger; - private readonly IRepository _repository; + await _repository.DeleteAsync(id); + return NoContent(); + } - public WeatherForecastController( - IRepository repository, - ILogger logger) - { - _logger = logger; - _repository = repository; - } + [HttpGet] + [ProducesResponseType(typeof(WeatherForecastListItem), StatusCodes.Status200OK)] + [ProducesDefaultResponseType] + public async Task Get() + { + var result = await _repository.GetAll() + .Select(x => + new WeatherForecastListItem() + { + Id = x.Id, + Date = x.Date, + TemperatureC = x.TemperatureC + }).ToListAsync(); - [HttpGet] - public async Task Get() - { - var result = await _repository.GetAll() - .Select(x => - new WeatherForecastListItem() - { - Id = x.Id, - Date = x.Date, - TemperatureC = x.TemperatureC - }).ToListAsync(); + return Ok(result); + } - return Ok(result); - } + [HttpGet("{id:int}")] + [ProducesDefaultResponseType] + public async Task GetById(int id) + { + var entity = await _repository.GetByIdAsync(id); + if (entity == null) + { + return NotFound(); + } - [HttpGet("{id}")] - public async Task GetById(int id) - { - var entity = await _repository.GetByIdAsync(id); - if (entity == null) return NotFound(); + var result = new WeatherForecastDetails() + { + Id = entity.Id, + Date = entity.Date, + TemperatureC = entity.TemperatureC, + Summary = entity.Summary + }; - var result = new WeatherForecastDetails() - { - Id = entity.Id, - Date = entity.Date, - TemperatureC = entity.TemperatureC, - Summary = entity.Summary - }; + return Ok(result); + } - return Ok(result); - } + [HttpPost] + public async Task Post(WeatherForecastDetails model) + { + if (ModelState.IsValid) + { + var entity = new WeatherForecast() + { + Id = model.Id, + Date = model.Date, + TemperatureC = model.TemperatureC, + Summary = model.Summary + }; + await _repository.CreateAsync(entity); - [HttpPost] - public async Task Post(WeatherForecastDetails model) - { - if (ModelState.IsValid) - { - var entity = new WeatherForecast() - { - Id = model.Id, - Date = model.Date, - TemperatureC = model.TemperatureC, - Summary = model.Summary - }; - await _repository.CreateAsync(entity); - return CreatedAtAction(nameof(GetById), new { id = model.Id }, model); - } - return BadRequest(model); - } + model.Id = entity.Id; - [HttpPut("{id}")] - public async Task Put(int id, WeatherForecastDetails model) - { - var entity = await _repository.GetByIdAsync(id); - if (entity == null) return NotFound(); + return CreatedAtAction(nameof(GetById), new { id = model.Id }, model); + } + return BadRequest(model); + } - if (ModelState.IsValid) - { - entity.Date = model.Date; - entity.TemperatureC = model.TemperatureC; - entity.Summary = model.Summary; - await _repository.UpdateAsync(entity); - return NoContent(); - } - return BadRequest(model); - } + [HttpPut("{id:int}")] + public async Task Put(int id, WeatherForecastDetails model) + { + var entity = await _repository.GetByIdAsync(id); + if (entity == null) + { + return NotFound(); + } - [HttpDelete("{id}")] - public async Task Delete(int id) - { - var entity = await _repository.GetByIdAsync(id); - if (entity == null) return NotFound(); - await _repository.DeleteAsync(id); - return NoContent(); - } - } + if (ModelState.IsValid) + { + entity.Date = model.Date; + entity.TemperatureC = model.TemperatureC; + entity.Summary = model.Summary; + await _repository.UpdateAsync(entity); + return NoContent(); + } + return BadRequest(model); + } + } } \ No newline at end of file diff --git a/BlazorDevIta.ERP.BlazorWasm/Server/Pages/Error.cshtml.cs b/BlazorDevIta.ERP.BlazorWasm/Server/Pages/Error.cshtml.cs index d04bdc7..7646069 100644 --- a/BlazorDevIta.ERP.BlazorWasm/Server/Pages/Error.cshtml.cs +++ b/BlazorDevIta.ERP.BlazorWasm/Server/Pages/Error.cshtml.cs @@ -1,27 +1,28 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; + using System.Diagnostics; namespace BlazorDevIta.ERP.BlazorWasm.Server.Pages { - [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] - [IgnoreAntiforgeryToken] - public class ErrorModel : PageModel - { - public string? RequestId { get; set; } + [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] + [IgnoreAntiforgeryToken] + public class ErrorModel : PageModel + { + public string? RequestId { get; set; } - public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); + public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); - private readonly ILogger _logger; + private readonly ILogger _logger; - public ErrorModel(ILogger logger) - { - _logger = logger; - } + public ErrorModel(ILogger logger) + { + _logger = logger; + } - public void OnGet() - { - RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier; - } - } + public void OnGet() + { + RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier; + } + } } \ No newline at end of file diff --git a/BlazorDevIta.ERP.BlazorWasm/Server/Program.cs b/BlazorDevIta.ERP.BlazorWasm/Server/Program.cs index 7347bc3..587287d 100644 --- a/BlazorDevIta.ERP.BlazorWasm/Server/Program.cs +++ b/BlazorDevIta.ERP.BlazorWasm/Server/Program.cs @@ -1,7 +1,7 @@ using BlazorDevIta.ERP.Business.Data; using BlazorDevIta.ERP.Infrastructure; using BlazorDevIta.ERP.Infrastructure.EF; -using Microsoft.AspNetCore.ResponseCompression; + using Microsoft.EntityFrameworkCore; var builder = WebApplication.CreateBuilder(args); @@ -12,9 +12,9 @@ builder.Services.AddRazorPages(); builder.Services.AddDbContext(opt => - opt.UseSqlServer( - builder.Configuration.GetConnectionString("DefaultConnection"), - b => b.MigrationsAssembly("BlazorDevIta.ERP.BlazorWasm.Server"))); + opt.UseSqlServer( + builder.Configuration.GetConnectionString("DefaultConnection"), + b => b.MigrationsAssembly("BlazorDevIta.ERP.BlazorWasm.Server"))); builder.Services.AddScoped(); builder.Services.AddScoped(typeof(IRepository<,>), typeof(EFRepository<,>)); @@ -24,13 +24,13 @@ // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) { - app.UseWebAssemblyDebugging(); + app.UseWebAssemblyDebugging(); } else { - app.UseExceptionHandler("/Error"); - // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. - app.UseHsts(); + app.UseExceptionHandler("/Error"); + // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. + app.UseHsts(); } app.UseHttpsRedirection(); @@ -40,9 +40,8 @@ app.UseRouting(); - app.MapRazorPages(); app.MapControllers(); app.MapFallbackToFile("index.html"); -app.Run(); +app.Run(); \ No newline at end of file diff --git a/BlazorDevIta.ERP.BlazorWasm/Server/Properties/launchSettings.json b/BlazorDevIta.ERP.BlazorWasm/Server/Properties/launchSettings.json index a0e0c27..6999074 100644 --- a/BlazorDevIta.ERP.BlazorWasm/Server/Properties/launchSettings.json +++ b/BlazorDevIta.ERP.BlazorWasm/Server/Properties/launchSettings.json @@ -1,30 +1,30 @@ { - "iisSettings": { - "windowsAuthentication": false, - "anonymousAuthentication": true, - "iisExpress": { - "applicationUrl": "http://localhost:14759", - "sslPort": 44321 + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:14759", + "sslPort": 44321 + } + }, + "profiles": { + "BlazorDevIta.ERP.BlazorWasm.Server": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", + "applicationUrl": "https://localhost:7063;http://localhost:5063", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" } }, - "profiles": { - "BlazorDevIta.ERP.BlazorWasm.Server": { - "commandName": "Project", - "dotnetRunMessages": true, - "launchBrowser": true, - "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", - "applicationUrl": "https://localhost:7063;http://localhost:5063", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } - }, - "IIS Express": { - "commandName": "IISExpress", - "launchBrowser": true, - "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" } } } +} \ No newline at end of file diff --git a/BlazorDevIta.ERP.BlazorWasm/Server/appsettings.Development.json b/BlazorDevIta.ERP.BlazorWasm/Server/appsettings.Development.json index 0c208ae..1b2d3ba 100644 --- a/BlazorDevIta.ERP.BlazorWasm/Server/appsettings.Development.json +++ b/BlazorDevIta.ERP.BlazorWasm/Server/appsettings.Development.json @@ -5,4 +5,4 @@ "Microsoft.AspNetCore": "Warning" } } -} +} \ No newline at end of file diff --git a/BlazorDevIta.ERP.BlazorWasm/Server/appsettings.json b/BlazorDevIta.ERP.BlazorWasm/Server/appsettings.json index 61994bb..dbed920 100644 --- a/BlazorDevIta.ERP.BlazorWasm/Server/appsettings.json +++ b/BlazorDevIta.ERP.BlazorWasm/Server/appsettings.json @@ -9,4 +9,4 @@ } }, "AllowedHosts": "*" -} +} \ No newline at end of file diff --git a/BlazorDevIta.ERP.Business/Data/ERPDbContext.cs b/BlazorDevIta.ERP.Business/Data/ERPDbContext.cs index aa640de..0441648 100644 --- a/BlazorDevIta.ERP.Business/Data/ERPDbContext.cs +++ b/BlazorDevIta.ERP.Business/Data/ERPDbContext.cs @@ -2,11 +2,11 @@ namespace BlazorDevIta.ERP.Business.Data { - public class ERPDbContext : DbContext - { - public ERPDbContext(DbContextOptions opt) - : base(opt) { } + public class ERPDbContext : DbContext + { + public ERPDbContext(DbContextOptions opt) + : base(opt) { } - public DbSet WeatherForecasts => Set(); - } -} + public DbSet WeatherForecasts => Set(); + } +} \ No newline at end of file diff --git a/BlazorDevIta.ERP.Business/Data/WeatherForecast.cs b/BlazorDevIta.ERP.Business/Data/WeatherForecast.cs index 2917a55..3d166d4 100644 --- a/BlazorDevIta.ERP.Business/Data/WeatherForecast.cs +++ b/BlazorDevIta.ERP.Business/Data/WeatherForecast.cs @@ -1,18 +1,19 @@ using BlazorDevIta.ERP.Infrastructure; + using System.ComponentModel.DataAnnotations; namespace BlazorDevIta.ERP.Business.Data { - public class WeatherForecast: IEntity - { - public int Id { get; set; } + public class WeatherForecast : IEntity + { + public int Id { get; set; } - public DateTime Date { get; set; } + public DateTime Date { get; set; } - public int TemperatureC { get; set; } + public int TemperatureC { get; set; } - [Required] - [MaxLength(50)] - public string? Summary { get; set; } - } -} + [Required] + [MaxLength(50)] + public string? Summary { get; set; } + } +} \ No newline at end of file diff --git a/BlazorDevIta.ERP.Infrastructure.EF/BlazorDevIta.ERP.Infrastructure.EF.csproj b/BlazorDevIta.ERP.Infrastructure.EF/BlazorDevIta.ERP.Infrastructure.EF.csproj index 0de616a..c67232e 100644 --- a/BlazorDevIta.ERP.Infrastructure.EF/BlazorDevIta.ERP.Infrastructure.EF.csproj +++ b/BlazorDevIta.ERP.Infrastructure.EF/BlazorDevIta.ERP.Infrastructure.EF.csproj @@ -7,7 +7,7 @@ - + diff --git a/BlazorDevIta.ERP.Infrastructure.EF/EFRepository.cs b/BlazorDevIta.ERP.Infrastructure.EF/EFRepository.cs index 4948b37..76584e8 100644 --- a/BlazorDevIta.ERP.Infrastructure.EF/EFRepository.cs +++ b/BlazorDevIta.ERP.Infrastructure.EF/EFRepository.cs @@ -2,53 +2,58 @@ namespace BlazorDevIta.ERP.Infrastructure.EF { - public class EFRepository - : IRepository - where TEntity : class, IEntity, new() - { - private readonly DbContext _dbContext; - private readonly DbSet _set; - - public EFRepository(DbContext dbContext) - { - _dbContext = dbContext; - _set = _dbContext.Set(); - } - - public IQueryable GetAll() - { - return _set.AsNoTracking(); - } - - public async Task GetByIdAsync(TKey id) - { - var entity = await _set.FindAsync(id); - if (entity == null) return null; - _dbContext.Entry(entity).State = EntityState.Detached; - return entity; - } - - public async Task CreateAsync(TEntity entity) - { - _set.Add(entity); - await _dbContext.SaveChangesAsync(); - _dbContext.Entry(entity).State = EntityState.Detached; - } - - public async Task UpdateAsync(TEntity entity) - { - _set.Update(entity); - await _dbContext.SaveChangesAsync(); - _dbContext.Entry(entity).State = EntityState.Detached; - } - public Task DeleteAsync(TKey id) - { - var entity = new TEntity() - { - Id = id, - }; - _set.Remove(entity); - return _dbContext.SaveChangesAsync(); - } - } + public class EFRepository + : IRepository + where TEntity : class, IEntity, new() + { + private readonly DbContext _dbContext; + private readonly DbSet _set; + + public EFRepository(DbContext dbContext) + { + _dbContext = dbContext; + _set = _dbContext.Set(); + } + + public IQueryable GetAll() + { + return _set.AsNoTracking(); + } + + public async Task GetByIdAsync(TKey id) + { + var entity = await _set.FindAsync(id); + if (entity == null) + { + return null; + } + + _dbContext.Entry(entity).State = EntityState.Detached; + return entity; + } + + public async Task CreateAsync(TEntity entity) + { + _set.Add(entity); + await _dbContext.SaveChangesAsync(); + _dbContext.Entry(entity).State = EntityState.Detached; + } + + public async Task UpdateAsync(TEntity entity) + { + _set.Update(entity); + await _dbContext.SaveChangesAsync(); + _dbContext.Entry(entity).State = EntityState.Detached; + } + + public Task DeleteAsync(TKey id) + { + var entity = new TEntity() + { + Id = id, + }; + _set.Remove(entity); + return _dbContext.SaveChangesAsync(); + } + } } \ No newline at end of file diff --git a/BlazorDevIta.ERP.Infrastructure/Attributes/HiddenAttribute.cs b/BlazorDevIta.ERP.Infrastructure/Attributes/HiddenAttribute.cs index 0483d09..1029fae 100644 --- a/BlazorDevIta.ERP.Infrastructure/Attributes/HiddenAttribute.cs +++ b/BlazorDevIta.ERP.Infrastructure/Attributes/HiddenAttribute.cs @@ -1,5 +1,6 @@ namespace BlazorDevIta.ERP.Infrastructure.Attributes { - [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false)] - public class HiddenAttribute : Attribute { } -} + [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false)] + public class HiddenAttribute : Attribute + { } +} \ No newline at end of file diff --git a/BlazorDevIta.ERP.Infrastructure/IEntity.cs b/BlazorDevIta.ERP.Infrastructure/IEntity.cs index acee15d..0602439 100644 --- a/BlazorDevIta.ERP.Infrastructure/IEntity.cs +++ b/BlazorDevIta.ERP.Infrastructure/IEntity.cs @@ -1,13 +1,7 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BlazorDevIta.ERP.Infrastructure +namespace BlazorDevIta.ERP.Infrastructure { - public interface IEntity - { - TKey Id { get; set; } - } -} + public interface IEntity + { + TKey Id { get; set; } + } +} \ No newline at end of file diff --git a/BlazorDevIta.ERP.Infrastructure/IRepository.cs b/BlazorDevIta.ERP.Infrastructure/IRepository.cs index bde5671..dc1ac9d 100644 --- a/BlazorDevIta.ERP.Infrastructure/IRepository.cs +++ b/BlazorDevIta.ERP.Infrastructure/IRepository.cs @@ -1,19 +1,16 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BlazorDevIta.ERP.Infrastructure +namespace BlazorDevIta.ERP.Infrastructure { - public interface IRepository - where TEntity : class, IEntity, new() - { - IQueryable GetAll(); - Task GetByIdAsync(TKey id); + public interface IRepository + where TEntity : class, IEntity, new() + { + IQueryable GetAll(); + + Task GetByIdAsync(TKey id); + + Task CreateAsync(TEntity entity); + + Task UpdateAsync(TEntity entity); - Task CreateAsync(TEntity entity); - Task UpdateAsync(TEntity entity); - Task DeleteAsync(TKey id); - } -} + Task DeleteAsync(TKey id); + } +} \ No newline at end of file diff --git a/BlazorDevIta.Shared/WeatherForecastDetails.cs b/BlazorDevIta.Shared/WeatherForecastDetails.cs index 68a1c80..6512b3e 100644 --- a/BlazorDevIta.Shared/WeatherForecastDetails.cs +++ b/BlazorDevIta.Shared/WeatherForecastDetails.cs @@ -2,18 +2,18 @@ namespace BlazorDevIta.ERP.Shared { - public class WeatherForecastDetails - { - public int Id { get; set; } + public class WeatherForecastDetails + { + public int Id { get; set; } - public DateTime Date { get; set; } + public DateTime Date { get; set; } - public int TemperatureC { get; set; } + public int TemperatureC { get; set; } - [Required] - [MaxLength(50)] - public string? Summary { get; set; } + [Required] + [MaxLength(50)] + public string? Summary { get; set; } - public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); - } + public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); + } } \ No newline at end of file diff --git a/BlazorDevIta.Shared/WeatherForecastListItem.cs b/BlazorDevIta.Shared/WeatherForecastListItem.cs index d740af3..528b77d 100644 --- a/BlazorDevIta.Shared/WeatherForecastListItem.cs +++ b/BlazorDevIta.Shared/WeatherForecastListItem.cs @@ -1,19 +1,18 @@ -using BlazorDevIta.ERP.Infrastructure.Attributes; using System.ComponentModel.DataAnnotations; namespace BlazorDevIta.ERP.Shared { - public class WeatherForecastListItem - { - public int Id { get; set; } + public class WeatherForecastListItem + { + public int Id { get; set; } - [DisplayFormat(DataFormatString = "{0:dd-MM-yyyy}")] - public DateTime Date { get; set; } + [DisplayFormat(DataFormatString = "{0:dd-MM-yyyy}")] + public DateTime Date { get; set; } - [Display(Name = "Temp (C)")] - public int TemperatureC { get; set; } + [Display(Name = "Temp (C)")] + public int TemperatureC { get; set; } - [Display(Name = "Temp (F)")] - public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); - } + [Display(Name = "Temp (F)")] + public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); + } } \ No newline at end of file diff --git a/BlazorDevIta.UI/BlazorDevIta.UI.csproj b/BlazorDevIta.UI/BlazorDevIta.UI.csproj index 75b06b8..48f2f2d 100644 --- a/BlazorDevIta.UI/BlazorDevIta.UI.csproj +++ b/BlazorDevIta.UI/BlazorDevIta.UI.csproj @@ -12,7 +12,7 @@ - + diff --git a/BlazorDevIta.UI/Services/IDataServices.cs b/BlazorDevIta.UI/Services/IDataServices.cs index a897735..7c9e0f5 100644 --- a/BlazorDevIta.UI/Services/IDataServices.cs +++ b/BlazorDevIta.UI/Services/IDataServices.cs @@ -2,14 +2,16 @@ namespace BlazorDevIta.UI.Services { - public interface IDataServices - { - Task> GetWeatherForecastsAsync(); + public interface IDataServices + { + Task> GetWeatherForecastsAsync(); - Task GetWeatherForecastByIdAsync(int id); + Task GetWeatherForecastByIdAsync(int id); - Task Create(WeatherForecastDetails details); - Task Update(WeatherForecastDetails details); - Task Delete(int id); - } -} + Task Create(WeatherForecastDetails details); + + Task Update(WeatherForecastDetails details); + + Task Delete(int id); + } +} \ No newline at end of file diff --git a/BlazorDevIta.UI/Shared/MainLayout.razor.css b/BlazorDevIta.UI/Shared/MainLayout.razor.css index c865427..bd27bb0 100644 --- a/BlazorDevIta.UI/Shared/MainLayout.razor.css +++ b/BlazorDevIta.UI/Shared/MainLayout.razor.css @@ -27,14 +27,14 @@ main { text-decoration: none; } - .top-row ::deep a:hover, .top-row ::deep .btn-link:hover { - text-decoration: underline; - } + .top-row ::deep a:hover, .top-row ::deep .btn-link:hover { + text-decoration: underline; + } - .top-row ::deep a:first-child { - overflow: hidden; - text-overflow: ellipsis; - } + .top-row ::deep a:first-child { + overflow: hidden; + text-overflow: ellipsis; + } @media (max-width: 640.98px) { .top-row:not(.auth) { @@ -68,14 +68,14 @@ main { z-index: 1; } - .top-row.auth ::deep a:first-child { - flex: 1; - text-align: right; - width: 0; - } + .top-row.auth ::deep a:first-child { + flex: 1; + text-align: right; + width: 0; + } .top-row, article { padding-left: 2rem !important; padding-right: 1.5rem !important; } -} +} \ No newline at end of file diff --git a/BlazorDevIta.UI/Shared/NavMenu.razor.css b/BlazorDevIta.UI/Shared/NavMenu.razor.css index acc5f9f..e132378 100644 --- a/BlazorDevIta.UI/Shared/NavMenu.razor.css +++ b/BlazorDevIta.UI/Shared/NavMenu.razor.css @@ -40,15 +40,15 @@ line-height: 3rem; } -.nav-item ::deep a.active { - background-color: rgba(255,255,255,0.25); - color: white; -} + .nav-item ::deep a.active { + background-color: rgba(255,255,255,0.25); + color: white; + } -.nav-item ::deep a:hover { - background-color: rgba(255,255,255,0.1); - color: white; -} + .nav-item ::deep a:hover { + background-color: rgba(255,255,255,0.1); + color: white; + } @media (min-width: 641px) { .navbar-toggler { @@ -59,4 +59,4 @@ /* Never collapse the sidebar for wide screens */ display: block; } -} +} \ No newline at end of file