/// <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); } }
public string GetNewsById(string NewsId) { try { Guid Newsid = Guid.Parse(NewsId); Domain.Myfashion.Domain.News objNews = objNewsRepo.getNewsDetailsbyId(Newsid); return(new JavaScriptSerializer().Serialize(objNews)); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); return(null); } }
public string UpdateNews(string ObjPackage) { try { Domain.Myfashion.Domain.News objNews = (Domain.Myfashion.Domain.News)(new JavaScriptSerializer().Deserialize(ObjPackage, typeof(Domain.Myfashion.Domain.News))); objNewsRepo.UpdateNews(objNews); return(new JavaScriptSerializer().Serialize("Updated Successfully")); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); return(null); } }
/// <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); } }
public string AddNews(string ObjPackage, string News) { try { if (objNewsRepo.checkNewsExists(News)) { Domain.Myfashion.Domain.News objNews = (Domain.Myfashion.Domain.News)(new JavaScriptSerializer().Deserialize(ObjPackage, typeof(Domain.Myfashion.Domain.News))); objNewsRepo.UpdateNews(objNews); return(new JavaScriptSerializer().Serialize("Success")); } else { Domain.Myfashion.Domain.News objNews = (Domain.Myfashion.Domain.News)(new JavaScriptSerializer().Deserialize(ObjPackage, typeof(Domain.Myfashion.Domain.News))); objNewsRepo.AddNews(objNews); return(new JavaScriptSerializer().Serialize("Success")); } } catch (Exception ex) { Console.WriteLine(ex.StackTrace); return(null); } }
/// <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 }