Esempio n. 1
0
        public bool ResetCustomerAccountPassword(ResetPasswordModel resetPasswordModel)
        {
            try
            {
                using (SqlConnection connection = new SqlConnection(connectionString))
                {
                    using (connection)
                    {
                        connection.Open();
                        SqlCommand cmd = new SqlCommand("ChangeCustomerPassword", connection)
                        {
                            CommandType = CommandType.StoredProcedure
                        };
                        cmd.Parameters.AddWithValue("Email", resetPasswordModel.Email);
                        cmd.Parameters.AddWithValue("NewPassword", Password.ConvertToEncrypt(resetPasswordModel.NewPassword));
                        var returnParameter = cmd.Parameters.Add("@Result", SqlDbType.Int);
                        returnParameter.Direction = ParameterDirection.ReturnValue;

                        CustomerUser  customer = new CustomerUser();
                        SqlDataReader rd       = cmd.ExecuteReader();
                        var           result   = returnParameter.Value;

                        if (result != null && result.Equals(1))
                        {
                            return(true);
                        }
                        return(false);
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Esempio n. 2
0
        public CustomerUser RegisterDetails(RegisterCustomer registration)
        {
            try
            {
                CustomerUser customerUser = new CustomerUser();
                using (SqlConnection connection = new SqlConnection(connectionString))
                {
                    using (connection)
                    {
                        connection.Open();
                        //define the SqlCommand Object
                        SqlCommand cmd = new SqlCommand("spRegisterCustomerDetails", connection);
                        cmd.CommandType = CommandType.StoredProcedure;



                        cmd.Parameters.AddWithValue("@FirstName", registration.CustomerFirstName);
                        cmd.Parameters.AddWithValue("@LastName", registration.CustomerLastName);
                        cmd.Parameters.AddWithValue("@PhoneNumber", registration.PhoneNumber);
                        cmd.Parameters.AddWithValue("@Email", registration.Email);
                        cmd.Parameters.AddWithValue("@Password", Password.ConvertToEncrypt(registration.Password));

                        SqlDataReader sqlDataReader = cmd.ExecuteReader();


                        if (sqlDataReader.HasRows)
                        {
                            if (sqlDataReader.Read())
                            {
                                customerUser.CustomerID        = sqlDataReader.GetInt64(0);
                                customerUser.CustomerFirstName = sqlDataReader.GetString(1);
                                customerUser.CustomerLastName  = sqlDataReader.GetString(2);
                                customerUser.Email             = sqlDataReader.GetString(3);
                                customerUser.PhoneNumber       = sqlDataReader.GetInt64(4);
                            }
                        }

                        return(customerUser);

                        //Close Data Reader
                        sqlDataReader.Close();
                        connection.Close();
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Esempio n. 3
0
        public string AdminLogin(LoginAdmin login)
        {
            try
            {
                connection.Open();
                SqlCommand cmd = new SqlCommand("spInsertAdminLoginDetail", connection)
                {
                    CommandType = CommandType.StoredProcedure
                };
                cmd.Parameters.AddWithValue("@Email", login.Email);
                cmd.Parameters.AddWithValue("@Password", Password.ConvertToEncrypt(login.Password));
                var returnParameter = cmd.Parameters.Add("@Result", SqlDbType.Int);
                returnParameter.Direction = ParameterDirection.ReturnValue;
                SqlDataReader sqlDataReader = cmd.ExecuteReader();
                Admin         admin         = new Admin();

                if (sqlDataReader.HasRows)
                {
                    if (sqlDataReader.Read())
                    {
                        admin.AdminID     = sqlDataReader.GetInt64(0);
                        admin.AdminName   = sqlDataReader.GetString(1);
                        admin.PhoneNumber = sqlDataReader.GetInt64(2);
                        admin.Email       = sqlDataReader.GetString(3);
                    }
                }

                var result = returnParameter.Value;
                if (result != null && result.Equals(2))
                {
                    throw new Exception("AdminID is invalid");
                }
                if (result != null && result.Equals(3))
                {
                    throw new Exception("wrong password");
                }

                string token1 = CreateAdminToken(admin);
                return(token1);
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                connection.Close();
            }
        }
Esempio n. 4
0
        public Admin RegisterAdminDetails(RegisterAdmin registration)
        {
            try
            {
                Admin admin = new Admin();
                using (SqlConnection connection = new SqlConnection(connectionString))
                {
                    using (connection)
                    {
                        connection.Open();
                        //define the SqlCommand Object
                        SqlCommand cmd = new SqlCommand("RegisterAdminDetails", connection);
                        cmd.CommandType = CommandType.StoredProcedure;

                        cmd.Parameters.AddWithValue("@AdminName", registration.AdminName);
                        cmd.Parameters.AddWithValue("@PhoneNumber", registration.PhoneNumber);
                        cmd.Parameters.AddWithValue("@Email", registration.Email);
                        cmd.Parameters.AddWithValue("@Password", Password.ConvertToEncrypt(registration.Password));

                        SqlDataReader sqlDataReader = cmd.ExecuteReader();


                        if (sqlDataReader.HasRows)
                        {
                            if (sqlDataReader.Read())
                            {
                                admin.AdminID     = sqlDataReader.GetInt64(0);
                                admin.AdminName   = sqlDataReader.GetString(1);
                                admin.PhoneNumber = sqlDataReader.GetInt64(2);
                                admin.Email       = sqlDataReader.GetString(3);
                            }
                        }

                        return(admin);

                        //Close Data Reader
                        sqlDataReader.Close();
                        connection.Close();
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Esempio n. 5
0
        public CustomerUser LoginCustomer(LoginCustomer loginCustomerAccount)
        {
            try
            {
                loginCustomerAccount.Password = Password.ConvertToEncrypt(loginCustomerAccount.Password);

                var result = userRL.LoginCustome(loginCustomerAccount);
                if (result != null)
                {
                    result.token = userRL.CreateToken(result);
                }
                return(result);
            }
            catch (Exception)
            {
                throw;
            }
        }