public int Add(PushkinoActionPost news) { var connectionString = this.GetConnection(); int count = 0; using (var con = new SqlConnection(connectionString)) { try { con.Open(); var query = "INSERT INTO PushkinoActionsPosts(Name, Intro, Text, Picture) VALUES(@Name, @Intro, @Text,@Picture);"; count = con.Execute(query, news); } catch (Exception ex) { throw ex; } finally { con.Close(); } return(count); } }
public int EditNews(PushkinoActionPost news) { var connectionString = this.GetConnection(); var count = 0; using (var con = new SqlConnection(connectionString)) { try { con.Open(); var query = "UPDATE PushkinoActionsPosts SET Name = @Name, Intro = @Intro, Text = @Text, Picture = @Picture WHERE Id = @Id"; count = con.Execute(query, news); } catch (Exception ex) { throw ex; } finally { con.Close(); } return(count); } }
public PushkinoActionPost GetNews(int id) { var connectionString = this.GetConnection(); PushkinoActionPost product = new PushkinoActionPost(); using (var con = new SqlConnection(connectionString)) { try { con.Open(); var query = "SELECT * FROM PushkinoActionsPosts WHERE Id =" + id; product = con.Query <PushkinoActionPost>(query).FirstOrDefault(); } catch { throw new Exception("Нет данного поста"); } finally { con.Close(); } return(product); } }