/// <summary> /// Get number the total click count /// </summary> /// <returns>Total count</returns> public ActionResult Index() { PressViewModel press = new PressViewModel(); try { press.count = method.Count(); } catch (Exception ex) { return(View("Error", new HandleErrorInfo(ex, "Index", "Index"))); } return(View(press)); }
/// <summary> /// Reads total clicked /// </summary> /// <returns>Total count</returns> public int Count() { PressViewModel press = new PressViewModel(); SqlConnection con = new SqlConnection(AppConnectionString()); //Validates if connectionstring was successfully read from app.config if (string.IsNullOrEmpty(con.ConnectionString)) { return(0); } try { using (con) { SqlCommand cmd = new SqlCommand("spGetClickCount", con); con.Open(); cmd.CommandType = CommandType.StoredProcedure; using (SqlDataReader dr = cmd.ExecuteReader()) { if (dr.HasRows) { while (dr.Read()) { press.count = Convert.ToInt32(dr["Counts"]); } } dr.Close(); dr.Dispose(); } } } catch (Exception ex) { throw new Exception(ex.Message); } finally { con.Close(); } return(press.count); }