public ActionResult EditUser(EditUserModel model)
        {
            UserTypeTableAdapter userTypeAdapter = new UserTypeTableAdapter();
            DataTable userTypeDT = userTypeAdapter.GetData();

            List<SelectListItem> items = new List<SelectListItem>();
            foreach (DataRow row in userTypeDT.Rows)
            {
                items.Add(new SelectListItem { Text = row["TypeName"].ToString(), Value = row["TypeShortName"].ToString() });
            }
            ViewData["UserType"] = items;

            if (!ModelState.IsValid)
            {
                return View(model);
            }

            string email = model.Email;
            if (!string.IsNullOrEmpty(email))
            {
                AccountTableAdapter AccountAdapter = new AccountTableAdapter();
                DataTable dt = AccountAdapter.GetDataByUsername(model.Username);

                if (!dt.Rows[0]["Email"].ToString().Equals(email))
                {
                    DataTable AccountDT = AccountAdapter.GetDataByEmail(email);

                    if (AccountDT.Rows.Count == 1)
                    {
                        if (!AccountDT.Rows[0]["Username"].ToString().Equals(model.Username))
                        {
                            Log.ActivityLog(AccountDT.Rows[0]["Username"].ToString().Equals(model.Username).ToString());
                            ModelState.AddModelError("", "Email đã tồn tại");
                            return View(model);
                        }
                    }
                }
            }

            string updateBy = AccountInfo.GetUserName(Request);
            DateTime date = DateTime.Now;
            string username = model.Username;
            string name = model.Name;
            string userTypeID = model.UserTypeID;
            bool isCafeteriaStaff = false;
            int role = model.Role;
            bool isActive = model.isActive;
            if (role == 2)
            {
                isCafeteriaStaff = true;
            }

            AccountTableAdapter accountAdapter = new AccountTableAdapter();
            UserInfoTableAdapter userInfoAdapter = new UserInfoTableAdapter();

            DataTable userInfoDT = userInfoAdapter.GetDataByUsername(username);
            DataRow userInfoRow = userInfoDT.Rows[0];

            int amountOfMoney = userInfoRow.Field<int>("AmountOfMoney");
            DateTime lastUpdatedMoney = userInfoRow.Field<DateTime>("LastUpdatedMoney");
            byte[] fingerPrintIMG = userInfoRow.Field<byte[]>("FingerPrintIMG");
            DateTime? lastUpdatedFingerPrint = userInfoRow.Field<DateTime?>("LastUpdatedFingerPrint");
            int? fingerPosition = userInfoRow.Field<int?>("FingerPosition");
            DateTime insertedDate = userInfoRow.Field<DateTime>("InsertedDate");

            accountAdapter.Connection.Open();
            userInfoAdapter.Connection = accountAdapter.Connection;

            using (SqlTransaction transaction = accountAdapter.Connection.BeginTransaction())
            {
                accountAdapter.AttachTransaction(transaction);
                userInfoAdapter.AttachTransaction(transaction);

                try
                {
                    userInfoAdapter.UpdateUserInfo(username, name, userTypeID, amountOfMoney, lastUpdatedMoney, fingerPrintIMG
                        , lastUpdatedFingerPrint, fingerPosition, isCafeteriaStaff, isActive, insertedDate, updateBy, date, username);
                    Log.ActivityLog("Update to UserInfo: username = "******"Update to Account: username = "******"editUser"] = "******";
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    Log.ErrorLog(ex.Message);
                    Session["editUser"] = "******";
                }
            }

            return RedirectToAction("EditUser", "Account", new { @username = model.Username });
        }
        public ActionResult EditUser(string username)
        {
            UserTypeTableAdapter userTypeAdapter = new UserTypeTableAdapter();
            DataTable userTypeDT = userTypeAdapter.GetData();

            List<SelectListItem> items = new List<SelectListItem>();
            foreach (DataRow row in userTypeDT.Rows)
            {
                items.Add(new SelectListItem { Text = row["TypeName"].ToString(), Value = row["TypeShortName"].ToString() });
            }
            ViewData["UserType"] = items;

            EditUserModel userInfo = new EditUserModel();
            UserInfoDetailTableAdapter userinfoAdapter = new UserInfoDetailTableAdapter();
            DataTable userinfoDataTable = userinfoAdapter.GetDataByUsername(username);

            try
            {
                userInfo.Username = username;
                userInfo.Name = userinfoDataTable.Rows[0]["Name"].ToString();
                userInfo.UserTypeID = (string)userinfoDataTable.Rows[0]["TypeShortName"];
                userInfo.Email = userinfoDataTable.Rows[0]["Email"].ToString();
                userInfo.Role = (int)userinfoDataTable.Rows[0]["Role"];
                userInfo.isActive = (bool)userinfoDataTable.Rows[0]["IsActive"];

                return View(userInfo);
            }
            catch (Exception ex)
            {
                Log.ErrorLog(ex.Message);
                return RedirectToAction("Error", "Error");
            }
        }