Example #1
0
 public bool Save(INewsItemDTO dto)
 {
     try
     {
         using (MySqlConnection conn = new MySqlConnection(_connection))
         {
             conn.Open();
             using (MySqlCommand cmd = new MySqlCommand("INSERT INTO newsitem (Title, Description,Date) VALUES(@Title, @Description,@Date)", conn))
             {
                 cmd.Parameters.AddWithValue("@Title", dto.Title);
                 cmd.Parameters.AddWithValue("@Description", dto.Description);
                 cmd.Parameters.AddWithValue("@Date", dto.PostDate);
                 if (cmd.ExecuteNonQuery() > 0)
                 {
                     return(true);
                 }
                 return(false);
             }
         }
     }
     catch (MySqlException ex)
     {
         throw new Exception(ex.Message, ex);
     }
 }
Example #2
0
        public bool Update(INewsItemDTO dto)
        {
            try
            {
                using (MySqlConnection conn = new MySqlConnection(_connection))
                {
                    conn.Open();
                    using (MySqlCommand cmd = new MySqlCommand("Update newsitem SET Title = @Title, Description=@Description, Date=@Date WHERE Id = @Id"))
                    {
                        cmd.Parameters.AddWithValue("@Name", dto.Title);
                        cmd.Parameters.AddWithValue("@Email", dto.Description);
                        cmd.Parameters.AddWithValue("@Age", dto.PostDate);
                        cmd.Parameters.AddWithValue("@Id", dto.Id);

                        if (cmd.ExecuteNonQuery() > 0)
                        {
                            return(true);
                        }
                        return(false);
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex);
            }
        }
 private NewsItem ExtractNewsItem(INewsItemDTO dto)
 {
     return(new NewsItem(dto.Title, _newsItemDAL)
     {
         Id = dto.Id,
         Description = dto.Description,
         PostDate = dto.PostDate
     });
 }
 private NewsItem ExtractNewsItem(INewsItemDTO dto)
 {
     return(new NewsItem(dto.Title, null)
     {
         Id = dto.Id,
         Description = dto.Description,
         date = dto.date
     });
 }
        public bool AddNewsItem(NewsItem news)
        {
            if (news != null)
            {
                INewsItemDTO dTO = news;

                if (containerDAL.Save(dTO))
                {
                    NewsItems.Add(news);
                    return(true);
                }
            }
            return(false);
        }
 public bool Update(INewsItemDTO dto)
 {
     newsItems.Add(dto);
     return(true);
 }
 public bool Save(INewsItemDTO dto)
 {
     news.Add(dto);
     return(true);
 }