Example #1
0
        public static bool Validate(TransitCodeRequest request)
        {
            var validationResult = true;

            if (string.IsNullOrEmpty(request.ClientInformation.ClientId))
            {
                ThrowException(FaultCodes.MandatoryFieldMissing, string.Format(FaultMessages.MandatoryFieldMissing, "ClientId"));
            }

            if (string.IsNullOrEmpty(request.ClientInformation.ProgramId))
            {
                ThrowException(FaultCodes.MandatoryFieldMissing, string.Format(FaultMessages.MandatoryFieldMissing, "ProgramId"));
            }

            if (string.IsNullOrEmpty(request.ClientInformation.ProgramCode))
            {
                ThrowException(FaultCodes.MandatoryFieldMissing, string.Format(FaultMessages.MandatoryFieldMissing, "ProgramCode"));
            }

            return(validationResult);
        }
        public async Task <TransitCodeResponse> GenerateTransitCode(TransitCodeRequest transitCodeRequest, string url)
        {
            TransitCodeRequestValidator.Validate(transitCodeRequest);
            HttpResponse webResponse = null;
            var          webrequest  = await new WebCaller().GetWebRequest(new { transitCodeRequest }, url);

            try
            {
                webResponse = await webrequest.SendAsync();
            }
            catch (Exception ex)
            {
                return(new TransitCodeResponse
                {
                    Status = "failed",
                    Message = ex.Message
                });
            }

            var response = await webResponse.GetResponseAsync <TransitCodeResponse>();

            return(response);
        }