Ejemplo n.º 1
0
        public IActionResult NRICTypeValidation([FromHeader(Name = "Grid-General-Token")] string Token, [FromBody] NRIC IDDetails)
        {
            string _warningmsg = "";

            try
            {
                TokenValidationHelper tokenValidationHelper = new TokenValidationHelper();
                if (!tokenValidationHelper.ValidateGenericToken(Token, _iconfiguration))
                {
                    return(Ok(new OperationResponse
                    {
                        HasSucceeded = false,
                        Message = Core.Extensions.EnumExtensions.GetDescription(DbReturnValue.TokenAuthFailed),
                        IsDomainValidationErrors = true
                    }));
                }

                EmailValidationHelper _helper = new EmailValidationHelper();
                if (_helper.NRICValidation(IDDetails.IDType, IDDetails.IDNumber, out _warningmsg))
                {
                    return(Ok(new ServerResponse
                    {
                        HasSucceeded = true,
                        Message = StatusMessages.ValidMessage
                    }));
                }
                else
                {
                    LogInfo.Warning("NRIC Validation: " + IDDetails.IDType + "_" + _warningmsg);
                    return(Ok(new OperationResponse
                    {
                        HasSucceeded = false,
                        Message = StatusMessages.InvalidMessage,
                        IsDomainValidationErrors = false
                    }));
                }
            }

            catch (Exception ex)
            {
                LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical));

                return(Ok(new OperationResponse
                {
                    HasSucceeded = false,
                    Message = (_warningmsg == "" ? StatusMessages.ServerError : StatusMessages.InvalidMessage),
                    IsDomainValidationErrors = false
                }));
            }
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> UpdateNRICDetails([FromHeader(Name = "Grid-Authorization-Token")] string token, [FromForm] NRICDetails request)
        {
            try
            {
                if (string.IsNullOrEmpty(token))
                {
                    return(Ok(new OperationResponse
                    {
                        HasSucceeded = false,
                        IsDomainValidationErrors = true,
                        Message = EnumExtensions.GetDescription(CommonErrors.TokenEmpty)
                    }));
                }
                AdminUsersDataAccess _adminUsersDataAccess = new AdminUsersDataAccess(_iconfiguration);

                DatabaseResponse tokenAuthResponse = await _adminUsersDataAccess.AuthenticateAdminUserToken(token);

                if (tokenAuthResponse.ResponseCode == (int)DbReturnValue.AuthSuccess)
                {
                    if (!((AuthTokenResponse)tokenAuthResponse.Results).IsExpired)
                    {
                        if (!ModelState.IsValid)
                        {
                            return(StatusCode((int)HttpStatusCode.OK,
                                              new OperationResponse
                            {
                                HasSucceeded = false,
                                IsDomainValidationErrors = true,
                                Message = string.Join("; ", ModelState.Values
                                                      .SelectMany(x => x.Errors)
                                                      .Select(x => x.ErrorMessage))
                            }));
                        }

                        if (!string.IsNullOrEmpty(request.IdentityCardNumber))
                        {
                            EmailValidationHelper _helper = new EmailValidationHelper();
                            if (!_helper.NRICValidation(null, request.IdentityCardNumber, out string _warningmsg))
                            {
                                LogInfo.Warning("NRIC Validation with type: " + _warningmsg);
                                return(Ok(new OperationResponse
                                {
                                    HasSucceeded = false,
                                    Message = "Document details are invalid",
                                    IsDomainValidationErrors = false
                                }));
                            }
                        }

                        int deliveryStatusNumber = request.IDVerificationStatus;

                        var              authToken         = (AuthTokenResponse)tokenAuthResponse.Results;
                        MiscHelper       configHelper      = new MiscHelper();
                        CommonDataAccess _commonDataAccess = new CommonDataAccess(_iconfiguration);

                        NRICDetailsRequest personalDetails = new NRICDetailsRequest
                        {
                            OrderID            = request.OrderID,
                            IdentityCardNumber = request.IdentityCardNumber,
                            IdentityCardType   = request.IdentityCardType,
                            Nationality        = request.Nationality,
                            NameInNRIC         = request.NameInNRIC,
                            DOB     = request.DOB,
                            Expiry  = request.Expiry,
                            Remarks = request.Remarks,
                            IDVerificationStatus = request.IDVerificationStatus,
                        };

                        if (request.FrontImage != null || request.BackImage != null)
                        {
                            string IDCardNumberForImage = string.Empty;

                            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);
                                // Check for IdentityCardNumber
                                //Start
                                if (string.IsNullOrEmpty(request.IdentityCardNumber))
                                {
                                    var orderDetailsForIDCard = await _commonDataAccess.GetOrderDetails(request.OrderID);

                                    IDCardNumberForImage = orderDetailsForIDCard.IdentityCardNumber;
                                }
                                else
                                {
                                    IDCardNumberForImage = request.IdentityCardNumber;
                                }
                                //End
                                AmazonS3 s3Helper = new AmazonS3(awsConfig);
                                if (request.FrontImage != null)
                                {
                                    string fileNameFront = IDCardNumberForImage.Substring(1, IDCardNumberForImage.Length - 2) +
                                                           "_Front_" + DateTime.Now.ToString("yyMMddhhmmss") + Path.GetExtension(request.FrontImage.FileName); //Grid_IDNUMBER_yyyymmddhhmmss.extension

                                    UploadResponse s3UploadResponse = await s3Helper.UploadFile(request.FrontImage, fileNameFront);

                                    if (s3UploadResponse.HasSucceed)
                                    {
                                        personalDetails.FrontImage = awsConfig.AWSEndPoint + s3UploadResponse.FileName;
                                    }
                                    else
                                    {
                                        LogInfo.Warning(EnumExtensions.GetDescription(CommonErrors.S3UploadFailed));
                                    }
                                }
                                if (request.BackImage != null)
                                {
                                    string fileNameBack = IDCardNumberForImage.Substring(1, IDCardNumberForImage.Length - 2) + "_Back_" + DateTime.Now.ToString("yyMMddhhmmss")
                                                          + Path.GetExtension(request.BackImage.FileName); //Grid_IDNUMBER_yyyymmddhhmmss.extension

                                    UploadResponse s3UploadResponse = await s3Helper.UploadFile(request.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));
                            }
                        }

                        var returnResponse = await _commonDataAccess.UpdateNRICDetails(authToken.CustomerID, deliveryStatusNumber, personalDetails);

                        if (returnResponse.ResponseCode == (int)DbReturnValue.UpdateSuccessSendEmail)
                        {
                            var emailDetails = (EmailResponse)returnResponse.Results;
                            DatabaseResponse configResponse        = new DatabaseResponse();
                            DatabaseResponse tokenCreationResponse = new DatabaseResponse();

                            string finalURL = string.Empty;
                            // Fetch the URL
                            if (emailDetails.VerificationStatus == 2) // Rejected then token
                            {
                                configResponse        = ConfigHelper.GetValueByKey(ConfigKeys.NRICReUploadLink.GetDescription(), _iconfiguration);
                                tokenCreationResponse = await _adminOrderDataAccess.CreateTokenForVerificationRequests(request.OrderID);

                                var tokenCreation = (VerificationRequestResponse)tokenCreationResponse.Results;
                                finalURL = configResponse.Results.ToString() + tokenCreation.RequestToken;
                            }
                            else
                            {
                                var result = await _commonDataAccess.UpdateTokenForVerificationRequests(request.OrderID);
                            }

                            //Sending message start
                            // Send email to customer email                            ConfigDataAccess _configAccess = new ConfigDataAccess(_iconfiguration);
                            DatabaseResponse registrationResponse = await _adminOrderDataAccess.GetEmailNotificationTemplate(emailDetails.VerificationStatus == 2?NotificationEvent.ICValidationReject.GetDescription() : NotificationEvent.ICValidationChange.GetDescription());

                            string[] changelog = emailDetails.ChangeLog.Split(";");
                            string   finallog  = "";
                            foreach (string log in changelog)
                            {
                                if (!string.IsNullOrWhiteSpace(log))
                                {
                                    finallog = finallog + "&bull; " + log.Trim() + "<br/>";
                                }
                            }
                            var notificationMessage = MessageHelper.GetMessage(emailDetails.Email, emailDetails.Name, emailDetails.VerificationStatus == 2 ? NotificationEvent.ICValidationReject.GetDescription() : NotificationEvent.ICValidationChange.GetDescription(),
                                                                               ((EmailTemplate)registrationResponse.Results).TemplateName,
                                                                               _iconfiguration, string.IsNullOrWhiteSpace(finalURL) ? "-" : finalURL, string.IsNullOrWhiteSpace(emailDetails.Remark) ? "-" : emailDetails.Remark.Replace(";", "<br />"), string.IsNullOrWhiteSpace(emailDetails.ChangeLog) ? "-" : finallog);
                            var notificationResponse = await _adminOrderDataAccess.GetConfiguration(ConfiType.Notification.ToString());


                            MiscHelper parser             = new MiscHelper();
                            var        notificationConfig = parser.GetNotificationConfig((List <Dictionary <string, string> >)notificationResponse.Results);

                            Publisher customerNotificationPublisher = new Publisher(_iconfiguration, notificationConfig.SNSTopic);
                            await customerNotificationPublisher.PublishAsync(notificationMessage);

                            try
                            {
                                DatabaseResponse notificationLogResponse = await _adminOrderDataAccess.CreateEMailNotificationLogForDevPurpose(
                                    new NotificationLogForDevPurpose
                                {
                                    EventType = NotificationEvent.OrderSuccess.ToString(),
                                    Message   = JsonConvert.SerializeObject(notificationMessage)
                                });
                            }
                            catch (Exception ex)
                            {
                                LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical));
                            }
                            //Sending message Stop
                            return(Ok(new ServerResponse
                            {
                                HasSucceeded = true,
                                Message = StatusMessages.SuccessMessage,
                                Result = null
                            }));
                        }
                        else if (returnResponse.ResponseCode == (int)DbReturnValue.UpdateSuccess)
                        {
                            var emailDetails = (EmailResponse)returnResponse.Results;
                            DatabaseResponse configResponse        = new DatabaseResponse();
                            DatabaseResponse tokenCreationResponse = new DatabaseResponse();
                            string           finalURL = string.Empty;
                            if (emailDetails.VerificationStatus == 2) // Rejected then token
                            {
                                configResponse        = ConfigHelper.GetValueByKey(ConfigKeys.NRICReUploadLink.GetDescription(), _iconfiguration);
                                tokenCreationResponse = await _adminOrderDataAccess.CreateTokenForVerificationRequests(request.OrderID);

                                var tokenCreation = (VerificationRequestResponse)tokenCreationResponse.Results;
                                finalURL = configResponse.Results.ToString() + tokenCreation.RequestToken;

                                DatabaseResponse registrationResponse = await _adminOrderDataAccess.GetEmailNotificationTemplate(NotificationEvent.ICValidationReject.GetDescription());

                                var notificationMessage = MessageHelper.GetMessage(emailDetails.Email, emailDetails.Name, NotificationEvent.ICValidationReject.GetDescription(),
                                                                                   ((EmailTemplate)registrationResponse.Results).TemplateName,
                                                                                   _iconfiguration, string.IsNullOrWhiteSpace(finalURL) ? "-" : finalURL, string.IsNullOrWhiteSpace(emailDetails.Remark) ? "-" : emailDetails.Remark.Replace(";", "<br />"), string.IsNullOrWhiteSpace(emailDetails.ChangeLog) ? "-" : emailDetails.ChangeLog);
                                var notificationResponse = await _adminOrderDataAccess.GetConfiguration(ConfiType.Notification.ToString());


                                MiscHelper parser             = new MiscHelper();
                                var        notificationConfig = parser.GetNotificationConfig((List <Dictionary <string, string> >)notificationResponse.Results);

                                Publisher customerNotificationPublisher = new Publisher(_iconfiguration, notificationConfig.SNSTopic);
                                await customerNotificationPublisher.PublishAsync(notificationMessage);

                                try
                                {
                                    DatabaseResponse notificationLogResponse = await _adminOrderDataAccess.CreateEMailNotificationLogForDevPurpose(
                                        new NotificationLogForDevPurpose
                                    {
                                        EventType = NotificationEvent.OrderSuccess.ToString(),
                                        Message   = JsonConvert.SerializeObject(notificationMessage)
                                    });
                                }
                                catch (Exception ex)
                                {
                                    LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical));
                                }
                            }
                            else
                            {
                                var result = await _commonDataAccess.UpdateTokenForVerificationRequests(request.OrderID);
                            }

                            //Sending message start
                            // Send email to customer email                            ConfigDataAccess _configAccess = new ConfigDataAccess(_iconfiguration);


                            return(Ok(new ServerResponse
                            {
                                HasSucceeded = true,
                                Message = StatusMessages.SuccessMessage,
                                Result = null
                            }));
                        }
                        else
                        {
                            LogInfo.Error("UpdateNRICDetails failed for " + request.OrderID + " Order Id " + DbReturnValue.UpdationFailed);
                            return(Ok(new OperationResponse
                            {
                                HasSucceeded = false,
                                Message = EnumExtensions.GetDescription(DbReturnValue.UpdationFailed),
                                IsDomainValidationErrors = false
                            }));
                        }
                    }
                    else
                    {
                        //Token expired

                        LogInfo.Warning(EnumExtensions.GetDescription(CommonErrors.ExpiredToken));

                        return(Ok(new OperationResponse
                        {
                            HasSucceeded = false,
                            Message = EnumExtensions.GetDescription(DbReturnValue.TokenExpired),
                            IsDomainValidationErrors = true
                        }));
                    }
                }

                else
                {
                    // token auth failure
                    LogInfo.Warning(EnumExtensions.GetDescription(DbReturnValue.TokenAuthFailed));

                    return(Ok(new OperationResponse
                    {
                        HasSucceeded = false,
                        Message = EnumExtensions.GetDescription(DbReturnValue.TokenAuthFailed),
                        IsDomainValidationErrors = false
                    }));
                }
            }
            catch (Exception ex)
            {
                LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical));

                return(Ok(new OperationResponse
                {
                    HasSucceeded = false,
                    Message = StatusMessages.ServerError,
                    IsDomainValidationErrors = false
                }));
            }
        }