Compare commits
8 Commits
2c3463b74f
...
5a4b46cb4f
Author | SHA1 | Date | |
---|---|---|---|
5a4b46cb4f | |||
58526d5feb | |||
35da59304d | |||
c701187223 | |||
bed58af120 | |||
![]() |
7a1a4d6bdb | ||
cdd67c1137 | |||
65ef5f9a5a |
@ -175,6 +175,13 @@ namespace MarcoBMS.Services.Controllers
|
||||
{
|
||||
return BadRequest(new { Message = "Feature Permission is required." });
|
||||
}
|
||||
|
||||
bool roleExists = _context.ApplicationRoles
|
||||
.Any(r => r.TenantId == TenantId && r.Role.ToLower() == createRoleDto.Role.ToLower());// assuming role name is unique per tenant
|
||||
if (roleExists)
|
||||
{
|
||||
return BadRequest(new {message = "Role already exists." });
|
||||
}
|
||||
ApplicationRole role = createRoleDto.ToApplicationRoleFromCreateDto(TenantId);
|
||||
_context.ApplicationRoles.Add(role);
|
||||
|
||||
@ -202,6 +209,7 @@ namespace MarcoBMS.Services.Controllers
|
||||
if (id != updateRoleDto.Id.ToString())
|
||||
return BadRequest("Role ID mismatch");
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
int TenantId = GetTenantId();
|
||||
|
38
Marco.Pms.Services/Dockerfile
Normal file
38
Marco.Pms.Services/Dockerfile
Normal file
@ -0,0 +1,38 @@
|
||||
#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.
|
||||
|
||||
|
||||
#This stage is used when running from VS in fast mode (Default for Debug configuration)
|
||||
|
||||
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
|
||||
USER $APP_UID
|
||||
WORKDIR /app
|
||||
EXPOSE 8080
|
||||
EXPOSE 8081
|
||||
|
||||
|
||||
#This stage is used to build the service project
|
||||
|
||||
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
|
||||
ARG BUILD_CONFIGURATION=Release
|
||||
WORKDIR /src
|
||||
COPY ["Marco.Pms.Services/Marco.Pms.Services.csproj", "Marco.Pms.Services/"]
|
||||
COPY ["Marco.Pms.DataAccess/Marco.Pms.DataAccess.csproj", "Marco.Pms.DataAccess/"]
|
||||
COPY ["Marco.Pms.Model/Marco.Pms.Model.csproj", "Marco.Pms.Model/"]
|
||||
COPY ["Marco.Pms.Utility/Marco.Pms.Utility.csproj", "Marco.Pms.Utility/"]
|
||||
RUN dotnet restore "./Marco.Pms.Services/Marco.Pms.Services.csproj"
|
||||
COPY . .
|
||||
WORKDIR "/src/Marco.Pms.Services"
|
||||
RUN dotnet build "./Marco.Pms.Services.csproj" -c $BUILD_CONFIGURATION -o /app/build
|
||||
|
||||
#This stage is used to publish the service project to be copied to the final stage
|
||||
|
||||
FROM build AS publish
|
||||
ARG BUILD_CONFIGURATION=Release
|
||||
RUN dotnet publish "./Marco.Pms.Services.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
|
||||
|
||||
#This stage is used in production or when running from VS in regular mode (Default when not using the Debug configuration)
|
||||
|
||||
FROM base AS final
|
||||
WORKDIR /app
|
||||
COPY --from=publish /app/publish .
|
||||
ENTRYPOINT ["dotnet", "Marco.Pms.Services.dll"]
|
@ -25,26 +25,34 @@ builder.Host.UseSerilog((context, config) =>
|
||||
;
|
||||
|
||||
// Add services
|
||||
builder.Services.AddCors(options =>
|
||||
{
|
||||
options.AddPolicy("DevCorsPolicy", policy =>
|
||||
{
|
||||
policy.AllowAnyOrigin()
|
||||
.AllowAnyMethod()
|
||||
.AllowAnyHeader();
|
||||
});
|
||||
});
|
||||
|
||||
//builder.Services.AddCors(options =>
|
||||
//{
|
||||
// options.AddPolicy("ProdCorsPolicy", policy =>
|
||||
// options.AddPolicy("DevCorsPolicy", policy =>
|
||||
// {
|
||||
// policy.WithOrigins("https://yourdomain.com", "https://anothertrustedsource.com") // List of allowed origins
|
||||
// policy.AllowAnyOrigin()
|
||||
// .AllowAnyMethod()
|
||||
// .AllowAnyHeader();
|
||||
// });
|
||||
//});
|
||||
|
||||
var corsSettings = builder.Configuration.GetSection("Cors");
|
||||
var allowedOrigins = corsSettings.GetValue<string>("AllowedOrigins")?.Split(',');
|
||||
var allowedMethods = corsSettings.GetValue<string>("AllowedMethods")?.Split(',');
|
||||
var allowedHeaders = corsSettings.GetValue<string>("AllowedHeaders")?.Split(',');
|
||||
|
||||
builder.Services.AddCors(options =>
|
||||
{
|
||||
options.AddPolicy("Policy", policy =>
|
||||
{
|
||||
if (allowedOrigins != null)
|
||||
{
|
||||
policy.WithOrigins(allowedOrigins)
|
||||
.WithMethods(allowedMethods)
|
||||
.WithHeaders(allowedHeaders);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Add services to the container.
|
||||
builder.Services.AddControllers();
|
||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||
@ -146,12 +154,21 @@ if (app.Environment.IsDevelopment())
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI();
|
||||
// Use CORS in the pipeline
|
||||
app.UseCors("DevCorsPolicy");
|
||||
//app.UseCors("DevCorsPolicy");
|
||||
}
|
||||
|
||||
//if (app.Environment.IsProduction())
|
||||
//{
|
||||
// app.UseCors("ProdCorsPolicy");
|
||||
//}
|
||||
|
||||
app.UseCors("Policy");
|
||||
|
||||
app.UseStaticFiles(); // Enables serving static files
|
||||
|
||||
app.UseSerilogRequestLogging(); // Log HTTP requests
|
||||
//app.UseSerilogRequestLogging(); // This is Default Serilog Logging Middleware we are not using this because we're using custom logging middleware
|
||||
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
app.UseMiddleware<ExceptionHandlingMiddleware>();
|
||||
app.UseMiddleware<TenantMiddleware>();
|
||||
|
@ -1,8 +1,13 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"Cors": {
|
||||
"AllowedOrigins": "*",
|
||||
"AllowedMethods": "*",
|
||||
"AllowedHeaders": "*"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
11
Marco.Pms.Services/appsettings.Production.json
Normal file
11
Marco.Pms.Services/appsettings.Production.json
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"AllowedHosts": "*",
|
||||
"Cors": {
|
||||
"AllowedOrigins": "http://localhost:4173",
|
||||
"AllowedMethods": "*",
|
||||
"AllowedHeaders": "*"
|
||||
},
|
||||
"ConnectionStrings": {
|
||||
"DefaultConnectionString": "Server=147.93.98.152;User ID=devuser;Password=AppUser@123$;Database=MarcoBMS1"
|
||||
}
|
||||
}
|
@ -11,7 +11,7 @@
|
||||
"Microsoft": "Warning",
|
||||
"Microsoft.EntityFrameworkCore.Database.Command": "Warning",
|
||||
"Microsoft.AspNetCore.Mvc.Infrastructure": "Warning",
|
||||
"Serilog.AspNetCore.RequestLoggingMiddleware": "Warning"
|
||||
//"Serilog.AspNetCore.RequestLoggingMiddleware": "Warning"
|
||||
}
|
||||
},
|
||||
"WriteTo": [
|
||||
@ -62,11 +62,11 @@
|
||||
]
|
||||
},
|
||||
|
||||
"ConnectionStrings": {
|
||||
// "DefaultConnectionString": "Server=103.50.160.45;User ID=marcowvh_admin;Password=Marcoemp@123;Database=marcowvh_empattendanceci",
|
||||
"DefaultConnectionString": "Server=localhost;port=3333;User ID=root;Password=root;Database=MarcoBMS1",
|
||||
// "DefaultConnectionString": "Server=147.93.98.152;User ID=devuser;Password=AppUser@123$;Database=MarcoBMS1"
|
||||
},
|
||||
"ConnectionStrings": {
|
||||
// "DefaultConnectionString": "Server=103.50.160.45;User ID=marcowvh_admin;Password=Marcoemp@123;Database=marcowvh_empattendanceci",
|
||||
//"DefaultConnectionString": "Server=localhost;port=3333;User ID=root;Password=root;Database=MarcoBMS1",
|
||||
"DefaultConnectionString": "Server=147.93.98.152;User ID=devuser;Password=AppUser@123$;Database=MarcoBMS1"
|
||||
},
|
||||
"AppSettings": {
|
||||
"WebFrontendUrl": "http://localhost:5173",
|
||||
"ImagesBaseUrl": "http://localhost:5173"
|
||||
|
Loading…
x
Reference in New Issue
Block a user