Пример #1
0
        public ActionResult Edit(string id)
        {
            UserAccessRepository rep         = new UserAccessRepository();
            UserAccountView      userAccView = new UserAccountView();

            userAccView.UserAccount = rep.GetUserAccount(id);

            List <Role> roles = rep.GetAllRoles();

            userAccView.Roles = new List <SelectListItem>();

            foreach (Role role in roles)
            {
                userAccView.Roles.Add(new SelectListItem {
                    Text = role.RoleName, Value = role.ID.ToString()
                });
            }


            if (userAccView.UserAccount != null)
            {
                View("Edit", userAccView);
            }
            else
            {
                ViewData["Message"] = "User could not be found!";
            }

            return(View("Edit", userAccView));
        }
Пример #2
0
        public ActionResult Delete(object id)
        {
            UserAccessRepository rep = new UserAccessRepository();

            UserAccount userAcc = rep.GetUserAccount((string)id);

            if (userAcc != null)
            {
                if (rep.DeleteUser(userAcc.Username))
                {
                    if (Membership.DeleteUser(userAcc.Username))
                    {
                        ViewData["Message"] = "User account deleted successfully!";
                        userAcc             = null;
                    }

                    else
                    {
                        ViewData["Message"] = "There was an error deleting user account. Please contact your administrator";
                        userAcc             = null;
                    }
                }

                return(View(userAcc));
            }
            else
            {
                ViewData["Message"] = "User could not be found!";
            }


            return(View(userAcc));
        }
Пример #3
0
        public ActionResult Edit(UserAccountView UserAccountView, Guid Roles)
        {
            UserAccessRepository rep = new UserAccessRepository();

            List <Role> roles = rep.GetAllRoles();

            UserAccountView.Roles            = new List <SelectListItem>();
            UserAccountView.UserAccount.Role = rep.GetRole(Roles);

            ModelState.Remove("Roles"); //We remove any model state error on Roles because we manually load it from the database as drop-down list only returns the selected role

            foreach (Role role in roles)
            {
                UserAccountView.Roles.Add(new SelectListItem {
                    Text = role.RoleName, Value = role.ID.ToString()
                });
            }

            if (ModelState.IsValid)
            {
                if (UserAccountView.UserAccount != null)
                {
                    ////////////////////
                    MembershipUser user = Membership.GetUser(UserAccountView.UserAccount.Username);

                    UserAccount existingAccount = rep.GetUserAccount(UserAccountView.UserAccount.Username);

                    foreach (AvailableFunction func in existingAccount.Role.AvailableFunctions)
                    {
                        System.Web.Security.Roles.RemoveUserFromRole(existingAccount.Username, func.FunctionName);
                    }

                    foreach (var func in UserAccountView.UserAccount.Role.AvailableFunctions)
                    {
                        System.Web.Security.Roles.AddUserToRole(UserAccountView.UserAccount.Username, func.FunctionName);
                    }


                    ////////////////////
                    bool status = rep.UpdateUserAccount(UserAccountView.UserAccount);

                    if (status)
                    {
                        ViewData["Message"] = "User updated successfully!";
                    }
                    else
                    {
                        ViewData["Message"] = "There was an error updating this user. Please contact your administrator!";
                    }

                    return(View("Edit", null));
                }
                else
                {
                    ViewData["Message"] = "User could not be found!";
                }
            }

            return(View(UserAccountView));
        }
Пример #4
0
        public ActionResult Delete(string id)
        {
            UserAccessRepository rep = new UserAccessRepository();

            UserAccount userAcc = rep.GetUserAccount(id);

            if (userAcc != null)
            {
                return(View(userAcc));
            }
            else
            {
                ViewData["Message"] = "User could not be found!";
            }


            return(View(userAcc));
        }