Files
moadiran/Back/Program.cs

140 lines
4.9 KiB
C#
Raw Normal View History

2024-04-18 00:33:46 +03:30
using Back;
2024-03-30 15:10:36 +03:30
using Back.Data.Contracts;
using Back.Data.Infrastructure.Repository;
2024-04-29 07:58:41 +03:30
using Back.Features;
2024-03-30 15:10:36 +03:30
using Back.Services;
2024-04-05 01:05:32 +03:30
using Back.Validations;
2024-03-30 15:10:36 +03:30
using Microsoft.EntityFrameworkCore;
2024-04-18 00:33:46 +03:30
using Microsoft.IdentityModel.Tokens;
2024-06-14 22:37:22 +03:30
using Microsoft.Net.Http.Headers;
2024-05-27 18:01:50 +03:30
using Microsoft.OpenApi.Models;
2024-04-18 00:33:46 +03:30
using System.Text;
2024-03-30 15:10:36 +03:30
using TaxPayer.Infrastructure.Persistence;
2024-03-29 17:44:38 +03:30
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();
2024-05-27 18:01:50 +03:30
builder.Services.AddSwaggerGen(option =>
{
option.SwaggerDoc("v1", new OpenApiInfo { Title = "TaxPayer API", Version = "Preview" });
option.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
{
In = ParameterLocation.Header,
Description = "Please enter a valid token",
Name = "Authorization",
Type = SecuritySchemeType.Http,
BearerFormat = "JWT",
Scheme = "Bearer"
});
option.AddSecurityRequirement(new OpenApiSecurityRequirement
{
{
new OpenApiSecurityScheme
{
Reference = new OpenApiReference
{
Type=ReferenceType.SecurityScheme,
Id="Bearer"
}
},
new string[]{}
}
});
});
2024-03-30 15:10:36 +03:30
builder.Services.AddDbContext<SqlDbContext>(options =>
{
options.UseSqlServer(builder.Configuration.GetConnectionString("Base"));
});
builder.Services.AddScoped(typeof(IAsyncRepository<>), typeof(RepositoryBase<>));
2024-04-29 18:15:46 +03:30
builder.Services.AddScoped(typeof(RepositoryBase<>), typeof(RepositoryBase<>));
2024-03-30 15:10:36 +03:30
builder.Services.AddScoped<Back.Services.ServBase>();
2024-04-05 01:05:32 +03:30
builder.Services.AddScoped<MobileValidation> ();
builder.Services.AddScoped<Service.Main>();
2024-04-14 16:09:36 +03:30
builder.Services.AddScoped<servTicket > ();
2024-05-27 18:01:50 +03:30
builder.Services.AddScoped<ServValidatinMsg>();
2024-04-15 17:16:17 +03:30
builder.Services.AddScoped<GetVerificationValidation> ();
2024-04-16 12:23:29 +03:30
builder.Services.AddScoped<GetVerificationValidation>();
2024-04-17 15:49:34 +03:30
builder.Services.AddScoped<CheckPermission>();
builder.Services.AddScoped<servCompany>();
builder.Services.AddScoped<servNotification>();
builder.Services.AddScoped<servPermission>();
builder.Services.AddScoped<servSendMsg>();
builder.Services.AddScoped<servUser>();
2024-04-30 16:40:05 +03:30
builder.Services.AddScoped<servTaxPayer>();
2024-05-05 18:15:37 +03:30
builder.Services.AddScoped<servCustomer>();
2024-08-28 00:29:35 +03:30
builder.Services.AddScoped<servInvoicePayment>();
2024-04-17 15:49:34 +03:30
builder.Services.AddScoped<CompanyRegistrationValidation>();
2024-05-08 17:25:02 +03:30
builder.Services.AddScoped<AddOrCustomerValidation>();
2024-05-09 23:55:22 +03:30
builder.Services.AddScoped<AddOrCodValidation>();
2024-05-09 19:56:53 +03:30
builder.Services.AddScoped<ServCOD>();
2024-05-13 16:52:57 +03:30
builder.Services.AddScoped<servInvoice>();
builder.Services.AddScoped<AddOrUpdateInvoiceValidation>();
2024-05-25 17:52:40 +03:30
builder.Services.AddScoped<AUInvoiceItemValidation>();
builder.Services.AddScoped<servInvoiceItem>();
2024-06-09 17:23:57 +03:30
builder.Services.AddScoped<ActionTaxPayer>();
2024-06-26 17:10:29 +03:30
builder.Services.AddScoped<Servstuff>();
2024-07-25 17:18:03 +03:30
builder.Services.AddScoped<ServPromotion>();
builder.Services.AddScoped<ServOrders>();
builder.Services.AddScoped<ServPricing>();
2024-07-29 17:50:46 +03:30
builder.Services.AddScoped<ServWalt>();
2024-09-08 17:23:33 +03:30
builder.Services.AddScoped<AUInvoicePayValidation>();
2025-01-09 16:01:37 +03:30
builder.Services.AddScoped<servReport>();
2024-04-17 15:49:34 +03:30
builder.Services.AddScoped(c => new mpNuget.RestClient("09119660045", "C54S2"));
2024-04-16 12:23:29 +03:30
2024-03-30 15:10:36 +03:30
string origins = "OriginTaxPayer";
builder.Services.AddCors(options =>
{
options.AddPolicy(origins,
policy =>
{
2024-10-15 16:17:17 +03:30
policy.WithOrigins("https://localhost:7224", "http://localhost:5107"
, "http://195.88.208.142", "http://moadiran.ir"
2024-11-15 18:38:55 +03:30
, "https://195.88.208.142", "https://moadiran.ir"
2025-01-09 16:01:37 +03:30
, "https://195.88.208.142:440", "https://moadiran.ir:440", "https://localhost:44346")
2024-03-30 15:10:36 +03:30
.AllowAnyHeader()
2024-06-14 22:37:22 +03:30
.WithHeaders(HeaderNames.ContentType)
2024-03-30 15:10:36 +03:30
.AllowAnyMethod();
});
});
2024-03-29 17:44:38 +03:30
2024-04-18 00:33:46 +03:30
#region JWT
builder.Services.AddAuthentication("Bearer")
.AddJwtBearer(options =>
{
options.TokenValidationParameters = new()
{
ValidateIssuer = true,
ValidateAudience = true,
ValidateIssuerSigningKey = true,
ValidIssuer = Fixedvalues.Issuer,
ValidAudience = Fixedvalues.Audience,
IssuerSigningKey = new SymmetricSecurityKey(
Encoding.ASCII.GetBytes(Fixedvalues.SecretForKey))
};
}
);
#endregion
2024-03-29 17:44:38 +03:30
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
2024-03-30 15:10:36 +03:30
app.UseCors(origins);
2024-04-18 00:33:46 +03:30
app.UseAuthentication();
2024-03-29 17:44:38 +03:30
app.UseAuthorization();
2024-04-29 07:58:41 +03:30
app.UseCheckOnlineUser();
2024-03-29 17:44:38 +03:30
app.MapControllers();
app.Run();