Program.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. using WebApplicationAvaloniaForMe.Models;
  2. using Microsoft.EntityFrameworkCore;
  3. using Newtonsoft.Json;
  4. var builder = WebApplication.CreateBuilder(args);
  5. // Add services to the container.
  6. builder.Services.AddControllers();
  7. // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
  8. builder.Services.AddEndpointsApiExplorer();
  9. builder.Services.AddSwaggerGen();
  10. builder.Services.AddDbContext<KuzminivpostgrContext>();
  11. var app = builder.Build();
  12. app.MapGet("/", () => "Hello, world");
  13. app.MapGet("/number", () => "chto to tipo takogo: 100500");
  14. app.MapGet("/characterlist", (KuzminivpostgrContext db) => JsonConvert.SerializeObject(db.Mycharacters.Include(x=>x.Properties).ToList(), Formatting.Indented, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }));
  15. app.MapGet("/character/{id:int}",
  16. (KuzminivpostgrContext db, int id) =>
  17. JsonConvert.SerializeObject(db.Mycharacters.Include(x => x.GenderNavigation).Include(x => x.Properties).FirstOrDefault(x => x.Id == id),
  18. Formatting.Indented, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }));
  19. // Configure the HTTP request pipeline.
  20. if (app.Environment.IsDevelopment())
  21. {
  22. app.UseSwagger();
  23. app.UseSwaggerUI();
  24. }
  25. app.UseHttpsRedirection();
  26. app.UseAuthorization();
  27. app.MapControllers();
  28. app.Run();