예제 #1
0
        // **************************************
        // URL: /Backend/Update
        // **************************************

        public ActionResult UpdateUser(int id)
        {
            UserModel     user = null;
            RegisterModel reg  = new RegisterModel();

            ViewData["Role"] = MembershipService.GetAllRole();
            try
            {
                user = MembershipService.GetUsersByID(id);
                if (ContentHelpers.Isnull(user))
                {
                    ModelState.AddModelError("", "Data not found");
                }
                else
                {
                    reg.CitizenID = user.CitizenID;
                    reg.Email     = user.Email;
                    reg.Name      = user.Name;
                    reg.Phone     = user.Phone;
                    reg.RoleID    = user.RoleID;
                    reg.Status    = user.Status;
                    reg.UserName  = user.UserName;
                }
            }
            catch (Exception e)
            {
                ModelState.AddModelError(String.Empty, e.Message);
            }
            return(View(reg));
        }
예제 #2
0
        public List <AppraisalListsModel> searchResult(FormCollection val)
        {
            List <AppraisalListsModel> searchList = new List <AppraisalListsModel>();

            string appraisalCode = val["appraisalCode"];
            int    districtId    = val["districtId"] == null ? 38 : Convert.ToInt32(val["districtId"]);
            int    amphurId      = val["amphurId"] == null ? 581 : Convert.ToInt32(val["amphurId"]);
            string userName      = ContentHelpers.Decode(Convert.ToString(Session["UserName"]));

            AppraisalService serv = new AppraisalService();

            searchList = serv.GetAppraisalLists(appraisalCode, districtId, amphurId, userName, true);
            if (ContentHelpers.Isnull(searchList) || searchList.Count <= 0)
            {
                ModelState.AddModelError("", "Search data not found.");
            }

            return(searchList);
        }
예제 #3
0
        public Boolean UpdateUser(RegisterModel register, String updateBy)
        {
            if (String.IsNullOrEmpty(register.UserName))
            {
                throw new ArgumentException("Value cannot be null or empty.", "username");
            }
            if (String.IsNullOrEmpty(register.Email))
            {
                throw new ArgumentException("Value cannot be null or empty.", "email");
            }
            if (String.IsNullOrEmpty(register.CitizenID))
            {
                throw new ArgumentException("Value cannot be null or empty.", "citizen");
            }
            if (String.IsNullOrEmpty(updateBy))
            {
                throw new ArgumentException("Value cannot be null or empty.", "updateBy");
            }
            MySqlConnection  conn    = null;
            MySqlTransaction tran    = null;
            bool             process = false;

            try
            {
                using (conn = new MySqlConnection(GetConnectionString()))
                {
                    if (conn.State == ConnectionState.Closed)
                    {
                        conn.Open();
                    }

                    tran = conn.BeginTransaction(IsolationLevel.ReadCommitted);

                    using (MySqlCommand cmd = new MySqlCommand(Resources.SQLResource.USP_UPD_USERS, conn, tran))
                    {
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.Clear();
                        cmd.Parameters.Add("p_user_name", MySqlDbType.VarChar).Value = register.UserName;
                        cmd.Parameters.Add("p_password", MySqlDbType.VarChar).Value  = ContentHelpers.Isnull(register.Password) ?
                                                                                       ContentHelpers.MD5Hash(Resources.ConfigResource.PASSWORD_DEFAULT) :
                                                                                       ContentHelpers.MD5Hash(register.Password);
                        cmd.Parameters.Add("p_roleid", MySqlDbType.VarChar).Value    = register.RoleID;
                        cmd.Parameters.Add("p_citizenid", MySqlDbType.VarChar).Value = register.CitizenID;
                        cmd.Parameters.Add("p_name", MySqlDbType.VarChar).Value      = register.Name;
                        cmd.Parameters.Add("p_email", MySqlDbType.VarChar).Value     = register.Email;
                        cmd.Parameters.Add("p_phone", MySqlDbType.VarChar).Value     = register.Phone;
                        cmd.Parameters.Add("p_update_by", MySqlDbType.VarChar).Value = updateBy;

                        int excute = cmd.ExecuteNonQuery();
                        //
                        if (excute > 0)
                        {
                            tran.Commit();
                            process = true;
                        }
                    }
                }
            }
            catch (MySqlException ms)
            {
                throw new Exception("MySqlException: " + ms.Message);
            }
            catch (Exception)
            {
                tran.Rollback();
                throw;
            }
            finally
            {
                conn.Close();
                conn.Dispose();
            }
            return(process);
        }
