소스 검색

companyUser data

zinab_elgendy 6 달 전
부모
커밋
479ff70e78

+ 5 - 3
MTWorkHR.API/Controllers/CompanyController.cs

@@ -11,7 +11,7 @@ namespace MTWorkHR.API.Controllers
 {
     [Route("api/[controller]")]
     [ApiController]
-    //[AppAuthorize]
+    [AppAuthorize]
     public class CompanyController : ControllerBase
     {
         private readonly ICompanyService _companyService;
@@ -25,15 +25,17 @@ namespace MTWorkHR.API.Controllers
             return Ok( await _companyService.GetAll(pagingInput));
         }
         [HttpGet("Get")]
-        public async Task<ActionResult<CompanyDto>> Get(long CompanyId)
+
+        public async Task<ActionResult<CompanyDto>> Get()
         {
-            return Ok(await _companyService.GetById(CompanyId));
+            return Ok(await _companyService.GetById());
         }
 
 
         [HttpPost("Create")]
         [ProducesResponseType(StatusCodes.Status200OK)]
         [Consumes("multipart/form-data")]
+        [AllowAnonymous]
         public async Task<ActionResult<CompanyDto>> Create([FromForm] CompanyDto input)
         {
             return await _companyService.Create(input);

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

@@ -32,9 +32,9 @@ namespace MTWorkHR.API.Controllers
             return Ok(await _userService.GetAllCompanyEmployees());
         }
         [HttpGet("Get")]
-        public async Task<ActionResult<UserDto>> Get(string userId)
+        public async Task<ActionResult<UserDto>> Get()
         {
-            return Ok(await _userService.GetById(userId));
+            return Ok(await _userService.GetById());
         }
 
 

+ 3 - 1
MTWorkHR.Application/Dtos/Identity/CompanyUserDto.cs

@@ -12,7 +12,8 @@ namespace MTWorkHR.Application.Models
     public class CompanyUserDto
     {
         public string? Id { get; set; }
-       
+        public string? UserName { get; set; }
+
         [Required]
         public string FirstName { get; set; }
         public string LastName { get; set; }
@@ -30,6 +31,7 @@ namespace MTWorkHR.Application.Models
         public string? Password { get; set; }
       
         public decimal? TaxNumber { get; set; }
+        public decimal? IncomeTaxValue { get; set; }
         public IList<AttachmentDto>? UserAttachments{ get; set; }
         public UserAddressDto? UserAddress{ get; set; }
     }

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

@@ -15,7 +15,7 @@ namespace MTWorkHR.Application.Models
 
         public string CRNumber { get; set; } //Commercial Registration
         public string? UserId { get; set; }
-
+        public UserTypeEnum? UserType { get; set; }
 
         public CompanyUserDto? CompanyUser { get; set; }
         public IFormFile? ProfileImage { get; set; }

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

@@ -24,10 +24,10 @@ namespace MTWorkHR.Application.Filters
             var cc = context.HttpContext.User.Identities.FirstOrDefault();
             var cc2 = cc.Claims.FirstOrDefault(c => c.Type.Contains( "email"));
             var email = cc2 != null ? cc2.Value : "";
-            var generatedGuid = context.HttpContext.User.Identities.FirstOrDefault().FindFirst("Jti").Value;
+            var generatedGuid = context.HttpContext.User.Identities.FirstOrDefault().FindFirst("Jti")?.Value;
             var companyId = context.HttpContext.User.Identities.FirstOrDefault().FindFirst("companyId")?.Value;
-            var userId = context.HttpContext.User.Identities.FirstOrDefault().FindFirst("uid").Value;
-            var userName = context.HttpContext.User.Identities.FirstOrDefault().FindFirst("name").Value;
+            var userId = context.HttpContext.User.Identities.FirstOrDefault().FindFirst("uid")?.Value;
+            var userName = context.HttpContext.User.Identities.FirstOrDefault().FindFirst("name")?.Value;
         //    var email1 = context.HttpContext.User.Identities.FirstOrDefault().FindFirst("emailaddress").Value;
         //    var email2 = context.HttpContext.User.Identities.FirstOrDefault().FindFirst("email").Value;
           //  var hierarchyIds = context.HttpContext.User.Identities.FirstOrDefault().FindFirst("hierarchyIds").Value;
@@ -54,7 +54,12 @@ namespace MTWorkHR.Application.Filters
             globalInfo.SetValues( userName, userId, companyId !=null && companyId != "" ? long.Parse(companyId) : null , token, lang);
 
             var userManager = context.HttpContext.RequestServices.GetService<ApplicationUserManager>();
-
+            bool hasAllowAnonymousFlag = context.ActionDescriptor.EndpointMetadata
+                           .Any(em => em.GetType() == typeof(AllowAnonymousAttribute));
+            if (hasAllowAnonymousFlag)
+            {
+                return;
+            }
             //check if user blocked
             if (await userManager.IsStopped(userId))
             {

+ 1 - 0
MTWorkHR.Application/Services/Interfaces/ICompanyService.cs

@@ -13,6 +13,7 @@ namespace MTWorkHR.Application.Services.Interfaces
     {
       
         Task<List<CompanyDto>> GetAllCompanies();
+        Task<CompanyDto> GetById();
         
     }
 }

+ 1 - 0
MTWorkHR.Application/Services/Interfaces/IUserService.cs

@@ -12,6 +12,7 @@ namespace MTWorkHR.Application.Identity
     {
         Task<PagingResultDto<UserAllDto>> GetAll(UserPagingInputDto PagingInputDto);
         Task<UserDto> GetById(string userId);
+        Task<UserDto> GetById();
         Task<List<UserDto>> GetAllEmployees();
 
         Task<UserDto> GetUserById(string id);

+ 12 - 5
MTWorkHR.Application/Services/User/CompanyService.cs

@@ -16,9 +16,11 @@ using MTWorkHR.Infrastructure.Entities;
 using System.Transactions;
 using MTWorkHR.Core.Entities.Base;
 using System.Threading.Tasks;
+using MTWorkHR.Application.Filters;
 
 namespace MTWorkHR.Application.Services
 {
+    
     public class CompanyService :BaseService<Company, CompanyDto, CompanyDto>, ICompanyService
     {
         private readonly IUnitOfWork _unitOfWork;
@@ -40,12 +42,17 @@ namespace MTWorkHR.Application.Services
         }
 
      
-        public override async Task<CompanyDto> GetById(long CompanyId)
+        public async Task<CompanyDto> GetById()
         {
-            var entity = await _unitOfWork.Company.GetByIdAsync(CompanyId);
-            var companyResponse = MapperObject.Mapper.Map<CompanyDto>(entity);
-            var userDto = await _userService.GetById(entity.UserId);
-            companyResponse.CompanyUser = MapperObject.Mapper.Map<CompanyUserDto>(userDto);
+            var companyResponse = new CompanyDto();
+            if (_globalInfo.CompanyId.HasValue)
+            {
+                var entity = await _unitOfWork.Company.GetByIdAsync(_globalInfo.CompanyId.Value);
+                companyResponse = MapperObject.Mapper.Map<CompanyDto>(entity);
+                var userDto = await _userService.GetById(entity.UserId);
+                companyResponse.CompanyUser = MapperObject.Mapper.Map<CompanyUserDto>(userDto);
+                companyResponse.UserType = companyResponse.CompanyUser.UserType;
+            }
             return companyResponse;
         }
 

+ 5 - 2
MTWorkHR.Application/Services/User/UserService.cs

@@ -51,9 +51,12 @@ namespace MTWorkHR.Application.Services
             _globalInfo = globalInfo;
             _fileService = fileService;
             _oTPService = oTPService;
-        }   
-
+        }
 
+        public async Task<UserDto> GetById()
+        {
+            return await GetById(_globalInfo.UserId);
+        }
         public async Task<UserDto> GetById(string id)
         {
             var entity = await _userManager.Users