예제 #1
0
        public ActionResult ConfirmVote(int c_id, string e_id)
        {
            bool found;
            var  vin        = Session["vin"].ToString();
            var  checkvoted = db.CastVotes.Where(x => (x.electionCode == e_id && x.voterId == vin)).FirstOrDefault();

            if (checkvoted == null)
            {
                found = false;

                var con_name = db.Contestants.Where(x => x.contestant_id == c_id).Select(x => x.contestantName).FirstOrDefault();
                ViewBag.con_name = con_name;

                var incvotes = db.Contestants.Where(x => (x.contestant_id == c_id && x.electionCode == e_id)).FirstOrDefault();
                incvotes.totalVotes = incvotes.totalVotes + 1;


                CastVote cv = new CastVote();

                cv.electionCode = e_id;
                cv.voterId      = Session["vin"].ToString();
                cv.hasVotedTo   = c_id;

                db.CastVotes.Add(cv);
                db.SaveChanges();
            }
            else
            {
                found = true;
            }
            ViewBag.found = found;
            return(View());
        }
예제 #2
0
        public async Task <IActionResult> Get()
        {
            Uri serviceName  = VotingWeb.GetVotingDataServiceName(this.serviceContext);
            Uri proxyAddress = this.GetProxyAddress(serviceName);

            ServicePartitionList partitions = await this.fabricClient.QueryManager.GetPartitionListAsync(serviceName);

            List <KeyValuePair <string, int> > result = new List <KeyValuePair <string, int> >();

            foreach (Partition partition in partitions)
            {
                string proxyUrl =
                    $"{proxyAddress}/api/VoteData?PartitionKey={((Int64RangePartitionInformation)partition.PartitionInformation).LowKey}&PartitionKind=Int64Range";

                using (HttpResponseMessage response = await this.httpClient.GetAsync(proxyUrl))
                {
                    if (response.StatusCode != System.Net.HttpStatusCode.OK)
                    {
                        continue;
                    }

                    result.AddRange(JsonConvert.DeserializeObject <List <KeyValuePair <string, int> > >(await response.Content.ReadAsStringAsync()));
                }
            }

            var voteToCast = new CastVote();

            voteToCast.Name = "Hello, world";

            try
            {
                await endpointInstance.Send(voteToCast);
            }
            catch (Exception ex)
            {
                throw;
            }

            return(this.Json(result));
        }