Skip to content

Commit 60b3635

Browse files
FabianGosebrinkFabianGosebrink
authored andcommitted
Initial commit
1 parent 20a2e8b commit 60b3635

File tree

15 files changed

+580
-0
lines changed

15 files changed

+580
-0
lines changed

SampleWebApiMVC6.sln

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 14
4+
VisualStudioVersion = 14.0.23107.0
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{F7E300EF-0B6D-46B2-8570-B1FA8A43FC11}"
7+
EndProject
8+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{E6D256BA-07C1-4A30-96DF-01491A8D5952}"
9+
ProjectSection(SolutionItems) = preProject
10+
global.json = global.json
11+
EndProjectSection
12+
EndProject
13+
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "SampleWebApiMVC6", "src\SampleWebApiMVC6\SampleWebApiMVC6.xproj", "{7E499032-B503-4410-A9A2-4B05D7E82B18}"
14+
EndProject
15+
Global
16+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
17+
Debug|Any CPU = Debug|Any CPU
18+
Release|Any CPU = Release|Any CPU
19+
EndGlobalSection
20+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
21+
{7E499032-B503-4410-A9A2-4B05D7E82B18}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
22+
{7E499032-B503-4410-A9A2-4B05D7E82B18}.Debug|Any CPU.Build.0 = Debug|Any CPU
23+
{7E499032-B503-4410-A9A2-4B05D7E82B18}.Release|Any CPU.ActiveCfg = Release|Any CPU
24+
{7E499032-B503-4410-A9A2-4B05D7E82B18}.Release|Any CPU.Build.0 = Release|Any CPU
25+
EndGlobalSection
26+
GlobalSection(SolutionProperties) = preSolution
27+
HideSolutionNode = FALSE
28+
EndGlobalSection
29+
GlobalSection(NestedProjects) = preSolution
30+
{7E499032-B503-4410-A9A2-4B05D7E82B18} = {F7E300EF-0B6D-46B2-8570-B1FA8A43FC11}
31+
EndGlobalSection
32+
EndGlobal

