/// <summary> /// inserts a completed vote into the database /// </summary> /// <param name="completedVote"></param> /// <returns></returns> public int InsertCompletedVote(CompletedVote completedVote) { int CompletedVoteID = 0; var conn = DBConnection.GetConnection(); var cmd = new SqlCommand("sp_insert_completed_vote", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@PersonID", completedVote.PersonID); cmd.Parameters.AddWithValue("@ElectionID", completedVote.ElectionID); try { conn.Open(); CompletedVoteID = Convert.ToInt32(cmd.ExecuteScalar()); } catch (Exception ex) { throw ex; } finally { conn.Close(); } return(CompletedVoteID); }
/// <summary> /// updates completed vote /// </summary> /// <param name="oldCompletedVote"></param> /// <param name="newCompletedVote"></param> /// <returns></returns> public int UdateCompletedVote(CompletedVote oldCompletedVote, CompletedVote newCompletedVote) { int rows = 0; var conn = DBConnection.GetConnection(); var cmd = new SqlCommand("sp_update_completed_vote", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@CompletedVoteID", oldCompletedVote.ElectionID); cmd.Parameters.AddWithValue("@OldPersonID", oldCompletedVote.PersonID); cmd.Parameters.AddWithValue("@OldElectionID", oldCompletedVote.ElectionID); cmd.Parameters.AddWithValue("@OldHasVoted", oldCompletedVote.HasVoted); cmd.Parameters.AddWithValue("@NewPersonID", newCompletedVote.PersonID); cmd.Parameters.AddWithValue("@NewElectionID", newCompletedVote.ElectionID); cmd.Parameters.AddWithValue("@NewHasVoted", newCompletedVote.HasVoted); try { conn.Open(); rows = cmd.ExecuteNonQuery(); } catch (Exception ex) { throw ex; } finally { conn.Close(); } return(rows); }
/// <summary> /// adds a completed vote /// </summary> /// <param name="completedVote"></param> /// <returns></returns> public int AddCompletedVote(CompletedVote completedVote) { int result; try { result = _completedVoteAccessor.InsertCompletedVote(completedVote); } catch (Exception ex) { throw new ApplicationException("Completed Vote not Added", ex); } return(result); }
/// <summary> /// edits a completed vote /// </summary> /// <param name="oldCompletedVote"></param> /// <param name="newCompletedVote"></param> /// <returns></returns> public bool EditCompletedVote(CompletedVote oldCompletedVote, CompletedVote newCompletedVote) { bool result; try { result = 1 == _completedVoteAccessor.UdateCompletedVote(oldCompletedVote, newCompletedVote); } catch (Exception ex) { throw new ApplicationException("Candidate not Edited", ex); } return(result); }