-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
18 lines (17 loc) · 829 Bytes
/
Copy pathProgram.cs
File metadata and controls
18 lines (17 loc) · 829 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
using Microsoft.Data.SqlClient;
using Dapper;
using System.Data;
var builder = WebApplication.CreateBuilder(args);
var constring = builder.Configuration.GetConnectionString("DB");
var con = new SqlConnection(constring);
builder.Services.AddCors(o => o.AddPolicy("AllowAll",
P => P.AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin())).AddEndpointsApiExplorer().AddSwaggerGen();
var app = builder.Build();
app.UseHttpsRedirection();
app.UseCors("AllowAll");
if (app.Environment.IsDevelopment())
app.UseSwagger().UseSwaggerUI();
app.MapGet("/", () => "Welcome, Hello World! what ever.");
app.MapGet("/api/employees", () => con.Query("SELECT * FROM Employees"));
app.MapGet("/api/employees/{id}", (int id) => con.Query("SelectEmployeesByID", new { id }, commandType: CommandType.StoredProcedure));
app.Run();