fix BaseTakeSelfiePageModel
This commit is contained in:
		
							parent
							
								
									b313d21a11
								
							
						
					
					
						commit
						7da749777e
					
				| @ -11,9 +11,11 @@ namespace EnotaryoPH.Web.Pages | ||||
|     public class BaseTakeSelfiePageModel : PageModel | ||||
|     { | ||||
|         protected readonly NotaryoDBContext _notaryoDBContext; | ||||
|         private readonly ICurrentUserService _currentUserService; | ||||
|         private readonly ICompreFaceClient _compreFaceClient; | ||||
|         private readonly IConfiguration _configuration; | ||||
|         private readonly ICurrentUserService _currentUserService; | ||||
|         private Transaction _transactionEntity; | ||||
|         private User _user; | ||||
| 
 | ||||
|         public BaseTakeSelfiePageModel(NotaryoDBContext notaryoDBContext, ICurrentUserService currentUserService, ICompreFaceClient compreFaceClient, IConfiguration configuration) | ||||
|         { | ||||
| @ -26,15 +28,22 @@ namespace EnotaryoPH.Web.Pages | ||||
|         protected async Task<bool> PostAsync() | ||||
|         { | ||||
|             var selfieImage = Convert.FromBase64String(SelfieBase64Image.Split(",")[1]) ?? []; | ||||
|             var identificationDocument = _notaryoDBContext.IdentificationDocuments.First(e => e.UserID == UserID); | ||||
|             var identificationDocument = _notaryoDBContext.IdentificationDocuments.First(e => e.UserID == CurrentUser.UserID); | ||||
|             var faceMatches = await VerifySelfieAsync(selfieImage, identificationDocument); | ||||
| 
 | ||||
|             var isMatchSuccess = faceMatches.Any(); | ||||
|             if (isMatchSuccess) | ||||
|             { | ||||
|                 var signatory = _notaryoDBContext.TransactionSignatories.First(x => x.UserID == UserID); | ||||
|                 signatory.Status = nameof(SignatoryStatus.FaceMatch); | ||||
|                 _notaryoDBContext.Update(signatory); | ||||
|                 var signatory = _notaryoDBContext.TransactionSignatories.FirstOrDefault(x => x.UserID == CurrentUser.UserID); | ||||
|                 if (signatory != null) | ||||
|                 { | ||||
|                     signatory.Status = nameof(SignatoryStatus.FaceMatch); | ||||
|                     _notaryoDBContext.Update(signatory); | ||||
|                 } | ||||
|                 else if (!_user.Role.IsInList(nameof(UserType.Principal), nameof(UserType.SuperUser), nameof(UserType.Administrator))) | ||||
|                 { | ||||
|                     return false; | ||||
|                 } | ||||
| 
 | ||||
|                 var selfieEntity = CreateOrUpdateSelfie(selfieImage); | ||||
|                 if (_notaryoDBContext.Entry(selfieEntity).State == EntityState.Detached) | ||||
| @ -50,32 +59,26 @@ namespace EnotaryoPH.Web.Pages | ||||
|             return isMatchSuccess; | ||||
|         } | ||||
| 
 | ||||
|         private Transaction _transactionEntity; | ||||
| 
 | ||||
|         private int TransactionID | ||||
|         private TransactionSelfie CreateOrUpdateSelfie(byte[] selfieImage) | ||||
|         { | ||||
|             get | ||||
|             TransactionSelfie selfieEntity; | ||||
|             if (TransactionSelfie_UID == Guid.Empty) | ||||
|             { | ||||
|                 if (_transactionEntity == null) | ||||
|                 selfieEntity = new TransactionSelfie | ||||
|                 { | ||||
|                     _transactionEntity = _notaryoDBContext.Transactions.AsNoTracking().First(x => x.Transaction_UID == Transaction_UID); | ||||
|                 } | ||||
|                 return _transactionEntity?.TransactionID ?? 0; | ||||
|                     CreatedOn = DateTime.UtcNow, | ||||
|                     TransactionSelfie_UID = Guid.CreateVersion7(DateTime.UtcNow), | ||||
|                     UserID = CurrentUser.UserID, | ||||
|                     TransactionID = TransactionID | ||||
|                 }; | ||||
|                 TransactionSelfie_UID = selfieEntity.TransactionSelfie_UID.Value; | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         private User _user; | ||||
| 
 | ||||
|         private int UserID | ||||
|         { | ||||
|             get | ||||
|             else | ||||
|             { | ||||
|                 if (_user == null) | ||||
|                 { | ||||
|                     _user = _notaryoDBContext.Users.AsNoTracking().First(x => x.User_UID == _currentUserService.GetUser_UID()); | ||||
|                 } | ||||
|                 return _user?.UserID ?? 0; | ||||
|                 selfieEntity = _notaryoDBContext.TransactionSelfies.FirstOrDefault(e => e.TransactionSelfie_UID == TransactionSelfie_UID); | ||||
|             } | ||||
|             selfieEntity.File = Convert.FromBase64String(SelfieBase64Image.Split(",")[1]); | ||||
|             return selfieEntity; | ||||
|         } | ||||
| 
 | ||||
|         private async Task<IEnumerable<FaceMatches>> VerifySelfieAsync(byte[] selfieImage, IdentificationDocument identificationDocument) | ||||
| @ -103,35 +106,37 @@ namespace EnotaryoPH.Web.Pages | ||||
|             return faceMatches; | ||||
|         } | ||||
| 
 | ||||
|         private TransactionSelfie CreateOrUpdateSelfie(byte[] selfieImage) | ||||
|         { | ||||
|             TransactionSelfie selfieEntity; | ||||
|             if (TransactionSelfie_UID == Guid.Empty) | ||||
|             { | ||||
|                 selfieEntity = new TransactionSelfie | ||||
|                 { | ||||
|                     CreatedOn = DateTime.UtcNow, | ||||
|                     TransactionSelfie_UID = Guid.CreateVersion7(DateTime.UtcNow), | ||||
|                     UserID = UserID, | ||||
|                     TransactionID = TransactionID | ||||
|                 }; | ||||
|                 TransactionSelfie_UID = selfieEntity.TransactionSelfie_UID.Value; | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 selfieEntity = _notaryoDBContext.TransactionSelfies.FirstOrDefault(e => e.TransactionSelfie_UID == TransactionSelfie_UID); | ||||
|             } | ||||
|             selfieEntity.File = Convert.FromBase64String(SelfieBase64Image.Split(",")[1]); | ||||
|             return selfieEntity; | ||||
|         } | ||||
| 
 | ||||
|         [BindProperty(SupportsGet = true)] | ||||
|         public Guid Transaction_UID { get; set; } | ||||
| 
 | ||||
|         [BindProperty] | ||||
|         public string SelfieBase64Image { get; set; } | ||||
| 
 | ||||
|         [BindProperty(SupportsGet = true)] | ||||
|         public Guid Transaction_UID { get; set; } | ||||
| 
 | ||||
|         [BindProperty(SupportsGet = true)] | ||||
|         public Guid TransactionSelfie_UID { get; set; } | ||||
| 
 | ||||
|         private User CurrentUser | ||||
|         { | ||||
|             get | ||||
|             { | ||||
|                 if (_user == null) | ||||
|                 { | ||||
|                     _user = _notaryoDBContext.Users.AsNoTracking().First(x => x.User_UID == _currentUserService.GetUser_UID()); | ||||
|                 } | ||||
|                 return _user ?? new(); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         private int TransactionID | ||||
|         { | ||||
|             get | ||||
|             { | ||||
|                 if (_transactionEntity == null) | ||||
|                 { | ||||
|                     _transactionEntity = _notaryoDBContext.Transactions.AsNoTracking().First(x => x.Transaction_UID == Transaction_UID); | ||||
|                 } | ||||
|                 return _transactionEntity?.TransactionID ?? 0; | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user