/// < Admin Update> /// Update a existing admin. /// </summary> /// <param name="user">Set Values in a Admin Class Property and Pass the Object of Admin Class.</param> public static void Update(Domain.Myfashion.Domain.Admin user) { //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 Sction to update Data. // And Set the reuired paremeters to find the specific values. int i = session.CreateQuery("Update Admin set Image =:profileurl, UserName =: username , TimeZone=:timezone,FirstName =:first,LastName =:last where Id = :twtuserid") .SetParameter("twtuserid", user.Id) .SetParameter("profileurl", user.Image) .SetParameter("username", user.UserName) .SetParameter("timezone", user.TimeZone) .SetParameter("first", user.FirstName) .SetParameter("last", user.LastName) .ExecuteUpdate(); transaction.Commit(); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } } //End Using trasaction } //End Using session }
/// <GetUserInfo> /// Get the all information of existing admin by UserName and Password. /// </summary> /// <param name="UserName">Admin UserName </param> /// <param name="Password">Admin Password</param> /// <returns>Return Latest Information of Admin</returns> public Domain.Myfashion.Domain.Admin GetUserInfo(string UserName, string Password) { //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 Get Data from Query //Set the parameters to find the specific Data. NHibernate.IQuery query = session.CreateQuery("from Admin u where u.UserName = : email and u.Password= :password"); query.SetParameter("email", UserName); query.SetParameter("password", Password); // Get the UniqueResult and return. Domain.Myfashion.Domain.Admin result = (Domain.Myfashion.Domain.Admin)query.UniqueResult(); return(result); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); return(null); } } // End using transaction } //End Using Session }
/// <Add> /// Add a new admin in DataBase. /// </summary> /// <param name="user">Set Values in a Admin Class Property and Pass the Object of Admin Class (Domain.Myfashion.Domain.Admin).</param> public static void Add(Domain.Myfashion.Domain.Admin user) { //Creates a database connection and opens up a session using (NHibernate.ISession session = SessionFactory.GetNewSession()) { //After Session creation, start and open Transaction. using (NHibernate.ITransaction transaction = session.BeginTransaction()) { //Proceed action to save data. session.Save(user); transaction.Commit(); } //End Using trasaction } //End Using session }