public async Task AddVote(string blind_test_id, string user_id, string vote) { if (int.TryParse(blind_test_id, out int bt_id) && int.TryParse(user_id, out int u_id) && int.TryParse(vote, out int vt)) { Participant participant = await PollController.Instance.GetUserById(bt_id, u_id, Context.ConnectionId); if (participant != null) { RegVoteReply reply = await PollController.Instance.AddVote(bt_id, u_id, vt); if (reply == null) { await Clients.Caller.voteAddVoteResult(new { BlindTestId = bt_id, ParticipantId = u_id, Result = "Klarte ikke å aksessere databasen!" }); } else { // Ok - vi har fått tilbake en status fra databasen // Skal vi informere andre om stemmen? if (reply.InformOthers) { // This call is implemented in the dashboard in order to update the the users summary in current round // We will not send to vote since it's secret. The vote is stored in the back-end until the round is completed await Clients.Others.voteAdded(new { reply.BlindTestId, reply.ParticipantId, ParticipantName = participant.Name, reply.ImageIndex, reply.UserVoteDeleted }); } // Give the caller a feedback on the vote await Clients.Caller.voteAddVoteResult(new { BlindTestId = bt_id, ParticipantId = u_id, reply.Result }); } } } }
public async Task <RegVoteReply> AddVote(int blind_test_id, int participant_id, int vote) { RegVoteReply reply = null; try { using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(Help.Helper.CnnVal("syse_db"))) { var ret = await connection.QueryAsync <RegVoteReply>("dbo.spAddVote" , new { BlindTestId = blind_test_id, ParticipantId = participant_id, Vote = vote } , null, null, CommandType.StoredProcedure); if (ret.Count() > 0) { reply = ret.FirstOrDefault(); } } } catch { } return(reply); }