/// <summary> /// Selects an election by election ID /// </summary> /// <param name="electionID"></param> /// <returns></returns> public ElectionVM SelectElectionByElectionID(int electionID) { ElectionVM election = new ElectionVM(); var conn = DBConnection.GetConnection(); var cmd = new SqlCommand("sp_select_election_by_election_id", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@ElectionID", electionID); try { conn.Open(); var reader = cmd.ExecuteReader(); if (reader.Read()) { election.ElectionID = reader.GetInt32(0); election.Name = reader.GetString(1); election.Description = reader.GetString(2); election.Active = reader.GetBoolean(3); } } catch (Exception ex) { throw ex; } finally { conn.Close(); } return(election); }
public ActionResult _ElectionDatePartial(ElectionVM model) { if (!ModelState.IsValid) { return(PartialView(model)); } // make sure dates are correct if (model.EndDate < model.StartDate) { return(Json(new { Status = 0, Message = "End date should be the future of the start date" })); } // get election var election = db.Election.FirstOrDefault(); // update end date election.StartDate = model.StartDate; election.EndDate = model.EndDate; // save db db.SaveChanges(); return(Json(new { Status = 1, Message = "Success" })); }
/// <summary> /// Selects a list of elections by active /// </summary> /// <param name="active"></param> /// <returns></returns> public List <ElectionVM> SelectElectionsByActive(bool active) { List <ElectionVM> elections = new List <ElectionVM>(); var conn = DBConnection.GetConnection(); var cmd = new SqlCommand("sp_select_elections_by_active", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@active", active); try { conn.Open(); var reader = cmd.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { var election = new ElectionVM(); election.ElectionID = reader.GetInt32(0); election.Name = reader.GetString(1); election.Description = reader.GetString(2); election.Active = reader.GetBoolean(3); elections.Add(election); } } } catch (Exception ex) { throw ex; } finally { conn.Close(); } return(elections); }