Skip to content

Commit

Permalink
Fix Web Api Post, Update dll to last version, refactoring code.
Browse files Browse the repository at this point in the history
  • Loading branch information
totti240282 committed Apr 26, 2022
1 parent 7090052 commit 07704d3
Show file tree
Hide file tree
Showing 34 changed files with 462 additions and 444 deletions.
Original file line number Diff line number Diff line change
@@ -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<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Date = table.Column<DateTime>(type: "datetime2", nullable: false),
TemperatureC = table.Column<int>(type: "int", nullable: false),
Summary = table.Column<string>(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<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Date = table.Column<DateTime>(type: "datetime2", nullable: false),
TemperatureC = table.Column<int>(type: "int", nullable: false),
Summary = table.Column<string>(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");
}
}
}
33 changes: 17 additions & 16 deletions BlazorDevIta.ERP.BlazorServer/Pages/Error.cshtml.cs
Original file line number Diff line number Diff line change
@@ -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<ErrorModel> _logger;
private readonly ILogger<ErrorModel> _logger;

public ErrorModel(ILogger<ErrorModel> logger)
{
_logger = logger;
}
public ErrorModel(ILogger<ErrorModel> logger)
{
_logger = logger;
}

public void OnGet()
{
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
}
}
public void OnGet()
{
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
}
}
}
20 changes: 9 additions & 11 deletions BlazorDevIta.ERP.BlazorServer/Program.cs
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -16,22 +15,21 @@
builder.Services.AddScoped<IDataServices, DataServices>();

builder.Services.AddDbContext<ERPDbContext>(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<DbContext, ERPDbContext>();
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();
Expand All @@ -43,4 +41,4 @@
app.MapBlazorHub();
app.MapFallbackToPage("/_Host");

app.Run();
app.Run();
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@
}
}
}
}
}
118 changes: 61 additions & 57 deletions BlazorDevIta.ERP.BlazorServer/Services/DataServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<WeatherForecast, int> _repository;
public class DataServices : IDataServices
{
private readonly IRepository<WeatherForecast, int> _repository;

public DataServices(IRepository<WeatherForecast, int> repository)
{
_repository = repository;
}
public DataServices(IRepository<WeatherForecast, int> repository)
{
_repository = repository;
}

public Task<List<WeatherForecastListItem?>> GetWeatherForecastsAsync()
{
return _repository.GetAll()
.Select(x =>
new WeatherForecastListItem()
{
Id = x.Id,
Date = x.Date,
TemperatureC = x.TemperatureC
}).ToListAsync<WeatherForecastListItem?>();
}
public Task<List<WeatherForecastListItem?>> GetWeatherForecastsAsync()
{
return _repository.GetAll()
.Select(x =>
new WeatherForecastListItem()
{
Id = x.Id,
Date = x.Date,
TemperatureC = x.TemperatureC
}).ToListAsync<WeatherForecastListItem?>();
}

public async Task<WeatherForecastDetails?> GetWeatherForecastByIdAsync(int id)
{
var x = await _repository.GetByIdAsync(id);
if (x == null) return null;
public async Task<WeatherForecastDetails?> 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);
}
}
}
2 changes: 1 addition & 1 deletion BlazorDevIta.ERP.BlazorServer/appsettings.Development.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
"Microsoft.AspNetCore": "Warning"
}
}
}
}
2 changes: 1 addition & 1 deletion BlazorDevIta.ERP.BlazorServer/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
}
},
"AllowedHosts": "*"
}
}
2 changes: 1 addition & 1 deletion BlazorDevIta.ERP.BlazorServer/wwwroot/css/site.css
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,4 @@ a, .btn-link {

.blazor-error-boundary::after {
content: "An error has occurred."
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="6.0.2" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="6.0.2" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="6.0.4" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="6.0.4" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
Expand Down
3 changes: 2 additions & 1 deletion BlazorDevIta.ERP.BlazorWasm/Client/Program.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -11,4 +12,4 @@
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
builder.Services.AddScoped<IDataServices, DataServices>();

await builder.Build().RunAsync();
await builder.Build().RunAsync();
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@
}
}
}
}
}
Loading

0 comments on commit 07704d3

Please sign in to comment.