Exemplo n.º 1
0
        public ViewResult EditAccount(string id, bool approved)
        {
            // Is a list of all the user roles
            List<String> removeRoleList = new List<String>(Roles.GetAllRoles());

            // We are requesting the form variables directly from the form
            foreach (string key in Request.Form.Keys)
            {
                if (key.StartsWith("role."))
                {
                    String userRole = key.Substring(5, key.Length - 5);

                    // ВСЕ чекбоксы передаются в Request.Form, даже неотмеченные!!!
                    // Поэтому проверяем содержимое "ролевых" чекбоксов (если не отмечен: "false" | если отмечен: "true;false" - такая хитрость из-за скрытых полей)
                    bool isRoleChecked = (Request.Form[key].Contains("true")) ? true : false;
                    if (isRoleChecked)
                        removeRoleList.Remove(userRole);

                    if (!Roles.IsUserInRole(id, userRole))
                        Roles.AddUserToRole(id, userRole); // а если у юзера уже есть эта роль, нет смысла ее повторно назначать
                }
            }

            foreach (string removeRole in removeRoleList)
            {
                Roles.RemoveUserFromRole(id, removeRole);
            }

            MembershipUser account = Membership.GetUser(id);
            account.IsApproved = approved;
            Membership.UpdateUser(account);
            AccountViewModel viewModel = new AccountViewModel();
            viewModel.Account = account;

            TempData["Message"] = "Данные аккаунта обновлены";
            return View(viewModel);
        }
Exemplo n.º 2
0
        public ViewResult EditAccount(string id)
        {
            AccountViewModel viewModel = new AccountViewModel();
            viewModel.Account = Membership.GetUser(id);

            return View(viewModel);
        }