-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a866988
commit d81ef50
Showing
61 changed files
with
1,744 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.9.34622.214 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ApiDemoApp", "ApiDemoApp\ApiDemoApp.csproj", "{1AA43B76-08A9-4356-88AB-4D2E8A44AEDB}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{1AA43B76-08A9-4356-88AB-4D2E8A44AEDB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{1AA43B76-08A9-4356-88AB-4D2E8A44AEDB}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{1AA43B76-08A9-4356-88AB-4D2E8A44AEDB}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{1AA43B76-08A9-4356-88AB-4D2E8A44AEDB}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {73C42076-E074-4126-8AB8-06135EFBC7EF} | ||
EndGlobalSection | ||
EndGlobal |
12 changes: 12 additions & 0 deletions
12
OwnProjects/ASP.NET Course/ApiDemo/ApiDemoApp/.config/dotnet-tools.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"version": 1, | ||
"isRoot": true, | ||
"tools": { | ||
"dotnet-ef": { | ||
"version": "8.0.2", | ||
"commands": [ | ||
"dotnet-ef" | ||
] | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
OwnProjects/ASP.NET Course/ApiDemo/ApiDemoApp/ApiDemoApp.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<UserSecretsId>1134f7ac-ad27-4e0e-be29-276d1367c5ff</UserSecretsId> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Dapper" Version="2.1.28" /> | ||
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.2.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Reference Include="DataLibrary"> | ||
<HintPath>DataLibrary.dll</HintPath> | ||
</Reference> | ||
</ItemGroup> | ||
|
||
</Project> |
6 changes: 6 additions & 0 deletions
6
OwnProjects/ASP.NET Course/ApiDemo/ApiDemoApp/ApiDemoApp.http
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
@ApiDemoApp_HostAddress = http://localhost:5291 | ||
|
||
GET {{ApiDemoApp_HostAddress}}/weatherforecast/ | ||
Accept: application/json | ||
|
||
### |
24 changes: 24 additions & 0 deletions
24
OwnProjects/ASP.NET Course/ApiDemo/ApiDemoApp/Controllers/FoodController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using DataLibrary.Data; | ||
using DataLibrary.Models; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace ApiDemoApp.Controllers | ||
{ | ||
[Route("api/[controller]")] | ||
[ApiController] | ||
public class FoodController : ControllerBase | ||
{ | ||
private readonly IFoodData _foodData; | ||
|
||
public FoodController(IFoodData foodData) | ||
{ | ||
_foodData = foodData; | ||
} | ||
[HttpGet] | ||
public async Task<List<FoodModel>> Get() | ||
{ | ||
return await _foodData.GetFood(); | ||
} | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
OwnProjects/ASP.NET Course/ApiDemo/ApiDemoApp/Controllers/OrderController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
using ApiDemoApp.Model; | ||
using DataLibrary.Data; | ||
using DataLibrary.Models; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace ApiDemoApp.Controllers | ||
{ | ||
[Route("api/[controller]")] | ||
[ApiController] | ||
public class OrderController : ControllerBase | ||
{ | ||
private readonly IOrderData _orderData; | ||
private readonly IFoodData _foodData; | ||
|
||
public OrderController(IOrderData orderData,IFoodData foodData) | ||
{ | ||
_orderData = orderData; | ||
_foodData = foodData; | ||
} | ||
|
||
[HttpPost] | ||
[ProducesResponseType(StatusCodes.Status200OK)] | ||
[ProducesResponseType(StatusCodes.Status400BadRequest)] | ||
public async Task<IActionResult> Post(OrderModel order) | ||
{ | ||
var food = await _foodData.GetFood(); | ||
|
||
order.Total = order.Quantity * food.Where(x => x.Id == order.FoodId).First().Price; | ||
|
||
int id = await _orderData.CreateOrder(order); | ||
|
||
return Ok(new { Id = id }); | ||
} | ||
|
||
[HttpGet("{id}")] | ||
[ProducesResponseType(StatusCodes.Status200OK)] | ||
[ProducesResponseType(StatusCodes.Status400BadRequest)] | ||
[ProducesResponseType(StatusCodes.Status404NotFound)] | ||
public async Task<IActionResult> Get(int id) | ||
{ | ||
if(id == 0) | ||
{ | ||
return BadRequest(); | ||
} | ||
|
||
var order = await _orderData.GetOrderById(id); | ||
|
||
if(order != null) | ||
{ | ||
var food = await _foodData.GetFood(); | ||
var output = new | ||
{ | ||
Order = order, | ||
ItemPurchased = food.Where(x => x.Id == order.FoodId).FirstOrDefault()?.Title | ||
}; | ||
|
||
return Ok(output); | ||
} | ||
else | ||
{ | ||
return NotFound(); | ||
} | ||
} | ||
|
||
[HttpPut] | ||
[ProducesResponseType(StatusCodes.Status200OK)] | ||
[ProducesResponseType(StatusCodes.Status400BadRequest)] | ||
|
||
public async Task<IActionResult> Put([FromBody] OrderUpdateModel data) | ||
{ | ||
await _orderData.UpdateOrderName(data.Id, data.OrderName); | ||
return Ok(); | ||
} | ||
|
||
[HttpDelete("{id}")] | ||
[ProducesResponseType(StatusCodes.Status200OK)] | ||
[ProducesResponseType(StatusCodes.Status400BadRequest)] | ||
public async Task<IActionResult> Delete(int id) | ||
{ | ||
await _orderData.DeleteOrder(id); | ||
return Ok(new { Id = id }); | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
OwnProjects/ASP.NET Course/ApiDemo/ApiDemoApp/Controllers/ValidateModelAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Mvc.Filters; | ||
|
||
namespace ApiDemoApp.Controllers | ||
{ | ||
public class ValidateModelAttribute : ActionFilterAttribute | ||
{ | ||
public override void OnActionExecuted(ActionExecutedContext context) | ||
{ | ||
if(context.ModelState.IsValid == false) | ||
{ | ||
context.Result = new BadRequestObjectResult(context.ModelState); | ||
} | ||
} | ||
} | ||
} |
Binary file not shown.
8 changes: 8 additions & 0 deletions
8
OwnProjects/ASP.NET Course/ApiDemo/ApiDemoApp/Model/OrderUpdateModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace ApiDemoApp.Model | ||
{ | ||
public class OrderUpdateModel | ||
{ | ||
public int Id { get; set; } | ||
public string OrderName { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using DataLibrary.Data; | ||
using DataLibrary.Db; | ||
|
||
var builder = WebApplication.CreateBuilder(args); | ||
|
||
// Add services to the container. | ||
|
||
builder.Services.AddControllers(); | ||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle | ||
builder.Services.AddEndpointsApiExplorer(); | ||
builder.Services.AddSwaggerGen(); | ||
|
||
builder.Services.AddSingleton(new ConnectionStringData | ||
{ | ||
SqlConnectionName = "Default" | ||
}); | ||
builder.Services.AddSingleton<IDataAccess, SqlDb>(); | ||
builder.Services.AddSingleton<IFoodData, FoodData>(); | ||
builder.Services.AddSingleton<IOrderData, OrderData>(); | ||
|
||
builder.Services.AddCors(options => | ||
{ | ||
options.AddPolicy("AllowOrigin", builder => builder.AllowAnyOrigin() | ||
.AllowAnyMethod() | ||
.AllowAnyHeader()); | ||
}); | ||
|
||
|
||
var app = builder.Build(); | ||
|
||
// Configure the HTTP request pipeline. | ||
if (app.Environment.IsDevelopment()) | ||
{ | ||
app.UseSwagger(); | ||
app.UseSwaggerUI(); | ||
} | ||
else | ||
{ | ||
app.UseSwagger(); | ||
app.UseSwaggerUI(); | ||
} | ||
|
||
|
||
|
||
app.UseHttpsRedirection(); | ||
|
||
app.UseCors(); | ||
|
||
app.UseAuthorization(); | ||
|
||
app.MapControllers(); | ||
|
||
|
||
app.Run(); |
41 changes: 41 additions & 0 deletions
41
OwnProjects/ASP.NET Course/ApiDemo/ApiDemoApp/Properties/launchSettings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{ | ||
"$schema": "http://json.schemastore.org/launchsettings.json", | ||
"iisSettings": { | ||
"windowsAuthentication": false, | ||
"anonymousAuthentication": true, | ||
"iisExpress": { | ||
"applicationUrl": "http://localhost:53936", | ||
"sslPort": 44360 | ||
} | ||
}, | ||
"profiles": { | ||
"http": { | ||
"commandName": "Project", | ||
"dotnetRunMessages": true, | ||
"launchBrowser": true, | ||
"launchUrl": "swagger", | ||
"applicationUrl": "http://localhost:5291", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
}, | ||
"https": { | ||
"commandName": "Project", | ||
"dotnetRunMessages": true, | ||
"launchBrowser": true, | ||
"launchUrl": "swagger", | ||
"applicationUrl": "https://localhost:7098;http://localhost:5291", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
}, | ||
"IIS Express": { | ||
"commandName": "IISExpress", | ||
"launchBrowser": true, | ||
"launchUrl": "swagger", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
OwnProjects/ASP.NET Course/ApiDemo/ApiDemoApp/appsettings.Development.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.AspNetCore": "Warning" | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
OwnProjects/ASP.NET Course/ApiDemo/ApiDemoApp/appsettings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.AspNetCore": "Warning" | ||
} | ||
}, | ||
"AllowedHosts": "*", | ||
"ConnectionStrings": { | ||
"Default": "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=JuansDinerDB;Integrated Security=True;Connect Timeout=30;Encrypt=False;Trust Server Certificate=False;Application Intent=ReadWrite;Multi Subnet Failover=False" | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
OwnProjects/ASP.NET Course/BlazorClientDemo/BlazorClientDemo.sln
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.9.34622.214 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazorClientDemoApp", "BlazorClientDemoApp\BlazorClientDemoApp.csproj", "{1CF9C27D-AD88-42FD-8B41-5D455C00C0C5}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{1CF9C27D-AD88-42FD-8B41-5D455C00C0C5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{1CF9C27D-AD88-42FD-8B41-5D455C00C0C5}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{1CF9C27D-AD88-42FD-8B41-5D455C00C0C5}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{1CF9C27D-AD88-42FD-8B41-5D455C00C0C5}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {511B12A8-C40C-452D-91B9-A921A153E28B} | ||
EndGlobalSection | ||
EndGlobal |
12 changes: 12 additions & 0 deletions
12
OwnProjects/ASP.NET Course/BlazorClientDemo/BlazorClientDemoApp/App.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<Router AppAssembly="@typeof(App).Assembly"> | ||
<Found Context="routeData"> | ||
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" /> | ||
<FocusOnNavigate RouteData="@routeData" Selector="h1" /> | ||
</Found> | ||
<NotFound> | ||
<PageTitle>Not found</PageTitle> | ||
<LayoutView Layout="@typeof(MainLayout)"> | ||
<p role="alert">Sorry, there's nothing at this address.</p> | ||
</LayoutView> | ||
</NotFound> | ||
</Router> |
15 changes: 15 additions & 0 deletions
15
OwnProjects/ASP.NET Course/BlazorClientDemo/BlazorClientDemoApp/BlazorClientDemoApp.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="6.0.0" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.2" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.2" PrivateAssets="all" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Oops, something went wrong.