global.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"projects": [ "src", "test" ],
3+
"sdk": {
4+
"version": "1.0.0-beta5",
5+
"runtime": "clr",
6+
"architecture": "x86"
7+
}
8+
}
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Microsoft.AspNet.Mvc;
6+
using SampleWebApiMVC6.Models;
7+
using SampleWebApiMVC6.Services;
8+
9+
namespace SampleWebApiMVC6.Controllers
10+
{
11+
[Route("api/[controller]")]
12+
public class HouseController : Controller
13+
{
14+
private readonly IHouseMapper _houseMapper;
15+
16+
public HouseController(IHouseMapper houseMapper)
17+
{
18+
_houseMapper = houseMapper;
19+
}
20+
21+
[HttpGet]
22+
public IActionResult Get()
23+
{
24+
return new ObjectResult(Singleton.Instance.Houses.Select(x => _houseMapper.MapToDto(x)));
25+
}
26+
27+
[HttpGet]
28+
[Route("{id:int}", Name="GetSingleHouse")]
29+
public IActionResult GetSingle(int id)
30+
{
31+
HouseEntity houseEntity = Singleton.Instance.Houses.FirstOrDefault(x => x.Id == id);
32+
33+
if(houseEntity == null)
34+
{
35+
return new HttpNotFoundResult();
36+
}
37+
38+
return new ObjectResult(_houseMapper.MapToDto(houseEntity));
39+
}
40+
41+
[HttpPost]
42+
public IActionResult Create([FromBody] HouseDto houseDto)
43+
{
44+
if(houseDto == null)
45+
{
46+
return HttpBadRequest();
47+
}
48+
49+
if(!ModelState.IsValid)
50+
{
51+
return new BadRequestObjectResult(ModelState);
52+
}
53+
54+
HouseEntity houseEntity = _houseMapper.MapToEntity(houseDto);
55+
56+
Singleton.Instance.Houses.Add(houseEntity);
57+
58+
return CreatedAtRoute("GetSingleHouse", new { id = houseEntity.Id }, _houseMapper.MapToDto(houseEntity));
59+
}
60+
61+
[HttpPut]
62+
[Route("{id:int}")]
63+
public IActionResult Update(int id, [FromBody] HouseDto houseDto)
64+
{
65+
if(houseDto == null)
66+
{
67+
return HttpBadRequest();
68+
}
69+
70+
if(!ModelState.IsValid)
71+
{
72+
return new BadRequestObjectResult(ModelState);
73+
}
74+
75+
HouseEntity houseEntityToUpdate = Singleton.Instance.Houses.FirstOrDefault(x => x.Id == id);
76+
77+
if(houseEntityToUpdate == null)
78+
{
79+
return new HttpNotFoundResult();
80+
}
81+
82+
houseEntityToUpdate.ZipCode = houseDto.ZipCode;
83+
houseEntityToUpdate.Street = houseDto.Street;
84+
houseEntityToUpdate.City = houseDto.City;
85+
86+
//Update to Database --> Is singleton in this case....
87+
88+
return new ObjectResult(_houseMapper.MapToDto(houseEntityToUpdate));
89+
}
90+
91+
[HttpDelete]
92+
[Route("{id:int}")]
93+
public IActionResult Delete(int id)
94+
{
95+
HouseEntity houseEntityToDelete = Singleton.Instance.Houses.FirstOrDefault(x => x.Id == id);
96+
97+
if(houseEntityToDelete == null)
98+
{
99+
return new HttpNotFoundResult();
100+
}
101+
102+
Singleton.Instance.Houses.Remove(houseEntityToDelete);
103+
104+
return new NoContentResult();
105+
}
106+
}
107+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System.ComponentModel.DataAnnotations;
2+
3+
namespace SampleWebApiMVC6.Models
4+
{
5+
public class HouseDto
6+
{
7+
public int Id { get; set; }
8+
9+
[Required, MinLength(3)]
10+
public string Street { get; set; }
11+
12+
[Required, MinLength(3)]
13+
public string City { get; set; }
14+
15+
[Required]
16+
[DataType(DataType.PostalCode)]
17+
public int ZipCode { get; set; }
18+
}
19+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace SampleWebApiMVC6.Models
2+
{
3+
public class HouseEntity
4+
{
5+
public int Id { get; set; }
6+
public string Street { get; set; }
7+
public string City { get; set; }
8+
public int ZipCode { get; set; }
9+
}
10+
}
Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<title>Welcome to ASP.NET 5</title>
6+
<style>
7+
html {
8+
background: #f1f1f1;
9+
height: 100%;
10+
}
11+
12+
body {
13+
background: #fff;
14+
color: #505050;
15+
font: 14px 'Segoe UI', tahoma, arial, helvetica, sans-serif;
16+
margin: 1%;
17+
min-height: 95.5%;
18+
border: 1px solid silver;
19+
position: relative;
20+
}
21+
22+
#header {
23+
padding: 0;
24+
}
25+
26+
#header h1 {
27+
font-size: 44px;
28+
font-weight: normal;
29+
margin: 0;
30+
padding: 10px 30px 10px 30px;
31+
}
32+
33+
#header span {
34+
margin: 0;
35+
padding: 0 30px;
36+
display: block;
37+
}
38+
39+
#header p {
40+
font-size: 20px;
41+
color: #fff;
42+
background: #007acc;
43+
padding: 0 30px;
44+
line-height: 50px;
45+
margin-top: 25px;
46+
47+
}
48+
49+
#header p a {
50+
color: #fff;
51+
text-decoration: underline;
52+
font-weight: bold;
53+
padding-right: 35px;
54+
background: no-repeat right bottom url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABcAAAAWCAMAAAAcqPc3AAAANlBMVEUAAAAAeswfitI9mthXp91us+KCvuaTx+mjz+2x1u+83PLH4vTR5/ba7Pjj8Pns9fv1+v3////wy3dWAAAAAXRSTlMAQObYZgAAAHxJREFUeNp9kVcSwCAIRMHUYoH7XzaxOxJ9P8oyQ1uIqNPwh3s2aLmIM2YtqrLcQIeQEylhuCeUOlhgve5yoBCfWmlnlgkN4H8ykbpaE7gR03AbUHiwoOxUH9Xp+ubd41p1HF3mBPrfC87BHeTdaB3ceeKL9HGpcvX9zu6+DdMWT9KQPvYAAAAASUVORK5CYII=);
55+
}
56+
57+
#main {
58+
padding: 5px 30px;
59+
clear: both;
60+
}
61+
62+
.section {
63+
width: 21.7%;
64+
float: left;
65+
margin: 0 0 0 4%;
66+
}
67+
68+
.section h2 {
69+
font-size: 13px;
70+
text-transform: uppercase;
71+
margin: 0;
72+
border-bottom: 1px solid silver;
73+
padding-bottom: 12px;
74+
margin-bottom: 8px;
75+
}
76+
77+
.section.first {
78+
margin-left: 0;
79+
}
80+
81+
.section.first h2 {
82+
font-size: 24px;
83+
text-transform: none;
84+
margin-bottom: 25px;
85+
border: none;
86+
}
87+
88+
.section.first li {
89+
border-top: 1px solid silver;
90+
padding: 8px 0;
91+
}
92+
93+
.section.last {
94+
margin-right: 0;
95+
}
96+
97+
ul {
98+
list-style: none;
99+
padding: 0;
100+
margin: 0;
101+
line-height: 20px;
102+
}
103+
104+
li {
105+
padding: 4px 0;
106+
}
107+
108+
a {
109+
color: #267cb2;
110+
text-decoration: none;
111+
}
112+
113+
a:hover {
114+
text-decoration: underline;
115+
}
116+
117+
#footer {
118+
clear: both;
119+
padding-top: 50px;
120+
}
121+
122+
#footer p {
123+
position: absolute;
124+
bottom: 10px;
125+
}
126+
</style>
127+
</head>
128+
<body>
129+
130+
<div id="header">
131+
<h1>Welcome to ASP.NET 5 Preview</h1>
132+
<span>
133+
We've made some big updates in this release, so it’s <b>important</b> that you spend
134+
a few minutes to learn what’s new.
135+
<br /><br />
136+
ASP.NET 5 has been rearchitected to make it <b>lean</b> and <b>composable</b>. It's fully
137+
<b>open source</b> and available on <a href="http://go.microsoft.com/fwlink/?LinkID=517854">GitHub</a>.
138+
<br />
139+
Your new project automatically takes advantage of modern client-side utilities
140+
like <a href="http://go.microsoft.com/fwlink/?LinkId=518004">Bower</a> and <a href="http://go.microsoft.com/fwlink/?LinkId=518005">npm</a>
141+
(to add client-side libraries) and <a href="http://go.microsoft.com/fwlink/?LinkId=518007">Gulp</a> (for client-side build and automation tasks).
142+
143+
<br /><br />
144+
We hope you enjoy the new capabilities in ASP.NET 5 and Visual Studio 2015.
145+
<br />
146+
The ASP.NET Team
147+
</span>
148+
<p>You've created a new ASP.NET 5 project. <a href="http://go.microsoft.com/fwlink/?LinkId=518016">Learn what's new</a></p>
149+
</div>
150+
151+
<div id="main">
152+
<div class="section first">
153+
<h2>This application consists of:</h2>
154+
<ul>
155+
<li>Sample pages using ASP.NET MVC 6</li>
156+
<li><a href="http://go.microsoft.com/fwlink/?LinkId=518007">Gulp</a> and <a href="http://go.microsoft.com/fwlink/?LinkId=518004">Bower</a> for managing client-side resources</li>
157+
<li>Theming using <a href="http://go.microsoft.com/fwlink/?LinkID=398939">Bootstrap</a></li>
158+
</ul>
159+
</div>
160+
161+
<div class="section">
162+
<h2>New concepts</h2>
163+
<ul>
164+
<li><a href="http://go.microsoft.com/fwlink/?LinkId=518008">The 'wwwroot' explained</a></li>
165+
<li><a href="http://go.microsoft.com/fwlink/?LinkId=518012">Configuration in ASP.NET 5</a></li>
166+
<li><a href="http://go.microsoft.com/fwlink/?LinkId=518013">Dependency Injection</a></li>
167+
<li><a href="http://go.microsoft.com/fwlink/?LinkId=518014">Razor TagHelpers</a></li>
168+
<li><a href="http://go.microsoft.com/fwlink/?LinkID=517849">Manage client packages using Gulp</a></li>
169+
<li><a href="http://go.microsoft.com/fwlink/?LinkID=517850">Develop on different platforms</a></li>
170+
</ul>
171+
</div>
172+
173+
<div class="section">
174+
<h2>Customize app</h2>
175+
<ul>
176+
<li><a href="http://go.microsoft.com/fwlink/?LinkID=398600">Add Controllers and Views</a></li>
177+
<li><a href="http://go.microsoft.com/fwlink/?LinkID=398602">Add Data using EntityFramework</a></li>
178+
<li><a href="http://go.microsoft.com/fwlink/?LinkID=398603">Add Authentication using Identity</a></li>
179+
<li><a href="http://go.microsoft.com/fwlink/?LinkID=398606">Add real time support using SignalR</a></li>
180+
<li><a href="http://go.microsoft.com/fwlink/?LinkID=398604">Add Class library</a></li>
181+
<li><a href="http://go.microsoft.com/fwlink/?LinkId=518009">Add Web APIs with MVC 6</a></li>
182+
<li><a href="http://go.microsoft.com/fwlink/?LinkID=517848">Add client packages using Bower</a></li>
183+
</ul>
184+
</div>
185+
186+
<div class="section last">
187+
<h2>Deploy</h2>
188+
<ul>
189+
<li><a href="http://go.microsoft.com/fwlink/?LinkID=517851">Run your app locally</a></li>
190+
<li><a href="http://go.microsoft.com/fwlink/?LinkID=517852">Run your app on ASP.NET Core 5</a></li>
191+
<li><a href="http://go.microsoft.com/fwlink/?LinkID=517853">Run commands in your project.json</a></li>
192+
<li><a href="http://go.microsoft.com/fwlink/?LinkID=398609">Publish to Microsoft Azure Web Sites</a></li>
193+
<li><a href="http://go.microsoft.com/fwlink/?LinkId=518019">Publish to the file system</a></li>
194+
</ul>
195+
</div>
196+
197+
<div id="footer">
198+
<p>We would love to hear your <a href="http://go.microsoft.com/fwlink/?LinkId=518015">feedback</a></p>
199+
</div>
200+
</div>
201+
202+
</body>
203+
</html>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"profiles": {
3+
"IIS Express": {
4+
"commandName" : "IISExpress",
5+
"launchBrowser": true,
6+
"launchUrl": "api/house",
7+
"environmentVariables" : {
8+
"ASPNET_ENV": "Development"
9+
}
10+
}
11+
}
12+
}

0 commit comments

Comments
 (0)