コード例 #1
0
ファイル: VotesController.cs プロジェクト: crazy4code72/mtdn
        public async Task <IActionResult> CastVote([FromBody] UserDetails userDetails)
        {
            try
            {
                IActionResult validationResult = Validator.ValidateCastVoteData(userDetails);
                if (validationResult != null)
                {
                    return(validationResult);
                }

                Uri    serviceName  = VotingWeb.GetVotingDataServiceName(serviceContext);
                Uri    proxyAddress = GetProxyAddress(serviceName);
                int    partitionKey = userDetails.AadharNo.Sum(c => (int)char.GetNumericValue(c));
                string proxyUrl     = $"{proxyAddress}/api/VoteData/CastVote?PartitionKey={partitionKey}&PartitionKind=Int64Range";

                StringContent postContent = new StringContent($"{{ 'AadharNo' : '{userDetails.AadharNo}', 'VoterId' : '{userDetails.VoterId}', 'VoteFor' : '{userDetails.VoteFor}', 'Otp' : '{userDetails.Otp}' }}", Encoding.UTF8, "application/json");
                postContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                using (HttpResponseMessage response = await httpClient.PostAsync(proxyUrl, postContent))
                {
                    return(ActionResultCreator.CreateCastVoteActionResult(response));
                }
            }
            catch (Exception)
            {
                return(new ContentResult
                {
                    StatusCode = (int)Enums.ResponseMessageCode.Success,
                    Content = Enums.CastVoteStatus.VotingFailed.ToString()
                });
            }
        }
コード例 #2
0
ファイル: VotesController.cs プロジェクト: crazy4code72/mtdn
        public async Task <IActionResult> VerifyOtp(string aadharNo, string userEnteredOtp)
        {
            try
            {
                IActionResult validationResult = Validator.ValidateVerifyOtpData(aadharNo, userEnteredOtp);
                if (validationResult != null)
                {
                    return(validationResult);
                }

                Uri    serviceName  = VotingWeb.GetVotingDataServiceName(serviceContext);
                Uri    proxyAddress = GetProxyAddress(serviceName);
                int    partitionKey = aadharNo.Sum(c => (int)char.GetNumericValue(c));
                string proxyUrl     = $"{proxyAddress}/api/VoteData/VerifyOtp/{aadharNo}/{userEnteredOtp}?PartitionKey={partitionKey}&PartitionKind=Int64Range";

                StringContent postContent = new StringContent($"{{ 'aadharNo' : '{aadharNo}', 'userEnteredOtp' : '{userEnteredOtp}' }}", Encoding.UTF8, "application/json");
                postContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");

                using (HttpResponseMessage response = await httpClient.PostAsync(proxyUrl, postContent))
                {
                    return(ActionResultCreator.CreateActionResult(response));
                }
            }
            catch (Exception)
            {
                return(new ContentResult
                {
                    StatusCode = (int)Enums.ResponseMessageCode.Success,
                    Content = Enums.ResponseMessageCode.Failure.ToString()
                });
            }
        }