示例#1
0
        public async Task <IActionResult> GetOrderDetails([FromHeader(Name = "Grid-Authorization-Token")] string token, [FromRoute] int orderID)
        {
            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))
                            }));
                        }

                        CommonDataAccess commonData = new CommonDataAccess(_iconfiguration);

                        var orderList = await commonData.GetOrderDetails(orderID);

                        if (orderList == null || orderList.OrderID == 0)
                        {
                            return(Ok(new ServerResponse
                            {
                                HasSucceeded = false,
                                Message = EnumExtensions.GetDescription(DbReturnValue.NotExists)
                            }));
                        }
                        else
                        {
                            // DownloadFile


                            DatabaseResponse awsConfigResponse = await commonData.GetConfiguration(ConfiType.AWS.ToString());

                            if (awsConfigResponse != null && awsConfigResponse.ResponseCode == (int)DbReturnValue.RecordExists)
                            {
                                MiscHelper configHelper = new MiscHelper();

                                GridAWSS3Config awsConfig = configHelper.GetGridAwsConfig((List <Dictionary <string, string> >)awsConfigResponse.Results);

                                AmazonS3 s3Helper = new AmazonS3(awsConfig);


                                DownloadResponse FrontImageDownloadResponse = new DownloadResponse();

                                DownloadResponse BackImageDownloadResponse = new DownloadResponse();

                                if (!string.IsNullOrEmpty(orderList.DocumentURL))
                                {
                                    FrontImageDownloadResponse = await s3Helper.DownloadFile(orderList.DocumentURL.Remove(0, awsConfig.AWSEndPoint.Length));

                                    if (FrontImageDownloadResponse.HasSucceed)
                                    {
                                        orderList.FrontImage = FrontImageDownloadResponse.FileObject != null?configHelper.GetBase64StringFromByteArray(FrontImageDownloadResponse.FileObject, orderList.DocumentURL.Remove(0, awsConfig.AWSEndPoint.Length)) : null;

                                        orderList.DocumentURL = "";
                                    }
                                    else
                                    {
                                        orderList.DocumentURL = "";
                                        orderList.FrontImage  = "";
                                    }
                                }

                                if (!string.IsNullOrEmpty(orderList.DocumentBackURL))
                                {
                                    BackImageDownloadResponse = await s3Helper.DownloadFile(orderList.DocumentBackURL.Remove(0, awsConfig.AWSEndPoint.Length));

                                    if (BackImageDownloadResponse.HasSucceed)
                                    {
                                        orderList.BackImage = BackImageDownloadResponse.FileObject != null?configHelper.GetBase64StringFromByteArray(BackImageDownloadResponse.FileObject, orderList.DocumentBackURL.Remove(0, awsConfig.AWSEndPoint.Length)) : null;

                                        orderList.DocumentBackURL = "";
                                    }
                                    else
                                    {
                                        orderList.DocumentBackURL = "";
                                        orderList.BackImage       = "";
                                    }
                                }
                                return(Ok(new ServerResponse
                                {
                                    HasSucceeded = true,
                                    Message = StatusMessages.SuccessMessage,
                                    Result = orderList
                                }));
                            }
                            else
                            {
                                // unable to get aws config
                                LogInfo.Warning(EnumExtensions.GetDescription(CommonErrors.FailedToGetConfiguration));

                                return(Ok(new OperationResponse
                                {
                                    HasSucceeded = false,
                                    Message = EnumExtensions.GetDescription(CommonErrors.FailedToGetConfiguration)
                                }));
                            }
                        }
                    }
                    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
                }));
            }
        }