예제 #4
0
        public Hashtable CreateUser(RegisterModel register, String createBy)
        {
            if (String.IsNullOrEmpty(register.UserName))
            {
                throw new ArgumentException("Value cannot be null or empty.", "username");
            }
            if (String.IsNullOrEmpty(register.Email))
            {
                throw new ArgumentException("Value cannot be null or empty.", "email");
            }
            if (String.IsNullOrEmpty(register.CitizenID))
            {
                throw new ArgumentException("Value cannot be null or empty.", "citizen");
            }
            if (String.IsNullOrEmpty(createBy))
            {
                throw new ArgumentException("Value cannot be null or empty.", "createBy");
            }
            MySqlConnection  conn    = null;
            MySqlTransaction tran    = null;
            Hashtable        result  = new Hashtable();
            bool             process = false;
            string           msg     = "";

            try
            {
                using (conn = new MySqlConnection(GetConnectionString()))
                {
                    if (conn.State == ConnectionState.Closed)
                    {
                        conn.Open();
                    }

                    tran = conn.BeginTransaction(IsolationLevel.ReadCommitted);

                    using (MySqlCommand cmd = new MySqlCommand(Resources.SQLResource.USP_INS_USERS, conn, tran))
                    {
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.Clear();
                        cmd.Parameters.Add("p_user_name", MySqlDbType.VarChar).Value = register.UserName;
                        cmd.Parameters.Add("p_password", MySqlDbType.VarChar).Value  = ContentHelpers.Isnull(register.Password) ?
                                                                                       ContentHelpers.MD5Hash(Resources.ConfigResource.PASSWORD_DEFAULT) :
                                                                                       ContentHelpers.MD5Hash(register.Password);
                        cmd.Parameters.Add("p_roleid", MySqlDbType.VarChar).Value    = register.RoleID;
                        cmd.Parameters.Add("p_citizenid", MySqlDbType.VarChar).Value = register.CitizenID;
                        cmd.Parameters.Add("p_name", MySqlDbType.VarChar).Value      = register.Name;
                        cmd.Parameters.Add("p_email", MySqlDbType.VarChar).Value     = register.Email;
                        cmd.Parameters.Add("p_phone", MySqlDbType.VarChar).Value     = register.Phone;
                        cmd.Parameters.Add("p_create_by", MySqlDbType.VarChar).Value = createBy;

                        cmd.Parameters.Add(new MySqlParameter("oMessage", MySqlDbType.VarChar)).Direction = ParameterDirection.Output;
                        cmd.Parameters.Add(new MySqlParameter("oUserID", MySqlDbType.Int32)).Direction    = ParameterDirection.Output;

                        cmd.ExecuteScalar();
                        //
                        int userId = cmd.Parameters["oUserID"].Value == System.DBNull.Value ? 0 : Convert.ToInt32(cmd.Parameters["oUserID"].Value);
                        if (userId > 0)
                        {
                            tran.Commit();
                            process = true;
                        }
                        msg = Convert.ToString(cmd.Parameters["oMessage"].Value);
                    }
                }
            }
            catch (MySqlException ms)
            {
                throw new Exception("MySqlException: " + ms.Message);
            }
            catch (Exception)
            {
                tran.Rollback();
                throw;
            }
            finally
            {
                conn.Close();
                conn.Dispose();
            }
            result["Status"]  = process;
            result["Message"] = msg;
            return(result);
        }