示例#1
0
        /// <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 SocioBoard.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.
                        SocioBoard.Domain.Admin result = (SocioBoard.Domain.Admin)query.UniqueResult();
                        return(result);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                        return(null);
                    }
                } // End using transaction
            }     //End Using Session
        }
示例#2
0
 /// < 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(SocioBoard.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
 }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            SocioBoard.Domain.Admin admin = (SocioBoard.Domain.Admin)Session["AdminProfile"];


            if (imgfileupload.HasFile)
            {
                string path = Server.MapPath("~/Contents/img/user_img/" + imgfileupload.FileName);
                imgfileupload.SaveAs(path);
                admin.Image = "../Contents/img/user_img/" + imgfileupload.FileName;
            }



            admin.FirstName = txtFirstName.Text;
            admin.LastName  = txtLastName.Text;
            admin.UserName  = txtUserName.Text;
            if (txtFirstName.Text == "" || txtLastName.Text == "" || txtUserName.Text == "")
            {
                ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Please fill all the fields');", true);
            }
            admin.TimeZone = ddlTimeZone.SelectedItem.Text;
            AdminRepository.Update(admin);
            Session["AdminProfile"] = admin;
            ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Updated successfully');", true);
            load();
        }
示例#4
0
 /// <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 (SocioBoard.Domain.Admin).</param>
 public static void Add(SocioBoard.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
 }
 public void load()
 {
     SocioBoard.Domain.Admin admin = (SocioBoard.Domain.Admin)Session["AdminProfile"];
     txtFirstName.Text       = admin.FirstName.ToString();
     txtLastName.Text        = admin.LastName.ToString();
     txtUserName.Text        = admin.UserName.ToString();
     txtPassword.Text        = "";
     txtConfirmPassword.Text = "";
     custImg.ImageUrl        = admin.Image.ToString();
     if (admin.TimeZone != null)
     {
         ddlTimeZone.DataSource = TimeZoneInfo.GetSystemTimeZones();
         ddlTimeZone.DataBind();
         ddlTimeZone.SelectedValue = admin.TimeZone.ToString(); //user.PaymentStatus;
     }
     else
     {
         ddlTimeZone.DataSource = TimeZoneInfo.GetSystemTimeZones();
         ddlTimeZone.DataBind();
     }
 }
示例#6
0
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            try
            {
                SessionFactory.configfilepath = Server.MapPath("~/hibernate.cfg.xml");
                AdminRepository         adminRepo = new AdminRepository();
                SocioBoard.Domain.Admin admin     = adminRepo.GetUserInfo(txtUserName.Text, txtPassword.Text);
                if (admin != null)
                {
                    Session["AdminProfile"] = admin;
                    Response.Redirect("Dashboard.aspx");
                }

                else
                {
                    ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Please enter correct Username and password!');", true);
                }
            }
            catch (Exception ex)
            {
            }
        }
        public void changePassoword(object sender, EventArgs e)
        {
            SocioBoard.Domain.Admin admin     = (SocioBoard.Domain.Admin)Session["AdminProfile"];
            AdminRepository         adminrepo = new AdminRepository();

            if (txtPassword.Text != "" && txtConfirmPassword.Text != "")
            {
                if (txtPassword.Text == admin.Password)
                {
                    adminrepo.ChangePwd(txtConfirmPassword.Text, admin.UserName);
                    txtConfirmPassword.Text = string.Empty;
                    txtPassword.Text        = string.Empty;
                    ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Password changed successfully');", true);
                }
                else
                {
                    ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Wrong Password');", true);
                }
            }
            else
            {
                ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Password should not be blank');", true);
            }
        }