public static List <Model.Post> getPost(string idPost) { string cs = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString; SqlConnection conn = null; SqlDataReader reader = null; try { conn = new SqlConnection(cs); SqlCommand com = new SqlCommand("DetaljnijePost", conn); com.CommandType = CommandType.StoredProcedure; com.Parameters.AddWithValue("@idPost", idPost); conn.Open(); reader = com.ExecuteReader(); List <Model.Post> postovi = new List <Model.Post>(); while (reader.Read()) { Model.Post post = new Model.Post(); post.Naslov = reader["Naslov"].ToString(); post.idAutor = Int32.Parse(reader["idAutor"].ToString()); post.Datum = DateTime.Parse(reader["Datum"].ToString()); post.KorisničkoIme = reader["KorisničkoIme"].ToString(); post.SlikaAutora = reader["SlikaAutora"].ToString(); post.TekstOAutoru = reader["TekstOAutoru"].ToString(); post.WebSite = reader["WebSite"].ToString(); post.LinkedIn = reader["LinkedIn"].ToString(); post.Facebook = reader["Facebook"].ToString(); post.Twitter = reader["Twitter"].ToString(); post.Podnaslov = reader["Podnaslov"].ToString(); post.Teskt = reader["Tekst"].ToString(); postovi.Add(post); } return(postovi); } catch (Exception exp) { HttpContext.Current.Trace.Warn("Greška", "Greška getPost(string idPost)", exp); } finally { if (reader != null) { reader.Close(); } if (conn != null && conn.State != ConnectionState.Closed) { conn.Close(); } } return(null); }
public static List <Model.Post> getPosts(string upit, string parametar) { string cs = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString; SqlConnection conn = null; SqlDataReader reader = null; try { conn = new SqlConnection(cs); SqlCommand com = new SqlCommand(upit, conn); com.CommandType = CommandType.StoredProcedure; com.Parameters.AddWithValue("@kr", parametar); conn.Open(); reader = com.ExecuteReader(); List <Model.Post> postovi = new List <Model.Post>(); while (reader.Read()) { Model.Post post = new Model.Post(); post.idPost = Int32.Parse(reader["idPost"].ToString()); post.Naslov = reader["Naslov"].ToString(); post.Slika = reader["Slika"].ToString(); post.OpisSlike = reader["OpisSlike"].ToString(); post.idAutor = Int32.Parse(reader["idAutor"].ToString()); post.Datum = DateTime.Parse(reader["Datum"].ToString()); post.OpisPosta = reader["OpisPosta"].ToString(); post.KorisničkoIme = reader["KorisničkoIme"].ToString(); postovi.Add(post); } return(postovi); } catch (Exception exp) { HttpContext.Current.Trace.Warn("Greška", "Greška getPosts(string upit, string parametar)", exp); } finally { if (reader != null) { reader.Close(); } if (conn != null && conn.State != ConnectionState.Closed) { conn.Close(); } } return(null); }
public static List <Model.Post> getPosts(string nazivKategorije) { string cs = ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString; SqlConnection conn = null; SqlDataReader reader = null; try { conn = new SqlConnection(cs); SqlCommand com = new SqlCommand("WSPost", conn); com.CommandType = CommandType.StoredProcedure; com.Parameters.AddWithValue("@Naziv", nazivKategorije); conn.Open(); reader = com.ExecuteReader(); List <Model.Post> postovi = new List <Model.Post>(); while (reader.Read()) { Model.Post post = new Model.Post(); post.Naslov = reader["Naslov"].ToString(); post.LinkKaPostu = "http://localhost:51136/ProbaZaTem157/detaljnije.aspx?post=" + reader["idPost"].ToString(); postovi.Add(post); } return(postovi); } catch (Exception exp) { HttpContext.Current.Trace.Warn("Greška", "Greška getPosts(nazivKategorije)", exp); } finally { if (reader != null) { reader.Close(); } if (conn != null && conn.State != ConnectionState.Closed) { conn.Close(); } } return(null); }
public static Model.Post getPostAutor(string ime) { string cs = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString; SqlConnection conn = null; SqlDataReader reader = null; try { conn = new SqlConnection(cs); SqlCommand com = new SqlCommand("AutorPostovi", conn); com.CommandType = CommandType.StoredProcedure; com.Parameters.AddWithValue("@ime", ime); conn.Open(); reader = com.ExecuteReader(); reader.Read(); Model.Post post = new Model.Post(); post.idAutor = Int32.Parse(reader["idAutor"].ToString()); return(post); } catch (Exception exp) { HttpContext.Current.Trace.Warn("Greška", "Greška getPostAutor(string ime)", exp); } finally { if (reader != null) { reader.Close(); } if (conn != null && conn.State != ConnectionState.Closed) { conn.Close(); } } return(null); }