This repository has been archived by the owner on Jan 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 47
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
Showing
8 changed files
with
227 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,39 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 15 | ||
VisualStudioVersion = 15.0.26020.0 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{31993304-902E-437F-A24B-2BC6F17061F3}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lab8", "src\Lab8\Lab8.csproj", "{9D59F770-EF3E-427E-A1C0-564306372914}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Debug|x64 = Debug|x64 | ||
Debug|x86 = Debug|x86 | ||
Release|Any CPU = Release|Any CPU | ||
Release|x64 = Release|x64 | ||
Release|x86 = Release|x86 | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{9D59F770-EF3E-427E-A1C0-564306372914}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{9D59F770-EF3E-427E-A1C0-564306372914}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{9D59F770-EF3E-427E-A1C0-564306372914}.Debug|x64.ActiveCfg = Debug|x64 | ||
{9D59F770-EF3E-427E-A1C0-564306372914}.Debug|x64.Build.0 = Debug|x64 | ||
{9D59F770-EF3E-427E-A1C0-564306372914}.Debug|x86.ActiveCfg = Debug|x86 | ||
{9D59F770-EF3E-427E-A1C0-564306372914}.Debug|x86.Build.0 = Debug|x86 | ||
{9D59F770-EF3E-427E-A1C0-564306372914}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{9D59F770-EF3E-427E-A1C0-564306372914}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{9D59F770-EF3E-427E-A1C0-564306372914}.Release|x64.ActiveCfg = Release|x64 | ||
{9D59F770-EF3E-427E-A1C0-564306372914}.Release|x64.Build.0 = Release|x64 | ||
{9D59F770-EF3E-427E-A1C0-564306372914}.Release|x86.ActiveCfg = Release|x86 | ||
{9D59F770-EF3E-427E-A1C0-564306372914}.Release|x86.Build.0 = Release|x86 | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(NestedProjects) = preSolution | ||
{9D59F770-EF3E-427E-A1C0-564306372914} = {31993304-902E-437F-A24B-2BC6F17061F3} | ||
EndGlobalSection | ||
EndGlobal |
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,48 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Lab8.Models; | ||
|
||
namespace Lab8.Controllers | ||
{ | ||
[Route("/api/[controller]")] | ||
[Produces("application/json")] | ||
public class ProductsController : ControllerBase | ||
{ | ||
private static List<Product> _products = new List<Product>(new[] { | ||
new Product() { Id = 1, Name = "Computer" }, | ||
new Product() { Id = 2, Name = "Radio" }, | ||
new Product() { Id = 3, Name = "Apple" }, | ||
}); | ||
|
||
[HttpGet] | ||
public IEnumerable<Product> Get() => _products; | ||
|
||
[HttpGet("{id}")] | ||
public IActionResult Get(int id) | ||
{ | ||
var product = _products.SingleOrDefault(p => p.Id == id); | ||
|
||
if (product == null) | ||
{ | ||
return NotFound(); | ||
} | ||
|
||
return Ok(product); | ||
} | ||
|
||
[HttpPost] | ||
public IActionResult Post([FromBody]Product product) | ||
{ | ||
if (!ModelState.IsValid) | ||
{ | ||
return BadRequest(ModelState); | ||
} | ||
|
||
_products.Add(product); | ||
return CreatedAtAction(nameof(Get), new { id = product.Id }, product); | ||
} | ||
} | ||
} |
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,21 @@ | ||
<Project ToolsVersion="15.0" Sdk="Microsoft.NET.Sdk.Web"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp1.0</TargetFramework> | ||
<PreserveCompilationContext>true</PreserveCompilationContext> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Folder Include="wwwroot\" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore.Mvc.DataAnnotations" Version="1.0.2" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Formatters.Json" Version="1.0.2" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Formatters.Xml" Version="1.0.2" /> | ||
<PackageReference Include="Microsoft.NETCore.App" Version="1.0.1" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="1.0.2" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Diagnostics" Version="1.0.0" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="1.0.0" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="1.0.1" /> | ||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.0.0" /> | ||
</ItemGroup> | ||
</Project> |
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 System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel.DataAnnotations; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
|
||
namespace Lab8.Models | ||
{ | ||
public class Product | ||
{ | ||
public int Id { get; set; } | ||
|
||
[Required] | ||
public string Name { 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,24 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Hosting; | ||
|
||
namespace Lab8 | ||
{ | ||
public class Program | ||
{ | ||
public static void Main(string[] args) | ||
{ | ||
var host = new WebHostBuilder() | ||
.UseKestrel() | ||
.UseContentRoot(Directory.GetCurrentDirectory()) | ||
.UseIISIntegration() | ||
.UseStartup<Startup>() | ||
.Build(); | ||
|
||
host.Run(); | ||
} | ||
} | ||
} |
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,27 @@ | ||
{ | ||
"iisSettings": { | ||
"windowsAuthentication": false, | ||
"anonymousAuthentication": true, | ||
"iisExpress": { | ||
"applicationUrl": "http://localhost:51418/", | ||
"sslPort": 0 | ||
} | ||
}, | ||
"profiles": { | ||
"IIS Express": { | ||
"commandName": "IISExpress", | ||
"launchBrowser": true, | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
}, | ||
"Lab8": { | ||
"commandName": "Project", | ||
"launchBrowser": true, | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
}, | ||
"applicationUrl": "http://localhost:51419" | ||
} | ||
} | ||
} |
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,38 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Lab8 | ||
{ | ||
public class Startup | ||
{ | ||
// This method gets called by the runtime. Use this method to add services to the container. | ||
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 | ||
public void ConfigureServices(IServiceCollection services) | ||
{ | ||
services.AddMvcCore() | ||
.AddJsonFormatters() | ||
.AddXmlDataContractSerializerFormatters() | ||
.AddDataAnnotations(); | ||
} | ||
|
||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. | ||
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) | ||
{ | ||
loggerFactory.AddConsole(); | ||
|
||
if (env.IsDevelopment()) | ||
{ | ||
app.UseDeveloperExceptionPage(); | ||
} | ||
|
||
app.UseMvc(); | ||
} | ||
} | ||
} |
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,14 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<configuration> | ||
|
||
<!-- | ||
Configure your application settings in appsettings.json. Learn more at https://go.microsoft.com/fwlink/?LinkId=786380 | ||
--> | ||
|
||
<system.webServer> | ||
<handlers> | ||
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified"/> | ||
</handlers> | ||
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false"/> | ||
</system.webServer> | ||
</configuration> |