Esempio n. 1
0
 /// <UpdateNews>
 /// Update News
 /// </summary>
 /// <param name="news">Set the values in a News Class Property and Pass the Object of News Class.(Domein.News)</param>
 public void UpdateNews(News news)
 {
     try
     {
         //Creates a database connection and opens up a session
         using (NHibernate.ISession session = SessionFactory.GetNewSession())
         {
             //After Session creation, start Transaction. 
             using (NHibernate.ITransaction transaction = session.BeginTransaction())
             {
                 try
                 {
                     //Proceed action, to update details of news.
                     session.CreateQuery("Update News set NewsDetail =:newsdetail,ExpiryDate=:expirydate,Status=:status where Id = :newsid")
                         .SetParameter("newsdetail", news.NewsDetail)
                         .SetParameter("status", news.Status)
                         .SetParameter("newsid", news.Id)
                         .SetParameter("expirydate", news.ExpiryDate)
                         .ExecuteUpdate();
                     transaction.Commit();
                 }
                 catch (Exception ex)
                 {
                     Console.WriteLine(ex.StackTrace);
                     // return 0;
                 }
             }//End Transaction
         }//End Session
     }
     catch (Exception ex)
     {
         Console.WriteLine("Error : " + ex.StackTrace);
     }
 }
Esempio n. 2
0
 /// <AddNews>
 /// Add New News
 /// </summary>
 /// <param name="news">Set Values in a News Class Property and Pass the Object of News Class.(Domein.News)</param>
 public void AddNews(News news)
 {
     try
     {
         //Creates a database connection and opens up a session
         using (NHibernate.ISession session = SessionFactory.GetNewSession())
         {
             //After Session creation, start Transaction. 
             using (NHibernate.ITransaction transaction = session.BeginTransaction())
             {
                 session.Save(news);
                 transaction.Commit();
             }//End Transaction
         }//End Session
     }
     catch (Exception ex)
     {
         Console.WriteLine("error : " + ex.StackTrace);
     }
 }
Esempio n. 3
0
        /// <getNewsForHome>
        /// Get News For Home
        /// </summary>
        /// <returns>Return object of News Class with  all news info.(List<News>)</returns>
        public News getNewsForHome()
        {
            //Creates a database connection and opens up a session
            using (NHibernate.ISession session = SessionFactory.GetNewSession())
            {
                //After Session creation, start Transaction. 
                using (NHibernate.ITransaction transaction = session.BeginTransaction())
                {
                    News nws = new News();
                    try
                    {
                        //Proceed action to get all home news.
                        var query = session.CreateSQLQuery("Select Id,NewsDetail,Status from News Where ExpiryDate>CURDATE() and Status=1 order by Entrydate Desc");
                        foreach (var item in query.List())
                        {
                            Array temp = (Array)item;

                            nws.Id = Guid.Parse(temp.GetValue(0).ToString());
                            nws.NewsDetail = temp.GetValue(1).ToString();
                            //  nws.Status = bool.Parse(temp.GetValue(2).ToString());
                            break;
                        }
                    }
                    catch (Exception Err)
                    {
                        Console.Write(Err.StackTrace);
                    }
                    return nws;
                }//End Transaction
            }//End Session
        }