Przeglądaj źródła

Merge Master to chat

zinab_elgendy 6 miesięcy temu
rodzic
commit
665f80236e

+ 41 - 0
MTWorkHR.API/.env

@@ -0,0 +1,41 @@
+# Database Settings
+LOCAL_CONNECTION_STRING="Server=localhost;Database=MTWorkHRDB;User=sa;Password=Mahmoud001;MultipleActiveResultSets=true;Encrypt=False"
+
+
+# JWT Settings
+JWT_SECRET_KEY="dkajsdfhalksjdhfalksdjhfalksdjfhaslkdjfhasdlkfhjasdlkfhjasdfhh"
+JWT_AUDIENCE="http://localhost:28222"
+JWT_ISSUER="https://localhost:44325"
+JWT_DURATION_IN_MINUTES=60000
+
+# Cookie Options
+
+SESSION_COOKIE_EXPIRY_IN_SECONDS=3600
+SURVEY_COOKIE_EXPIRY_IN_SECONDS=1800
+
+# Database Config
+DB_RUN_MIGRATIONS=true
+
+# Attachment Settings
+TEMP_ATTACHMENT_PATH="/var/www/html/attachments/temp"
+ACTUAL_ATTACHMENT_PATH="/var/www/html/attachments/actual"
+
+# Mail Settings
+MAIL_API_KEY="your-sendgrid-api-key-here"
+MAIL_FROM_ADDRESS="eng_z@live.com"
+MAIL_FROM_NAME="Hr Management System"
+MAIL_PASSWORD="your-mail-password-here"
+MAIL_HOST="smtp-mail.outlook.com"
+MAIL_PORT=587
+TEMPLATE_PATH="/var/www/html/attachments/actual"
+
+# OTP Settings
+OTP_LENGTH=4
+OTP_EXPIRE_PERIOD_IN_MINUTES=3000
+OTP_SEND_EMAIL=true
+OTP_ALLOW_ZEROS=false
+OTP_MESSAGE_BODY="Dear User, Your OTP is {0}. Use this passcode to proceed."
+OTP_MESSAGE_SUBJECT="OTP"
+
+# General Settings
+ALLOWED_HOSTS="*"

+ 1 - 1
MTWorkHR.API/Controllers/AttendanceController.cs

@@ -51,7 +51,7 @@ namespace MTWorkHR.API.Controllers
             await _AttendanceService.Update(input);
         }
 
-        [HttpPost("Delete")]
+        [HttpDelete("Delete")]
         [ProducesResponseType(StatusCodes.Status200OK)]
 
         public async Task Delete([FromQuery] long id)

+ 1 - 1
MTWorkHR.API/Controllers/CompanyController.cs

@@ -49,7 +49,7 @@ namespace MTWorkHR.API.Controllers
             return await _companyService.Update(input);
         }
 
-        [HttpPost("Delete")]
+        [HttpDelete("Delete")]
         [ProducesResponseType(StatusCodes.Status200OK)]
 
         public async Task Delete([FromQuery] long id)

+ 1 - 1
MTWorkHR.API/Controllers/MeetingController.cs

@@ -51,7 +51,7 @@ namespace MTWorkHR.API.Controllers
             return await _MeetingService.Update(input);
         }
 
-        [HttpPost("Delete")]
+        [HttpDelete("Delete")]
         [ProducesResponseType(StatusCodes.Status200OK)]
 
         public async Task Delete([FromQuery]long id)

+ 2 - 2
MTWorkHR.API/Controllers/OrderAllocationController.cs

@@ -51,10 +51,10 @@ namespace MTWorkHR.API.Controllers
             await _OrderAllocationService.Update(input);
         }
 
-        [HttpPost("Delete")]
+        [HttpDelete("Delete")]
         [ProducesResponseType(StatusCodes.Status200OK)]
 
-        public async Task Delete(long id)
+        public async Task Delete([FromQuery]long id)
         {
             await _OrderAllocationService.Delete(id);
         }

+ 1 - 1
MTWorkHR.API/Controllers/OrderRequestController.cs

@@ -51,7 +51,7 @@ namespace MTWorkHR.API.Controllers
             return await _LeaveRequestService.Update(input);
         }
 
-        [HttpPost("Delete")]
+        [HttpDelete("Delete")]
         [ProducesResponseType(StatusCodes.Status200OK)]
 
         public async Task Delete([FromQuery]long id)

+ 1 - 1
MTWorkHR.API/Controllers/ProjectController.cs

@@ -52,7 +52,7 @@ namespace MTWorkHR.API.Controllers
             await _ProjectService.Update(input);
         }
 
-        [HttpPost("Delete")]
+        [HttpDelete("Delete")]
         [ProducesResponseType(StatusCodes.Status200OK)]
       //  [AppAuthorize(Permissions = "Project.Delete")]
 

+ 1 - 1
MTWorkHR.API/Controllers/TeamController.cs

@@ -55,7 +55,7 @@ namespace MTWorkHR.API.Controllers
             return await _TeamService.Update(input);
         }
 
-        [HttpPost("Delete")]
+        [HttpDelete("Delete")]
         [ProducesResponseType(StatusCodes.Status200OK)]
       //  [AppAuthorize(Permissions = "Team.Delete")]
 

+ 1 - 1
MTWorkHR.API/Controllers/UserController.cs

@@ -54,7 +54,7 @@ namespace MTWorkHR.API.Controllers
             return Ok(await _userService.Update(input));
         }
 
-        [HttpPost("Delete")]
+        [HttpDelete("Delete")]
         [ProducesResponseType(StatusCodes.Status200OK)]
 
         public async Task Delete([FromQuery] string id)

+ 4 - 4
MTWorkHR.API/Controllers/UserTaskController.cs

@@ -51,10 +51,10 @@ namespace MTWorkHR.API.Controllers
             return await _userTaskService.Update(input);
         }
 
-        [HttpPost("Delete")]
+        [HttpDelete("Delete")]
         [ProducesResponseType(StatusCodes.Status200OK)]
 
-        public async Task Delete(long id)
+        public async Task Delete([FromQuery] long id)
         {
             await _userTaskService.Delete(id);
         }
@@ -75,7 +75,7 @@ namespace MTWorkHR.API.Controllers
             await _attachmentService.Update(input);
         }
 
-        [HttpPost("DeleteAttachment")]
+        [HttpDelete("DeleteAttachment")]
         [ProducesResponseType(StatusCodes.Status200OK)]
         public async Task DeleteAttachment([FromQuery] long id)
         {
@@ -98,7 +98,7 @@ namespace MTWorkHR.API.Controllers
         {
             await _taskHistoryService.Update(input);
         }
-        [HttpPost("DeleteTaskHistory")]
+        [HttpDelete("DeleteTaskHistory")]
         [ProducesResponseType(StatusCodes.Status200OK)]
         public async Task DeleteTaskHistory([FromQuery]long id)
         {

+ 4 - 0
MTWorkHR.API/MTWorkHR.API.csproj

@@ -10,12 +10,16 @@
   </PropertyGroup>
 
   <ItemGroup>
+    <PackageReference Include="Azure.Storage.Blobs" Version="12.20.0" />
+    <PackageReference Include="dotenv.net" Version="3.2.0" />
     <PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="8.0.8" />
     <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.1">
       <PrivateAssets>all</PrivateAssets>
       <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
     </PackageReference>
+    <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
     <PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.5" />
+    <PackageReference Include="Moq" Version="4.20.72" />
     <PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
   </ItemGroup>
 

+ 38 - 4
MTWorkHR.API/Program.cs

@@ -13,20 +13,33 @@ using Microsoft.AspNetCore.Mvc.Controllers;
 using Microsoft.OpenApi.Models;
 using MTWorkHR.API.Swagger;
 using Azure.Storage.Blobs;
+using Moq;
+
+
 using Microsoft.Extensions.DependencyInjection;
 using MTWorkHR.API.Chat;
 using Microsoft.AspNetCore.SignalR;
 
 var builder = WebApplication.CreateBuilder(args);
+
+if (OperatingSystem.IsLinux())
+{
+    builder.Configuration.AddJsonFile("appsettings.Linux.json", optional: true, reloadOnChange: true);
+}
+
+
+
 var config = new AppSettingsConfiguration();
 // Add services to the container.
 builder.Services.AddDbContext<HRDataContext>(options =>
 {
-    options.UseSqlServer(config.ConnectionStrings.LocalConnectionString);
-  //  options.UseSqlServer(builder.Configuration.GetSection("ConnectionStrings:MTWorkHRConnectionString").Value);
+    options.UseSqlServer(config.ConnectionStrings.MTWorkHRConnectionString);
+    //  options.UseSqlServer(builder.Configuration.GetSection("ConnectionStrings:MTWorkHRConnectionString").Value);
 });
 
 
+
+
 builder.Configuration.Bind(config);
 builder.Services.AddApplicationServices(config);
 builder.Services.AddInfrastructureIdentityServices(config);
@@ -34,7 +47,28 @@ builder.Services.AddInfrastructureIdentityServices(config);
 //builder.Services.AddIdentityServices(config);
 builder.Services.AddHostedService<DbMigrationService>();
 
-builder.Services.AddSingleton(x => new BlobServiceClient(config.ConnectionStrings.BlobConnectionString));
+
+
+
+if (builder.Environment.IsDevelopment())
+{
+    var mockBlobServiceClient = new Mock<BlobServiceClient>();
+
+    // Mock BlobContainerClient since this is what BlobServiceClient interacts with.
+    var mockBlobContainerClient = new Mock<BlobContainerClient>();
+
+    // Set up the mock to return a mock BlobContainerClient when requested.
+    mockBlobServiceClient
+        .Setup(x => x.GetBlobContainerClient(It.IsAny<string>()))
+        .Returns(mockBlobContainerClient.Object);
+
+    builder.Services.AddSingleton(mockBlobServiceClient.Object);
+}
+else
+{
+    // Use the actual connection string for production or other environments.
+    builder.Services.AddSingleton(x => new BlobServiceClient(config.ConnectionStrings.BlobConnectionString));
+}
 
 //builder.Services.AddControllers();
 builder.Services.AddControllers(options =>
@@ -117,7 +151,7 @@ app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "MTWorkHR.AP
 app.UseCors(x => x
     .AllowAnyMethod()
     .AllowAnyHeader()
-    .SetIsOriginAllowed(origin => 
+    .SetIsOriginAllowed(origin =>
     true) // allow any origin
     .AllowCredentials()); // allow credentials
 

+ 46 - 0
MTWorkHR.API/appsettings.Linux.json

@@ -0,0 +1,46 @@
+{
+    "Logging": {
+        "LogLevel": {
+            "Default": "Information",
+            "Microsoft.AspNetCore": "Warning"
+        }
+    },
+    "ConnectionStrings": {
+        "LocalConnectionString": "Server=localhost;Database=MTWorkHRDB;User=sa;Password=Mahmoud001;MultipleActiveResultSets=true;Encrypt=False"
+    },
+    "JwtSettings": {
+        "SecretKey": "dkajsdfhalksjdhfalksdjhfalksdjfhaslkdjfhasdlkfhjasdlkfhasdlkfhjasdfhh",
+        "Audience": "http://localhost:28222",
+        "Issuer": "https://localhost:44325",
+        "DurationInMinutes": 60000
+    },
+    "CookieOptions": {
+        "SessionCookieExpiryInSeconds": 3600,
+        "SurveyCookieExpiryInSeconds": 1800
+    },
+    "DbConfig": {
+        "RunMigrations": true
+    },
+    "AttachmentSettings": {
+        "TempAttachment": "/var/www/html/attachments/temp",
+        "ActualAttachment": "/var/www/html/attachments/actual"
+    },
+    "MailSettings": {
+        "ApiKey": "SendGrid-Key",
+        "FromAddress": "eng_z@live.com",
+        "FromName": "Hr Management System",
+        "Password": "111111111111",
+        "Host": "smtp-mail.outlook.com",
+        "Port": 587,
+        "TemplatePath": "/var/www/html/attachments/mailtemp"
+    },
+    "OTPSettings": {
+        "Length": 4,
+        "ExpirePeriodInMinutes": 3000,
+        "SendEmail": true,
+        "AllowZeros": false,
+        "MessageBody": "Dear User, Your OTP is {0}. Use this passcode to proceed.",
+        "MessageSubject": "OTP"
+    },
+    "AllowedHosts": "*"
+}

+ 2 - 2
MTWorkHR.Application/ApplicationServiceRegistration.cs

@@ -22,8 +22,8 @@ namespace MTWorkHR.Application
 
             services.AddScoped<IAuthService, AuthService>();
             services.AddScoped<IUserService, UserService>();
-            services.AddTransient<IFileService, FileService>();
-          //  services.AddScoped<IFileService, BlobFileService>();
+          //  services.AddTransient<IFileService, FileService>();
+            services.AddScoped<IFileService, BlobFileService>();
             services.AddScoped<IProjectService, ProjectService>();
             services.AddScoped<IUserTaskService, UserTaskService>();
             services.AddScoped<IUserTaskAttachmentService, UserTaskAttachmentService>();

+ 9 - 1
MTWorkHR.Application/Middlewares/LoggingMiddleware.cs

@@ -15,6 +15,7 @@ using Microsoft.AspNetCore.Mvc;
 using MTWorkHR.Core.UnitOfWork;
 using MTWorkHR.Application.Services;
 using MTWorkHR.Core.Global;
+using Microsoft.Extensions.Logging;
 
 namespace MTWorkHR.Application.Middlewares
 {
@@ -22,9 +23,14 @@ namespace MTWorkHR.Application.Middlewares
     {
         private readonly RequestDelegate _next;
 
-        public LoggingMiddleware(RequestDelegate next)
+        private readonly ILogger<LoggingMiddleware> _logger;
+
+
+        public LoggingMiddleware(RequestDelegate next, ILogger<LoggingMiddleware> logger)
         {
             _next = next;
+            _logger = logger;
+
         }
 
         public async Task Invoke(HttpContext context, IUnitOfWorkLog unitOfWork)
@@ -36,6 +42,8 @@ namespace MTWorkHR.Application.Middlewares
             catch (Exception error)
             {
                 //Get target controller info
+                _logger.LogError(error, "An error occurred during request processing");
+
                 var controllerActionDescriptor = context?
                     .GetEndpoint()?
                     .Metadata

+ 25 - 10
MTWorkHR.Application/Services/User/UserService.cs

@@ -168,18 +168,33 @@ namespace MTWorkHR.Application.Services
                 .Include(u => u.Qualification).Include(u => u.JobTitle).Include(u => u.University).Include(u => u.Industry).Include(u => u.Country)
                 .Where(e => _globalInfo.CompanyId == null || e.CompanyId != _globalInfo.CompanyId)
                 .AsQueryable();
-
-            if (PagingInputDto.Filter != null)
+            var filter = PagingInputDto.Filter;
+            query = query.Where(u =>
+         u.UserName.Contains(filter) ||
+         u.Email.Contains(filter) ||
+         u.FavoriteName.Contains(filter) ||
+         u.Position.Contains(filter) ||
+         u.PhoneNumber.Contains(filter));
+
+            // Check if the filter contains a space (indicating a full name)
+            if (filter.Contains(" "))
+            {
+                var fullName = filter.Split(" ");
+                var firstNameFilter = fullName[0];
+                var lastNameFilter = fullName.Length > 1 ? fullName[1] : "";
+
+                query = query.Where(u =>
+                    (u.FirstName.Contains(firstNameFilter) &&
+                     (string.IsNullOrEmpty(lastNameFilter) || u.LastName.Contains(lastNameFilter))) ||
+                    (u.LastName.Contains(lastNameFilter) &&
+                     (string.IsNullOrEmpty(firstNameFilter) || u.FirstName.Contains(firstNameFilter))));
+            }
+            else
             {
-                var filter = PagingInputDto.Filter;
-                query = query.Where(u => 
-                    u.UserName.Contains(filter) ||
-                    u.Email.Contains(filter) ||
+                // If there's no space, apply the filter for individual names
+                query = query.Where(u =>
                     u.FirstName.Contains(filter) ||
-                    u.LastName.Contains(filter) ||
-                    u.FavoriteName.Contains(filter) ||
-                    u.Position.Contains(filter) ||
-                    u.PhoneNumber.Contains(filter));
+                    u.LastName.Contains(filter));
             }
             if (PagingInputDto.IndustryId != null && PagingInputDto.IndustryId.Count > 0)
             {

+ 1 - 1
MTWorkHR.Infrastructure/InfrastructureServiceRegistration.cs

@@ -31,7 +31,7 @@ namespace MTWorkHR.Infrastructure
             
             services.AddDbContext<HRDataContext>(options =>
                 options.UseSqlServer(
-                    config.ConnectionStrings.LocalConnectionString  //configuration.GetSection("ConnectionString:MTWorkHRConnectionString").Value
+                    config.ConnectionStrings.MTWorkHRConnectionString  //configuration.GetSection("ConnectionString:MTWorkHRConnectionString").Value
                     ));
            
             services.AddIdentity<ApplicationUser, ApplicationRole>().AddEntityFrameworkStores<HRDataContext>().AddDefaultTokenProviders();