Skip to content
This repository has been archived by the owner on Jan 3, 2024. It is now read-only.

Commit

Permalink
Added Lab8 code
Browse files Browse the repository at this point in the history
  • Loading branch information
davidfowl committed Jan 17, 2017
1 parent c0dbe57 commit 4da59cd
Show file tree
Hide file tree
Showing 8 changed files with 227 additions and 0 deletions.
39 changes: 39 additions & 0 deletions Labs/Code/Lab8/Lab8.sln
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
48 changes: 48 additions & 0 deletions Labs/Code/Lab8/src/Lab8/Controllers/ProductsController.cs
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);
}
}
}
21 changes: 21 additions & 0 deletions Labs/Code/Lab8/src/Lab8/Lab8.csproj
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>
16 changes: 16 additions & 0 deletions Labs/Code/Lab8/src/Lab8/Models/Product.cs
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; }
}
}
24 changes: 24 additions & 0 deletions Labs/Code/Lab8/src/Lab8/Program.cs
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();
}
}
}
27 changes: 27 additions & 0 deletions Labs/Code/Lab8/src/Lab8/Properties/launchSettings.json
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"
}
}
}
38 changes: 38 additions & 0 deletions Labs/Code/Lab8/src/Lab8/Startup.cs
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();
}
}
}
14 changes: 14 additions & 0 deletions Labs/Code/Lab8/src/Lab8/web.config
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>

0 comments on commit 4da59cd

Please sign in to comment.