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
 public void AddNews(News news)
 {
     try
     {
         using (NHibernate.ISession session = SessionFactory.GetNewSession())
         {
             using (NHibernate.ITransaction transaction = session.BeginTransaction())
             {
                 session.Save(news);
                 transaction.Commit();
             }
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine("error : " + ex.StackTrace);
     }
 }
Esempio n. 3
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. 4
0
 protected void btnSave_Click(object sender, EventArgs e)
 {
     try
     {
         News objNews = new News();
         NewsRepository objNewsRepo = new NewsRepository();
         objNews.NewsDetail = txtNews.Text;
         objNews.Status = bool.Parse(ddlStatus.SelectedValue);
         objNews.EntryDate = DateTime.Now;
         objNews.ExpiryDate = Convert.ToDateTime(datepicker.Text);
         objNews.Id = Guid.Parse(AddUpdateNews());
         if (objNewsRepo.checkNewsExists(txtNews.Text))
             objNewsRepo.UpdateNews(objNews);
         else
             objNewsRepo.AddNews(objNews);
     }
     catch (Exception Err)
     {
         logger.Error(Err.Message);
         Response.Write(Err.Message);
     }
 }
Esempio n. 5
0
        public void UpdateNews(News news)
        {
            try
            {
                using (NHibernate.ISession session = SessionFactory.GetNewSession())
                {
                    using (NHibernate.ITransaction transaction = session.BeginTransaction())
                    {
                        try
                        {
                            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;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error : " + ex.StackTrace);
            }
        }
Esempio n. 6
0
        public News getNewsForHome()
        {
            using (NHibernate.ISession session = SessionFactory.GetNewSession())
            {
                using (NHibernate.ITransaction transaction = session.BeginTransaction())
                {
                    News nws = new News();
                    try
                    {
                        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;
                }
            }
        }