Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 24c2c5b

Browse files
author
ahotko
committed
Initial Import
1 parent 9d695ed commit 24c2c5b

File tree

10 files changed

+261
-0
lines changed

10 files changed

+261
-0
lines changed

‎MicroService/MicroService.sln

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.29519.87
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MicroServiceExample", "MicroServiceExample\MicroServiceExample.csproj", "{BFCE5A4C-E35C-43A2-97A3-96929BDDC725}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{BFCE5A4C-E35C-43A2-97A3-96929BDDC725}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{BFCE5A4C-E35C-43A2-97A3-96929BDDC725}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{BFCE5A4C-E35C-43A2-97A3-96929BDDC725}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{BFCE5A4C-E35C-43A2-97A3-96929BDDC725}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {7C211F48-35FB-4C47-BAF4-6DCB4E2B2BD1}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using MicroServiceExample.Models;
2+
using Microsoft.AspNetCore.Mvc;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
6+
namespace MicroServiceExample.Controllers
7+
{
8+
[ApiController]
9+
[Route("[controller]")]
10+
public class PersonController : ControllerBase
11+
{
12+
// GET: Person
13+
[HttpGet]
14+
public IEnumerable<Person> Get()
15+
{
16+
return PersonStorage.Instance.Persons.ToArray();
17+
}
18+
19+
// GET: Person/5
20+
[HttpGet("{id}", Name = "Get")]
21+
public Person Get(int id)
22+
{
23+
return PersonStorage.Instance.Find(id);
24+
}
25+
26+
// POST: Person
27+
[HttpPost]
28+
public void Post([FromBody] Person value)
29+
{
30+
PersonStorage.Instance.Add(value);
31+
}
32+
33+
// PUT: Person/5
34+
[HttpPut("{id}")]
35+
public void Put(int id, [FromBody] Person value)
36+
{
37+
PersonStorage.Instance.Update(id, value);
38+
}
39+
40+
// DELETE: ApiWithActions/5
41+
[HttpDelete("{id}")]
42+
public void Delete(int id)
43+
{
44+
PersonStorage.Instance.Delete(id);
45+
}
46+
}
47+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp3.0</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.0.0" />
9+
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.0.0">
10+
<PrivateAssets>all</PrivateAssets>
11+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
12+
</PackageReference>
13+
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="3.0.0" />
14+
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.0.0" />
15+
</ItemGroup>
16+
17+
</Project>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
3+
namespace MicroServiceExample.Models
4+
{
5+
public class Person
6+
{
7+
public int Id { get; set; }
8+
public string Name { get; set; }
9+
public string Lastname { get; set; }
10+
public DateTime DateOfBirth { get; set; }
11+
}
12+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using MicroServiceExample.Models;
2+
using System;
3+
using System.Collections.ObjectModel;
4+
using System.Linq;
5+
6+
namespace MicroServiceExample
7+
{
8+
public class PersonStorage
9+
{
10+
public static PersonStorage Instance { get; } = new PersonStorage();
11+
12+
public Collection<Person> Persons { get; } = new Collection<Person>();
13+
14+
public PersonStorage()
15+
{
16+
Persons.Add(new Person() { Id = 1, Name = "John", Lastname = "O'Connor", DateOfBirth = new DateTime(1980, 12, 2) });
17+
Persons.Add(new Person() { Id = 2, Name = "Jane", Lastname = "Doe", DateOfBirth = new DateTime(1985, 3, 22) });
18+
}
19+
20+
public void Add(Person person)
21+
{
22+
Persons.Add(person);
23+
}
24+
25+
public Person Find(int id)
26+
{
27+
return Persons.Where(p => p.Id == id).FirstOrDefault();
28+
}
29+
30+
public void Update(int id, Person person)
31+
{
32+
var personInfo = Find(id);
33+
if (personInfo != null)
34+
{
35+
personInfo.Id = person.Id;
36+
personInfo.Name = person.Name;
37+
personInfo.Lastname = person.Lastname;
38+
personInfo.DateOfBirth = person.DateOfBirth;
39+
}
40+
}
41+
42+
public void Delete(int id)
43+
{
44+
Persons.Remove(Find(id));
45+
}
46+
}
47+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Microsoft.AspNetCore.Hosting;
2+
using Microsoft.Extensions.Hosting;
3+
4+
namespace MicroServiceExample
5+
{
6+
public class Program
7+
{
8+
public static void Main(string[] args)
9+
{
10+
CreateHostBuilder(args).Build().Run();
11+
}
12+
13+
public static IHostBuilder CreateHostBuilder(string[] args) =>
14+
Host.CreateDefaultBuilder(args)
15+
.ConfigureWebHostDefaults(webBuilder =>
16+
{
17+
webBuilder.UseStartup<Startup>();
18+
});
19+
}
20+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"$schema": "http://json.schemastore.org/launchsettings.json",
3+
"iisSettings": {
4+
"windowsAuthentication": false,
5+
"anonymousAuthentication": true,
6+
"iisExpress": {
7+
"applicationUrl": "http://localhost:52973",
8+
"sslPort": 0
9+
}
10+
},
11+
"profiles": {
12+
"IIS Express": {
13+
"commandName": "IISExpress",
14+
"launchBrowser": true,
15+
"launchUrl": "person",
16+
"environmentVariables": {
17+
"ASPNETCORE_ENVIRONMENT": "Development"
18+
}
19+
},
20+
"MicroServiceExample": {
21+
"commandName": "Project",
22+
"launchBrowser": true,
23+
"launchUrl": "person",
24+
"applicationUrl": "https://localhost:5001;http://localhost:5000",
25+
"environmentVariables": {
26+
"ASPNETCORE_ENVIRONMENT": "Development"
27+
}
28+
}
29+
}
30+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using Microsoft.AspNetCore.Builder;
2+
using Microsoft.AspNetCore.Hosting;
3+
using Microsoft.Extensions.Configuration;
4+
using Microsoft.Extensions.DependencyInjection;
5+
using Microsoft.Extensions.Hosting;
6+
7+
namespace MicroServiceExample
8+
{
9+
public class Startup
10+
{
11+
public Startup(IConfiguration configuration)
12+
{
13+
Configuration = configuration;
14+
}
15+
16+
public IConfiguration Configuration { get; }
17+
18+
// This method gets called by the runtime. Use this method to add services to the container.
19+
public void ConfigureServices(IServiceCollection services)
20+
{
21+
services.AddControllers();
22+
}
23+
24+
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
25+
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
26+
{
27+
if (env.IsDevelopment())
28+
{
29+
app.UseDeveloperExceptionPage();
30+
}
31+
32+
app.UseHttpsRedirection();
33+
34+
app.UseRouting();
35+
36+
app.UseAuthorization();
37+
38+
app.UseEndpoints(endpoints =>
39+
{
40+
endpoints.MapControllers();
41+
});
42+
}
43+
}
44+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Debug",
5+
"System": "Information",
6+
"Microsoft": "Information"
7+
}
8+
}
9+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft": "Warning",
6+
"Microsoft.Hosting.Lifetime": "Information"
7+
}
8+
},
9+
"AllowedHosts": "*"
10+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /