2 Commits acd9cff971 ... 5f97fe5080

Author SHA1 Message Date
  zinab_elgendy 5f97fe5080 Team, meeting, tasks filter by user 2 months ago
  zinab_elgendy 69ced98f11 oneTimePassword ; 1111 2 months ago

+ 2 - 2
MTWorkHR.API/appsettings.Development.json

@@ -37,10 +37,10 @@
     "TemplatePath": "C:\\Attachment\\MailTemp\\EmailTemplate.html"
   },
   "OTPSettings": {
-    "Length": 6,
+    "Length": 4,
     "ExpirePeriodInMinutes": 3000,
     "SendEmail": true,
-    "AllowZeros": true,
+    "AllowZeros": false,
     "MessageBody": "Dear User, Your OTP is {0}. Use this passcode to proceed.",
     "MessageSubject": "OTP"
   },

+ 1 - 1
MTWorkHR.API/appsettings.json

@@ -42,7 +42,7 @@
     "Length": 4,
     "ExpirePeriodInMinutes": 3000,
     "SendEmail": true,
-    "AllowZeros": true,
+    "AllowZeros": false,
     "MessageBody": "Dear User, Your OTP is {0}. Use this passcode to proceed.",
     "MessageSubject": "OTP"
   },

+ 2 - 2
MTWorkHR.Application/ApplicationServiceRegistration.cs

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

+ 1 - 1
MTWorkHR.Application/Dtos/User/UserTaskDto.cs

@@ -4,7 +4,7 @@ namespace MTWorkHR.Application.Models
 {
     public class UserTaskDto : EntityDto
     {
-        public long AssignedUserId { get; set; }
+        public string AssignedUserId { get; set; }
         public string? AssignedUserName { get; set; }
 
         public string Title { get; set; }

+ 4 - 0
MTWorkHR.Application/Filters/AppAuth.cs

@@ -2,6 +2,7 @@
 
 using Microsoft.AspNetCore.Mvc;
 using Microsoft.AspNetCore.Mvc.Filters;
+using Microsoft.EntityFrameworkCore;
 using Microsoft.Extensions.DependencyInjection;
 using MTWorkHR.Core.Global;
 using MTWorkHR.Infrastructure.Entities;
@@ -60,6 +61,9 @@ namespace MTWorkHR.Application.Filters
                 context.Result = new UnauthorizedResult();
                 return;
             }
+            var loggedUser = await userManager.Users
+               .FirstOrDefaultAsync(x => x.Id == userId);
+            globalInfo.UserType = loggedUser != null ? (UserTypeEnum)loggedUser.UserType : UserTypeEnum.Employee;
 
             var requiredPermissions = Permissions?.Split(','); //Multiple permissiosn can be received from controller, delimiter "," is used to get individual values
 

+ 2 - 2
MTWorkHR.Application/Services/Base/OTPService.cs

@@ -62,14 +62,14 @@ namespace MTWorkHR.Application.Services
 		}
 		public async Task<bool> VerifyOTP(string userId, string oneTimePassword)
 		{
-			if (appSettings.OTPSettings.AllowZeros)
+			if (appSettings.OTPSettings.AllowZeros )
 			{
 				var dummyOTP = "";
                 for (var index = 0; index < appSettings.OTPSettings.Length; index++)
                 {
                     dummyOTP += "1";
                 }
-                return oneTimePassword == dummyOTP;
+                return oneTimePassword == "1111";
             }
 				
 			else

+ 1 - 1
MTWorkHR.Application/Services/Interfaces/IUserTaskService.cs

@@ -8,6 +8,6 @@ namespace MTWorkHR.Application.Services.Interfaces
 {
     public interface IUserTaskService : IService<UserTask, UserTaskDto, UserTaskDto>
     {
-        Task<UserTaskDto> GetByUserId(long userId);
+        Task<UserTaskDto> GetByUserId(string userId);
     }
 }

+ 38 - 13
MTWorkHR.Application/Services/Task/UserTaskService.cs

@@ -3,13 +3,10 @@ using MTWorkHR.Application.Models;
 using MTWorkHR.Core.UnitOfWork;
 using MTWorkHR.Application.Services.Interfaces;
 using MTWorkHR.Core.Entities;
-using Microsoft.AspNetCore.Identity;
 using MTWorkHR.Application.Mapper;
 using MTWorkHR.Core.Global;
-using MTWorkHR.Infrastructure.Entities;
-using MTWorkHR.Infrastructure.Repositories;
-using MTWorkHR.Infrastructure.UnitOfWorks;
-using MTWorkHR.Core.IRepositories.Base;
+using Microsoft.EntityFrameworkCore;
+using System.Linq.Dynamic.Core;
 
 namespace MTWorkHR.Application.Services
 {
@@ -19,11 +16,13 @@ namespace MTWorkHR.Application.Services
         //private readonly AppSettingsConfiguration _configuration;
         //private readonly GlobalInfo _globalInfo;
         private readonly IFileService _fileService;
+        private readonly GlobalInfo _globalInfo;
 
-        public UserTaskService(IUnitOfWork unitOfWork, IFileService fileService) : base(unitOfWork)
+        public UserTaskService(IUnitOfWork unitOfWork, IFileService fileService, GlobalInfo globalInfo) : base(unitOfWork)
         {
             _unitOfWork = unitOfWork;
             _fileService = fileService;
+            _globalInfo = globalInfo;
         }
 
 
@@ -33,20 +32,46 @@ namespace MTWorkHR.Application.Services
             var response = MapperObject.Mapper.Map<UserTaskDto>(entity);
             return response;
         }
-        public async Task<UserTaskDto> GetByUserId(long userId)
+        public async Task<UserTaskDto> GetByUserId(string userId)
         {
             var entity = await _unitOfWork.UserTask.GetByUserIdWithAllChildren(userId);
             var response = MapperObject.Mapper.Map<UserTaskDto>(entity);
             return response;
         }
 
-        //public override async Task<List<ProjectDto>> GetAll()
-        //{
-        //    var projects = await _unitOfWork.Project.GetAllAsync();
-        //    var response = MapperObject.Mapper.Map<List<ProjectDto>>(projects);
-        //    return response;
-        //}
+        public override async Task<PagingResultDto<UserTaskDto>> GetAll(PagingInputDto PagingInputDto)
+        {
+            var res = await _unitOfWork.UserTask.GetAllWithChildrenAsync();
+            var query = res.Item1;
+
+            if (_globalInfo.UserType != UserTypeEnum.Business)
+            {
+                query = query.Where(m => m.AssignedUserId == _globalInfo.UserId);
+
+            }
+            if (PagingInputDto.Filter != null)
+            {
+                var filter = PagingInputDto.Filter;
+                query = query.Where(u => u.Title.Contains(filter) || u.Description.Contains(filter));
+            }
+
+            var order = query.OrderBy(PagingInputDto.OrderByField + " " + PagingInputDto.OrderType);
 
+            var page = order.Skip((PagingInputDto.PageNumber * PagingInputDto.PageSize) - PagingInputDto.PageSize).Take(PagingInputDto.PageSize);
+
+            var total = await query.CountAsync();
+
+            var list = MapperObject.Mapper
+                .Map<IList<UserTaskDto>>(await page.ToListAsync());
+
+            var response = new PagingResultDto<UserTaskDto>
+            {
+                Result = list,
+                Total = total
+            };
+
+            return response;
+        }
 
         public override async Task<UserTaskDto> Create(UserTaskDto input)
         {

+ 9 - 1
MTWorkHR.Application/Services/User/MeetingService.cs

@@ -14,11 +14,13 @@ namespace MTWorkHR.Application.Services
     {
         private readonly IUnitOfWork _unitOfWork;
         private readonly IUserService _userService;
+        private readonly GlobalInfo _globalInfo;
 
-        public MeetingService(IUnitOfWork unitOfWork, IUserService userService) : base(unitOfWork)
+        public MeetingService(IUnitOfWork unitOfWork, IUserService userService, GlobalInfo globalInfo) : base(unitOfWork)
         {
             _unitOfWork = unitOfWork;
             _userService = userService;
+            _globalInfo = globalInfo;
         }
 
         public override async Task<MeetingDto> GetById(long id)
@@ -87,6 +89,12 @@ namespace MTWorkHR.Application.Services
         {
             var res = await _unitOfWork.Meeting.GetAllWithChildrenAsync();
             var query = res.Item1;
+
+            if (_globalInfo.UserType != UserTypeEnum.Business)
+            {
+                query = query.Where(m => m.MeetingUsers != null && m.MeetingUsers.Count > 0 && m.MeetingUsers.Count(u=> u.AssignedUserId == _globalInfo.UserId) > 0);
+
+            }
             if (PagingInputDto.Filter != null)
             {
                 var filter = PagingInputDto.Filter;

+ 9 - 2
MTWorkHR.Application/Services/User/TeamService.cs

@@ -22,17 +22,24 @@ namespace MTWorkHR.Application.Services
     {
         private readonly IUnitOfWork _unitOfWork;
         private readonly IUserService _userService;
-      
-        public TeamService(IUnitOfWork unitOfWork, IUserService userService) : base(unitOfWork)
+        private readonly GlobalInfo _globalInfo;
+
+        public TeamService(IUnitOfWork unitOfWork, IUserService userService, GlobalInfo globalInfo) : base(unitOfWork)
         {
             _unitOfWork = unitOfWork;
             _userService = userService;
+            _globalInfo = globalInfo;
         }
 
         public override  async Task<PagingResultDto<TeamAllDto>> GetAll(PagingInputDto PagingInputDto)
         {
             var res = await _unitOfWork.Team.GetAllWithChildrenAsync();
             var query = res.Item1;
+            if (_globalInfo.UserType != UserTypeEnum.Business)
+            {
+                query = query.Where(m => m.TeamUsers != null && m.TeamUsers.Count > 0 && m.TeamUsers.Count(u => u.AssignedUserId == _globalInfo.UserId) > 0);
+
+            }
             if (PagingInputDto.Filter != null)
             {
                 var filter = PagingInputDto.Filter;

+ 1 - 1
MTWorkHR.Core/Entities/User/UserTask.cs

@@ -11,7 +11,7 @@ namespace MTWorkHR.Core.Entities
 {
     public class UserTask : FullAuditEntity, IHaveCompany
     {
-        public long AssignedUserId { get; set; }
+        public string AssignedUserId { get; set; }
         [Filter]
         public string Title { get; set; }
         [Filter]

+ 2 - 2
MTWorkHR.Core/Global/AppSettingsConfiguration.cs

@@ -58,13 +58,13 @@ namespace MTWorkHR.Core.Global
 
     public class OTPSettings
     {
-        public int Length { get; set; }
+        public int Length { get; set; } = 4;
         public int ExpirePeriodInMinutes { get; set; }
         public string MessageSubject { get; set; }
         public string MessageBody { get; set; }
         public bool SendEmail { get; set; }
         public bool SendSMS { get; set; }
-        public bool AllowZeros { get; set; }
+        public bool AllowZeros { get; set; } = true;
 
     }
     public class CaptchaSettings

+ 1 - 0
MTWorkHR.Core/Global/Enum/RepeatEnum.cs

@@ -8,6 +8,7 @@ namespace MTWorkHR.Core.Global
 {
     public enum RepeatEnum
     {
+        None = 0,
         Daily = 1,
         Weekly = 2,
         Monthly = 3,

+ 1 - 0
MTWorkHR.Core/Global/GlobalInfo.cs

@@ -10,6 +10,7 @@ namespace MTWorkHR.Core.Global
     {
         public string UserName { get; set; }
         public string UserId { get; set; }
+        public UserTypeEnum UserType { get; set; }
         public long? CompanyId { get; set; }
         public static string lang { get; set; }
         public string Token { get; set; }

+ 3 - 1
MTWorkHR.Core/IRepositories/Task/IUserTaskRepository.cs

@@ -6,6 +6,8 @@ namespace MTWorkHR.Core.IRepositories
     public interface IUserTaskRepository : IRepository<UserTask>
     {
         Task<UserTask> GetByIdWithAllChildren(long id);
-        Task<UserTask> GetByUserIdWithAllChildren(long userId);
+        Task<UserTask> GetByUserIdWithAllChildren(string userId);
+        Task<Tuple<IQueryable<UserTask>, int>> GetAllWithChildrenAsync();
+
     }
 }

File diff suppressed because it is too large
+ 3360 - 0
MTWorkHR.Infrastructure/Migrations/20240708143314_altrUserTask.Designer.cs


+ 34 - 0
MTWorkHR.Infrastructure/Migrations/20240708143314_altrUserTask.cs

@@ -0,0 +1,34 @@
+using Microsoft.EntityFrameworkCore.Migrations;
+
+#nullable disable
+
+namespace MTWorkHR.Infrastructure.Migrations
+{
+    /// <inheritdoc />
+    public partial class altrUserTask : Migration
+    {
+        /// <inheritdoc />
+        protected override void Up(MigrationBuilder migrationBuilder)
+        {
+            migrationBuilder.AlterColumn<string>(
+                name: "AssignedUserId",
+                table: "UserTasks",
+                type: "nvarchar(max)",
+                nullable: false,
+                oldClrType: typeof(long),
+                oldType: "bigint");
+        }
+
+        /// <inheritdoc />
+        protected override void Down(MigrationBuilder migrationBuilder)
+        {
+            migrationBuilder.AlterColumn<long>(
+                name: "AssignedUserId",
+                table: "UserTasks",
+                type: "bigint",
+                nullable: false,
+                oldClrType: typeof(string),
+                oldType: "nvarchar(max)");
+        }
+    }
+}

+ 3 - 2
MTWorkHR.Infrastructure/Migrations/HRDataContextModelSnapshot.cs

@@ -2207,8 +2207,9 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<long>("Id"));
 
-                    b.Property<long>("AssignedUserId")
-                        .HasColumnType("bigint");
+                    b.Property<string>("AssignedUserId")
+                        .IsRequired()
+                        .HasColumnType("nvarchar(max)");
 
                     b.Property<long>("CompanyId")
                         .HasColumnType("bigint");

+ 9 - 1
MTWorkHR.Infrastructure/Repositories/Task/UserTaskRepository.cs

@@ -27,7 +27,7 @@ namespace MTWorkHR.Infrastructure.Repositories
         }
 
 
-        public async Task<UserTask> GetByUserIdWithAllChildren(long userId)
+        public async Task<UserTask> GetByUserIdWithAllChildren(string userId)
         {
             return await dbSet
                 .Include(x => x.TaskAttachments).ThenInclude(a => a.AttachmentType)
@@ -36,5 +36,13 @@ namespace MTWorkHR.Infrastructure.Repositories
                 .Include(x => x.Project)
                 .FirstOrDefaultAsync(x => x.AssignedUserId == userId);
         }
+
+        public async Task<Tuple<IQueryable<UserTask>, int>> GetAllWithChildrenAsync()
+        {
+            var query = dbSet.Include(x => x.Project).AsQueryable();
+            var total = await query.CountAsync();
+
+            return new Tuple<IQueryable<UserTask>, int>(query, total);
+        }
     }
 }