public async Task <IActionResult> UpdateNRICIDDetails([FromHeader(Name = "Grid-General-Token")] string Token, [FromForm] UpdateOrderPersonalIDDetailsPublicRequest request) { try { if (!ModelState.IsValid) { return(Ok(new OperationResponse { HasSucceeded = false, IsDomainValidationErrors = true, Message = string.Join("; ", ModelState.Values .SelectMany(x => x.Errors) .Select(x => x.ErrorMessage)) })); } TokenValidationHelper tokenValidationHelper = new TokenValidationHelper(); if (!tokenValidationHelper.ValidateGenericToken(Token, _iconfiguration)) { return(Ok(new OperationResponse { HasSucceeded = false, Message = Core.Extensions.EnumExtensions.GetDescription(DbReturnValue.TokenAuthFailed), IsDomainValidationErrors = true })); } CommonDataAccess commonDataAccess = new CommonDataAccess(_iconfiguration); var tokenResult = await commonDataAccess.ValidateVerificationToken(request.RequestToken); if (tokenResult.ResponseCode != (int)DbReturnValue.RecordExists) { return(Ok(new OperationResponse { HasSucceeded = false, Message = EnumExtensions.GetDescription(DbReturnValue.RequestTokenExpired), IsDomainValidationErrors = false })); } AccountDataAccess _AccountAccess = new AccountDataAccess(_iconfiguration); CommonDataAccess _commonDataAccess = new CommonDataAccess(_iconfiguration); DatabaseResponse customerResponse = await _commonDataAccess.GetCustomerIdFromOrderId(request.OrderID); if (customerResponse.ResponseCode == (int)DbReturnValue.RecordExists) { IFormFile frontImage = request.IDImageFront; IFormFile backImage = request.IDImageBack; BSSAPIHelper bsshelper = new BSSAPIHelper(); MiscHelper configHelper = new MiscHelper(); OrderDetails customerOrderDetails = await _commonDataAccess.GetOrderDetails(request.OrderID); NRICDetailsRequest personalDetails = new NRICDetailsRequest { OrderID = request.OrderID, IdentityCardNumber = customerOrderDetails.IdentityCardNumber, IdentityCardType = customerOrderDetails.IdentityCardType, Nationality = customerOrderDetails.Nationality, NameInNRIC = customerOrderDetails.Name, DOB = customerOrderDetails.DOB, Expiry = customerOrderDetails.ExpiryDate, }; //process file if uploaded - non null if (frontImage != null && backImage != null) { DatabaseResponse awsConfigResponse = await _commonDataAccess.GetConfiguration(ConfiType.AWS.ToString()); if (awsConfigResponse != null && awsConfigResponse.ResponseCode == (int)DbReturnValue.RecordExists) { GridAWSS3Config awsConfig = configHelper.GetGridAwsConfig((List <Dictionary <string, string> >)awsConfigResponse.Results); AmazonS3 s3Helper = new AmazonS3(awsConfig); string fileNameFront = customerOrderDetails.IdentityCardNumber.Substring(1, customerOrderDetails.IdentityCardNumber.Length - 2) + "_Front_" + DateTime.Now.ToString("yyMMddhhmmss") + Path.GetExtension(frontImage.FileName); //Grid_IDNUMBER_yyyymmddhhmmss.extension UploadResponse s3UploadResponse = await s3Helper.UploadFile(frontImage, fileNameFront); if (s3UploadResponse.HasSucceed) { personalDetails.FrontImage = awsConfig.AWSEndPoint + s3UploadResponse.FileName; } else { LogInfo.Warning(EnumExtensions.GetDescription(CommonErrors.S3UploadFailed)); } string fileNameBack = customerOrderDetails.IdentityCardNumber.Substring(1, customerOrderDetails.IdentityCardNumber.Length - 2) + "_Back_" + DateTime.Now.ToString("yyMMddhhmmss") + Path.GetExtension(frontImage.FileName); //Grid_IDNUMBER_yyyymmddhhmmss.extension s3UploadResponse = await s3Helper.UploadFile(backImage, fileNameBack); if (s3UploadResponse.HasSucceed) { personalDetails.BackImage = awsConfig.AWSEndPoint + s3UploadResponse.FileName; } else { LogInfo.Warning(EnumExtensions.GetDescription(CommonErrors.S3UploadFailed)); } } else { // unable to get aws config LogInfo.Warning(EnumExtensions.GetDescription(CommonErrors.FailedToGetConfiguration)); } } //file //update ID ReUpload details DatabaseResponse updateNRICResponse = await _commonDataAccess.UpdateNRICDetails(null, 0, personalDetails); if (updateNRICResponse.ResponseCode == (int)DbReturnValue.UpdateSuccess) { DatabaseResponse updateTokenStatus = await _commonDataAccess.UpdateTokenForVerificationRequests(request.OrderID); // EmailResponse emailResponse = (EmailResponse)updateNRICResponse.Results; // string emailStatus= await SendAdminEmailNotificationOnIDReUpload(emailResponse.Email, emailResponse.OrderNumber); return(Ok(new OperationResponse { HasSucceeded = true, Message = EnumExtensions.GetDescription(DbReturnValue.UpdateSuccess), IsDomainValidationErrors = false })); } else if (updateNRICResponse.ResponseCode == (int)DbReturnValue.UpdateSuccessSendEmail) { DatabaseResponse updateTokenStatus = await _commonDataAccess.UpdateTokenForVerificationRequests(request.OrderID); // EmailResponse emailResponse = (EmailResponse)updateNRICResponse.Results; // string emailStatus = await SendAdminEmailNotificationOnIDReUpload(emailResponse.Email, emailResponse.OrderNumber); // LogInfo.Warning(EnumExtensions.GetDescription(DbReturnValue.UpdateSuccessSendEmail) + "for " + request.OrderID + "Order"); return(Ok(new OperationResponse { HasSucceeded = true, Message = EnumExtensions.GetDescription(DbReturnValue.UpdateSuccessSendEmail), IsDomainValidationErrors = false })); } else if (updateNRICResponse.ResponseCode == (int)DbReturnValue.NotExists) { LogInfo.Warning(EnumExtensions.GetDescription(DbReturnValue.NotExists) + " " + EnumExtensions.GetDescription(CommonErrors.ImageAlreadyUploaded) + " Order" + request.OrderID); return(Ok(new OperationResponse { HasSucceeded = false, Message = EnumExtensions.GetDescription(CommonErrors.ImageAlreadyUploaded), IsDomainValidationErrors = false })); } else { LogInfo.Warning(EnumExtensions.GetDescription(DbReturnValue.UpdationFailed)); return(Ok(new OperationResponse { HasSucceeded = false, Message = EnumExtensions.GetDescription(DbReturnValue.UpdationFailed), IsDomainValidationErrors = false })); } } else { // failed to locate customer LogInfo.Warning(EnumExtensions.GetDescription(CommonErrors.FailedToGetCustomer)); return(Ok(new OperationResponse { HasSucceeded = false, Message = EnumExtensions.GetDescription(CommonErrors.FailedToGetCustomer), IsDomainValidationErrors = false })); } } catch (Exception ex) { LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical)); return(Ok(new OperationResponse { HasSucceeded = false, Message = StatusMessages.ServerError, IsDomainValidationErrors = false })); } }