public GenerateTokenResponse GenerateToken(GenerateTokenRequest request) { var response = new GenerateTokenResponse { IsSuccess = false }; try { if (request == null) throw new ArgumentNullException("request", "Request cannot be null"); if(string.IsNullOrEmpty(request.Email)) throw new ArgumentNullException("request.Email", "The email cannot be null"); if (request.Passengers <= 0) throw new ArgumentNullException("request.Passengers", "The number of passengers cannot be 0"); if (request.PayableAmount <= 0) throw new ArgumentNullException("request.PayableAmount", "The payable amount cannot be 0"); if (string.IsNullOrEmpty(request.Name)) throw new ArgumentNullException("request.Name", "The name cannot be null"); if (string.IsNullOrEmpty(request.Mobile)) throw new ArgumentNullException("request.Mobile", "The mobile cannot be null"); var tokenProvider = TokenProviderFactory.GetTokenProvider(); var tokenId = tokenProvider.GenerateToken(request.Email, request.Name, request.Mobile, request.Passengers, request.PayableAmount, request.RequestId); if (string.IsNullOrEmpty(tokenId) == false) { response.IsSuccess = true; response.ErrorMessage = string.Empty; response.TokenId = tokenId; } } catch (Exception ex) { Logger.LogException(ex, Source, "GenerateToken", Severity.Major); response.IsSuccess = false; response.ErrorMessage = ex.ToString(); } return response; }
public GenerateTokenResponse GenerateToken(GenerateTokenRequest request) { using (new ApplicationContextScope(new ApplicationContext())) { ApplicationContext.Current.Items["SessionId"] = request.SessionId; try { var channelFactory = new WebChannelFactory<ITokenServiceRest>(Configuration.TokenServiceConfigurationName); ITokenServiceRest channel = channelFactory.CreateChannel(); if (channel is IContextChannel) using (new OperationContextScope(channel as IContextChannel)) { WebOperationContext.Current.OutgoingRequest.Headers.Add("X-MethodName", "GenerateToken"); GenerateTokenResponse response = channel.GenerateToken(request); response.RequestId = request.RequestId; return response; } } catch (Exception exception) { Logger.LogException(exception, Source, "GenerateToken", Severity.Major); } } return null; }