Skip to content

Commit 8462b36

Browse files
committed
Initial Commit
1 parent 0caede6 commit 8462b36

File tree

119 files changed

+3908
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

119 files changed

+3908
-0
lines changed

NettaSec.ASP.NET.Web.API.sln

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.7.34202.233
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NettaSec.ASP.NET.Web.API", "NettaSec.ASP.NET.Web.API\NettaSec.ASP.NET.Web.API.csproj", "{22555210-B0BC-43DE-B62A-9C6A44601409}"
7+
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NettaSec.ASP.NET.Web.Repository", "NettaSec.ASP.NET.Web.Repository\NettaSec.ASP.NET.Web.Repository.csproj", "{455CB2CB-6DB0-45E4-BBBB-78C1AE1A0496}"
9+
EndProject
10+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NettaSec.ASP.NET.Web.Core", "NettaSec.ASP.NET.Web.Core\NettaSec.ASP.NET.Web.Core.csproj", "{EC32A083-56B7-4BD0-9978-B40D1B571231}"
11+
EndProject
12+
Global
13+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
14+
Debug|Any CPU = Debug|Any CPU
15+
Release|Any CPU = Release|Any CPU
16+
EndGlobalSection
17+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
18+
{22555210-B0BC-43DE-B62A-9C6A44601409}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
19+
{22555210-B0BC-43DE-B62A-9C6A44601409}.Debug|Any CPU.Build.0 = Debug|Any CPU
20+
{22555210-B0BC-43DE-B62A-9C6A44601409}.Release|Any CPU.ActiveCfg = Release|Any CPU
21+
{22555210-B0BC-43DE-B62A-9C6A44601409}.Release|Any CPU.Build.0 = Release|Any CPU
22+
{455CB2CB-6DB0-45E4-BBBB-78C1AE1A0496}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
23+
{455CB2CB-6DB0-45E4-BBBB-78C1AE1A0496}.Debug|Any CPU.Build.0 = Debug|Any CPU
24+
{455CB2CB-6DB0-45E4-BBBB-78C1AE1A0496}.Release|Any CPU.ActiveCfg = Release|Any CPU
25+
{455CB2CB-6DB0-45E4-BBBB-78C1AE1A0496}.Release|Any CPU.Build.0 = Release|Any CPU
26+
{EC32A083-56B7-4BD0-9978-B40D1B571231}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27+
{EC32A083-56B7-4BD0-9978-B40D1B571231}.Debug|Any CPU.Build.0 = Debug|Any CPU
28+
{EC32A083-56B7-4BD0-9978-B40D1B571231}.Release|Any CPU.ActiveCfg = Release|Any CPU
29+
{EC32A083-56B7-4BD0-9978-B40D1B571231}.Release|Any CPU.Build.0 = Release|Any CPU
30+
EndGlobalSection
31+
GlobalSection(SolutionProperties) = preSolution
32+
HideSolutionNode = FALSE
33+
EndGlobalSection
34+
GlobalSection(ExtensibilityGlobals) = postSolution
35+
SolutionGuid = {82E583A3-9168-424D-90A7-C60AFA301D8C}
36+
EndGlobalSection
37+
EndGlobal
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using NettaSec.ASP.NET.Web.Core.Models;
3+
4+
namespace NettaSec.ASP.NET.Web.API.Controllers
5+
{
6+
public class CustomController : ControllerBase
7+
{
8+
[NonAction]
9+
public IActionResult GetReturnStatus(object data, string? error)
10+
{
11+
ApiStatus<Object> status = new ApiStatus<Object>();
12+
if(data != null)
13+
{
14+
status.json = data;
15+
status.rowCount = ((IEnumerable<object>)data).ToList().Count;
16+
if(status.rowCount > 0)
17+
{
18+
status.statusCode = 200;
19+
}
20+
else
21+
{
22+
status.statusCode = 204;
23+
}
24+
25+
return Ok(status);
26+
}
27+
else
28+
{
29+
status.statusCode = 400;
30+
status.errors = error;
31+
return BadRequest(status);
32+
}
33+
}
34+
35+
[NonAction]
36+
public IActionResult PostReturnStatus(object data, string? error)
37+
{
38+
ApiStatus<Object> status = new ApiStatus<object>();
39+
if(error == null)
40+
{
41+
status.statusCode=200;
42+
status.json= data;
43+
return Ok(status);
44+
}
45+
else
46+
{
47+
status.statusCode = 400;
48+
status.errors = error;
49+
return BadRequest(status);
50+
}
51+
}
52+
[NonAction]
53+
public IActionResult PutReturnStatus(object data, string? error)
54+
{
55+
ApiStatus<Object> status = new ApiStatus<object>();
56+
if(data!= null)
57+
{
58+
status.statusCode = 200;
59+
status.json = data;
60+
return Ok(status);
61+
}
62+
else if(error != null)
63+
{
64+
status.statusCode = 400;
65+
status.errors = error;
66+
return BadRequest(status);
67+
}
68+
else
69+
{
70+
status.statusCode = 400;
71+
status.errors = "Hiçbir satır etkilenmedi";
72+
return BadRequest(status);
73+
}
74+
}
75+
76+
[NonAction]
77+
public IActionResult DeleteReturnStatus(int id, string? error)
78+
{
79+
ApiStatus<Object> status = new ApiStatus<object>();
80+
if (id > 0)
81+
{
82+
status.statusCode = 200;
83+
status.id = id;
84+
return Ok(status);
85+
}
86+
if(error != null)
87+
{
88+
status.statusCode = 400;
89+
status.id = id;
90+
status.errors = error;
91+
return BadRequest(status);
92+
}
93+
else
94+
{
95+
status.statusCode = 400;
96+
status.id = id;
97+
status.errors = "Hiçbir satır etkilenmedi";
98+
return BadRequest(status);
99+
}
100+
}
101+
}
102+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using NettaSec.ASP.NET.Web.Core.Models;
3+
using System.Data;
4+
using NettaSec.ASP.NET.Web.Repository.IRepositories;
5+
using Dapper;
6+
using System.Collections.Immutable;
7+
8+
namespace NettaSec.ASP.NET.Web.API.Controllers
9+
{
10+
[Route("api/[controller]/[action]")]
11+
[ApiController]
12+
public class UsersController : CustomController
13+
{
14+
private readonly IUsersRepository _usersRepository;
15+
16+
public UsersController(IUsersRepository usersRepository)
17+
{
18+
_usersRepository = usersRepository;
19+
}
20+
21+
[HttpGet]
22+
public async Task<IActionResult> Get(int id)
23+
{
24+
try
25+
{
26+
return GetReturnStatus(await _usersRepository.UsersGet(id), null);
27+
}
28+
catch (Exception ex)
29+
{
30+
return GetReturnStatus(null, ex.Message);
31+
}
32+
}
33+
34+
[HttpPost]
35+
public async Task<IActionResult> Post(Users users)
36+
{
37+
try
38+
{
39+
return PostReturnStatus(await _usersRepository.UsersPost(users), null);
40+
}
41+
catch (Exception ex)
42+
{
43+
return BadRequest(ex.Message);
44+
}
45+
}
46+
47+
[HttpPut]
48+
49+
public async Task<IActionResult> Put(Users users)
50+
{
51+
try
52+
{
53+
await _usersRepository.UsersPut(users);
54+
return PutReturnStatus(users.id, null);
55+
}
56+
catch (Exception ex)
57+
{
58+
return BadRequest(ex.Message);
59+
}
60+
}
61+
62+
[HttpDelete("{id}")]
63+
public async Task<IActionResult> Delete(int id)
64+
{
65+
try
66+
{
67+
await _usersRepository.UsersDelete(id);
68+
return DeleteReturnStatus(id,null);
69+
}
70+
catch (Exception ex)
71+
{
72+
return BadRequest(ex.Message);
73+
}
74+
}
75+
}
76+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net7.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Dapper" Version="2.1.15" />
11+
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.12" />
12+
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.13" />
13+
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.13">
14+
<PrivateAssets>all</PrivateAssets>
15+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
16+
</PackageReference>
17+
<PackageReference Include="Npgsql" Version="7.0.6" />
18+
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.11" />
19+
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
20+
</ItemGroup>
21+
22+
<ItemGroup>
23+
<ProjectReference Include="..\NettaSec.ASP.NET.Web.Core\NettaSec.ASP.NET.Web.Core.csproj" />
24+
<ProjectReference Include="..\NettaSec.ASP.NET.Web.Repository\NettaSec.ASP.NET.Web.Repository.csproj" />
25+
</ItemGroup>
26+
27+
</Project>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<ActiveDebugProfile>https</ActiveDebugProfile>
5+
<Controller_SelectedScaffolderID>MvcControllerWithActionsScaffolder</Controller_SelectedScaffolderID>
6+
<Controller_SelectedScaffolderCategoryPath>root/Common/MVC/Controller</Controller_SelectedScaffolderCategoryPath>
7+
</PropertyGroup>
8+
</Project>

NettaSec.ASP.NET.Web.API/Program.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using Microsoft.EntityFrameworkCore;
2+
using NettaSec.ASP.NET.Web.API.Settings;
3+
4+
var builder = WebApplication.CreateBuilder(args);
5+
6+
// Add services to the container.
7+
builder.Services.Configurations();
8+
builder.Services.AddControllers();
9+
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
10+
builder.Services.AddEndpointsApiExplorer();
11+
builder.Services.AddSwaggerGen();
12+
13+
var app = builder.Build();
14+
15+
// Configure the HTTP request pipeline.
16+
if (app.Environment.IsDevelopment())
17+
{
18+
app.UseSwagger();
19+
app.UseSwaggerUI();
20+
}
21+
22+
app.UseHttpsRedirection();
23+
24+
app.UseAuthorization();
25+
26+
app.MapControllers();
27+
28+
app.Run();
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"$schema": "https://json.schemastore.org/launchsettings.json",
3+
"iisSettings": {
4+
"windowsAuthentication": false,
5+
"anonymousAuthentication": true,
6+
"iisExpress": {
7+
"applicationUrl": "http://localhost:22773",
8+
"sslPort": 44327
9+
}
10+
},
11+
"profiles": {
12+
"http": {
13+
"commandName": "Project",
14+
"dotnetRunMessages": true,
15+
"launchBrowser": true,
16+
"launchUrl": "swagger",
17+
"applicationUrl": "http://localhost:5271",
18+
"environmentVariables": {
19+
"ASPNETCORE_ENVIRONMENT": "Development"
20+
}
21+
},
22+
"https": {
23+
"commandName": "Project",
24+
"dotnetRunMessages": true,
25+
"launchBrowser": true,
26+
"launchUrl": "swagger",
27+
"applicationUrl": "https://localhost:7098;http://localhost:5271",
28+
"environmentVariables": {
29+
"ASPNETCORE_ENVIRONMENT": "Development"
30+
}
31+
},
32+
"IIS Express": {
33+
"commandName": "IISExpress",
34+
"launchBrowser": true,
35+
"launchUrl": "swagger",
36+
"environmentVariables": {
37+
"ASPNETCORE_ENVIRONMENT": "Development"
38+
}
39+
}
40+
}
41+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using NettaSec.ASP.NET.Web.Repository.IRepositories;
2+
using NettaSec.ASP.NET.Web.Repository.Repositories;
3+
using Npgsql;
4+
using System.Data;
5+
6+
namespace NettaSec.ASP.NET.Web.API.Settings
7+
{
8+
public static class ServiceRegistration
9+
{
10+
11+
public static void Configurations(this IServiceCollection services)
12+
{
13+
var configuration = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build();
14+
var connectionString = configuration.GetConnectionString("DefaultConnection");
15+
16+
services.AddScoped<IDbConnection, NpgsqlConnection>(serviceProvider =>
17+
{
18+
var conn = new NpgsqlConnection(connectionString);
19+
conn.Open();
20+
return conn;
21+
});
22+
23+
services.AddScoped<IUsersRepository, UsersRepository>();
24+
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
25+
26+
}
27+
28+
29+
}
30+
31+
32+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning"
6+
}
7+
}
8+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"ConnectionStrings": {
3+
"DefaultConnection": "Server=localhost;Port=5432;Database=db;User Id=id;Password=pass;"
4+
},
5+
6+
"Logging": {
7+
"LogLevel": {
8+
"Default": "Information",
9+
"Microsoft.AspNetCore": "Warning"
10+
}
11+
},
12+
"AllowedHosts": "*"
13+
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)