1234567891011121314151617181920212223242526272829303132333435363738 |
- using WebApplicationAvaloniaForMe.Models;
- using Microsoft.EntityFrameworkCore;
- using Newtonsoft.Json;
- var builder = WebApplication.CreateBuilder(args);
- // Add services to the container.
- builder.Services.AddControllers();
- // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
- builder.Services.AddEndpointsApiExplorer();
- builder.Services.AddSwaggerGen();
- builder.Services.AddDbContext<KuzminivpostgrContext>();
- var app = builder.Build();
- app.MapGet("/", () => "Hello, world");
- app.MapGet("/number", () => "chto to tipo takogo: 100500");
- app.MapGet("/characterlist", (KuzminivpostgrContext db) => JsonConvert.SerializeObject(db.Mycharacters.Include(x=>x.Properties).ToList(), Formatting.Indented, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }));
- app.MapGet("/character/{id:int}",
- (KuzminivpostgrContext db, int id) =>
- JsonConvert.SerializeObject(db.Mycharacters.Include(x => x.GenderNavigation).Include(x => x.Properties).FirstOrDefault(x => x.Id == id),
- Formatting.Indented, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }));
- // Configure the HTTP request pipeline.
- if (app.Environment.IsDevelopment())
- {
- app.UseSwagger();
- app.UseSwaggerUI();
- }
- app.UseHttpsRedirection();
- app.UseAuthorization();
- app.MapControllers();
- app.Run();
|