From 080088528ea3120672521863a35a7b28ad4610b2 Mon Sep 17 00:00:00 2001 From: "Amir.H Khademi" Date: Wed, 29 Nov 2023 13:02:59 +0330 Subject: [PATCH] update .net to .net 8 --- Brizco.Api/Brizco.Api.csproj | 2 +- Brizco.Api/Controllers/UserController.cs | 2 +- Brizco.Core/Brizco.Core.csproj | 2 +- .../EntityServices/Abstracts/IUserService.cs | 1 + Brizco.Core/EntityServices/UserService.cs | 62 ++++++++++++------- Brizco.Domain/Brizco.Domain.csproj | 2 +- .../Brizco.Infrastructure.csproj | 2 +- Brizco.Repository/Brizco.Repository.csproj | 2 +- global.json | 5 -- 9 files changed, 46 insertions(+), 34 deletions(-) delete mode 100644 global.json diff --git a/Brizco.Api/Brizco.Api.csproj b/Brizco.Api/Brizco.Api.csproj index c8f4679..b3be273 100644 --- a/Brizco.Api/Brizco.Api.csproj +++ b/Brizco.Api/Brizco.Api.csproj @@ -1,7 +1,7 @@  - net7.0 + net8.0 enable enable Linux diff --git a/Brizco.Api/Controllers/UserController.cs b/Brizco.Api/Controllers/UserController.cs index 0894c88..d2e158f 100644 --- a/Brizco.Api/Controllers/UserController.cs +++ b/Brizco.Api/Controllers/UserController.cs @@ -54,5 +54,5 @@ public class UserController : ICarterModule // DELETE:Delete Entity public async Task Delete(Guid id, IUserService userService, CancellationToken cancellationToken) - => TypedResults.Ok(await userService.RemoveUserAsync(id, cancellationToken)); + => TypedResults.Ok(await userService.RemoveUserFromComplexAsync(id, cancellationToken)); } \ No newline at end of file diff --git a/Brizco.Core/Brizco.Core.csproj b/Brizco.Core/Brizco.Core.csproj index 3032b9c..ce14a5c 100644 --- a/Brizco.Core/Brizco.Core.csproj +++ b/Brizco.Core/Brizco.Core.csproj @@ -1,7 +1,7 @@  - net7.0 + net8.0 enable enable diff --git a/Brizco.Core/EntityServices/Abstracts/IUserService.cs b/Brizco.Core/EntityServices/Abstracts/IUserService.cs index e551e1b..3471b1f 100644 --- a/Brizco.Core/EntityServices/Abstracts/IUserService.cs +++ b/Brizco.Core/EntityServices/Abstracts/IUserService.cs @@ -12,6 +12,7 @@ public interface IUserService : IScopedDependency Task EditUserAsync(UserActionRequestDto request, CancellationToken cancellationToken); Task EditUserProfileAsync(UserActionRequestDto request, CancellationToken cancellationToken); Task RemoveUserAsync(Guid userId, CancellationToken cancellationToken); + Task RemoveUserFromComplexAsync(Guid userId, CancellationToken cancellationToken); Task> GetRolesAsync(int page = 0, CancellationToken cancellationToken = default); diff --git a/Brizco.Core/EntityServices/UserService.cs b/Brizco.Core/EntityServices/UserService.cs index acf8a09..c452f16 100644 --- a/Brizco.Core/EntityServices/UserService.cs +++ b/Brizco.Core/EntityServices/UserService.cs @@ -1,9 +1,7 @@ using System.Security.Claims; -using System.Threading; using Brizco.Domain.CommandQueries.Queries; using Brizco.Domain.Mappers; using Mapster; -using Newtonsoft.Json.Linq; namespace Brizco.Core.EntityServices; @@ -172,28 +170,33 @@ public class UserService : IUserService if (!Guid.TryParse(_currentUserService.ComplexId, out Guid complexId)) throw new AppException("Wrong authorize token , ComplexId needed"); - var user = new ApplicationUser + var user = await _userManager.FindByNameAsync(request.PhoneNumber); + if (user == null) { - UserName = request.PhoneNumber, - PhoneNumber = request.PhoneNumber, - FirstName = request.FirstName, - LastName = request.LastName, - NationalId = request.NationalId, - BirthDate = DateTimeExtensions.UnixTimeStampToDateTime(request.BirthDateTimeStamp), - Gender = request.Gender, - SignUpStatus = SignUpStatus.SignUpCompleted - }; - if (!request.Password.IsNullOrEmpty()) - { - var result = await _userManager.CreateAsync(user, request.Password); - if (!result.Succeeded) - throw new AppException(string.Join('|', result.Errors.Select(e => e.Description))); - } - else - { - var result = await _userManager.CreateAsync(user); - if (!result.Succeeded) - throw new AppException(string.Join('|', result.Errors.Select(e => e.Description))); + user = new ApplicationUser + { + UserName = request.PhoneNumber, + PhoneNumber = request.PhoneNumber, + FirstName = request.FirstName, + LastName = request.LastName, + NationalId = request.NationalId, + BirthDate = DateTimeExtensions.UnixTimeStampToDateTime(request.BirthDateTimeStamp), + Gender = request.Gender, + SignUpStatus = SignUpStatus.SignUpCompleted + }; + + if (!request.Password.IsNullOrEmpty()) + { + var result = await _userManager.CreateAsync(user, request.Password); + if (!result.Succeeded) + throw new AppException(string.Join('|', result.Errors.Select(e => e.Description))); + } + else + { + var result = await _userManager.CreateAsync(user); + if (!result.Succeeded) + throw new AppException(string.Join('|', result.Errors.Select(e => e.Description))); + } } await _sender.Send(new CreateComplexUserCommand(complexId, user.Id, request.RoleIds), cancellationToken); @@ -291,6 +294,19 @@ public class UserService : IUserService return true; } + public async Task RemoveUserFromComplexAsync(Guid userId, CancellationToken cancellationToken) + { + if (_currentUserService.ComplexId.IsNullOrEmpty()) + throw new AppException("Wrong authorize token , ComplexId needed"); + if (!Guid.TryParse(_currentUserService.ComplexId, out Guid complexId)) + throw new AppException("Wrong authorize token , ComplexId needed"); + var user = await _userManager.FindByIdAsync(userId.ToString()); + if (user == null) + throw new AppException("User not found", ApiResultStatusCode.NotFound); + await _sender.Send(new DeleteComplexUserCommand(userId, complexId), cancellationToken); + return true; + } + public async Task> GetRolesAsync(int page = 0, CancellationToken cancellationToken = default) diff --git a/Brizco.Domain/Brizco.Domain.csproj b/Brizco.Domain/Brizco.Domain.csproj index e6ccecf..7d4abd0 100644 --- a/Brizco.Domain/Brizco.Domain.csproj +++ b/Brizco.Domain/Brizco.Domain.csproj @@ -1,7 +1,7 @@