using Diligent.WebAPI.Business.Services; using Diligent.WebAPI.Data.Entities; using Diligent.WebAPI.Data.HelperModels; using Diligent.WebAPI.Host.Hubs; using Microsoft.AspNetCore.Identity; using Serilog; using Serilog.Formatting.Json; var builder = WebApplication.CreateBuilder(args); builder.ConfigureData(builder.Configuration); var collection = builder.Services; Diligent.WebAPI.Host.Extensions.ApiConfiguration.ConfigureServices(collection); builder.ConfigureValidationMiddleware(); var app = builder.Build(); using (var serviceScope = app.Services.CreateScope()) { var roleManager = serviceScope.ServiceProvider.GetRequiredService>(); var requestService = serviceScope.ServiceProvider.GetRequiredService(); var roomService = serviceScope.ServiceProvider.GetRequiredService(); var customerManager = serviceScope.ServiceProvider.GetRequiredService>(); if (!await roleManager.RoleExistsAsync("Support")) { await roleManager.CreateAsync(new Roles() { Name = "Support" }); } if (!await roleManager.RoleExistsAsync("Customer")) { await roleManager.CreateAsync(new Roles() { Name = "Customer" }); } if ((await roomService.GetRoomsAsync()).Count() == 0) { await roomService.CreateRoomAsync(new Room { Id = "61da70bbde07582b720e056d", Name = "Room1", Customers = new List(), Messages = new List(), CreatedBy = "8a781b04-8d3a-4d65-98ab-77b832a6dd06" }); await roomService.CreateRoomAsync(new Room { Id = "61da61cbde07582b720e056d", Name = "Room2", Customers = new List(), Messages = new List(), CreatedBy = "8a781b04-8d3a-4d65-98ab-77b832a6dd06" }); } if ((await requestService.GetRequestsAsync()).Count() == 0) { await requestService.CreateRequestAsync(new Request { Id = "62fb60badc07582b720e056d", RoomId = "61da70bbde07582b720e056d", SenderId = "8a781b04-3d3a-4d65-98ab-77b532a6ad06", SenderUsername = "User2", RoomName = "Room1" }); await requestService.CreateRequestAsync(new Request { Id = "62fb31bbde12482b720e156f", RoomId = "61da70bbde07582b720e056d", SenderId = "8e781b04-8d4a-4d65-98ab-37b832a6da06", SenderUsername = "User3", RoomName = "Room2" }); } if (await customerManager.FindByEmailAsync("user1@gmail.com") == null) { Customer customer = new() { Id = new Guid("8a781b04-8d3a-4d65-98ab-77b832a6dd06"), FirstName = "User1", LastName = "User1", Email = "user1@gmail.com", UserName = "user1" }; await customerManager.CreateAsync(customer, "Nekasifra123!"); await customerManager.AddToRoleAsync(customer, "Support"); } if (await customerManager.FindByEmailAsync("user2@gmail.com") == null) { Customer customer = new() { Id = new Guid("8a781b04-3d3a-4d65-98ab-77b532a6ad06"), FirstName = "User2", LastName = "User2", Email = "user2@gmail.com", UserName = "user2" }; await customerManager.CreateAsync(customer, "Nekasifra123!"); await customerManager.AddToRoleAsync(customer, "Customer"); } if (await customerManager.FindByEmailAsync("user3@gmail.com") == null) { Customer customer = new() { Id = new Guid("8e781b04-8d4a-4d65-98ab-37b832a6da06"), FirstName = "User3", LastName = "User3", Email = "user3@gmail.com", UserName = "user3" }; await customerManager.CreateAsync(customer, "Nekasifra123!"); await customerManager.AddToRoleAsync(customer, "Customer"); } } app.UseCors("ClientPermission"); app.MapControllers(); app.UseAuthentication(); app.UseAuthorization(); app.SetupData(); app.MapHub("/chatHub"); app.MapHub("/statusHub"); app.Run();