示例#1
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));
        }
示例#2
0
        public ActionResult Delete(Guid id)
        {
            UserAccessRepository rep = new UserAccessRepository();

            Role role = rep.GetRole(id);

            return(View(role));
        }
示例#3
0
        public ActionResult Create(UserAccount UserAccount, Guid Roles)
        {
            UserAccessRepository rep = new UserAccessRepository();

            if (ModelState.IsValid)
            {
                UserAccount.Role = rep.GetRole(Roles);
                UserAccount.Person.Address.Country = "Canada";
                UserAccount.Person.Organization    = new Organization(Guid.Parse(ConfigurationManager.AppSettings["HostingOrganizationID"].ToString()));

                MembershipCreateStatus createStatus;
                MembershipUser         newUser = Membership.CreateUser(UserAccount.Username, UserAccount.Password, UserAccount.Person.Email, "Q", "P", true, out createStatus);
                UserAccount.Person.Type = PersonType.Employee;

                switch (createStatus)
                {
                case MembershipCreateStatus.DuplicateUserName:
                    ViewData["Message"] = "Duplicate username! This username already exists in the system.";

                    break;

                case MembershipCreateStatus.InvalidPassword:
                    ViewData["Message"] = "Invalid password! Minimum password length is six characters.";

                    break;

                case MembershipCreateStatus.Success:
                    foreach (AvailableFunction func in UserAccount.Role.AvailableFunctions)
                    {
                        System.Web.Security.Roles.AddUserToRole(UserAccount.Username, func.FunctionName);
                    }

                    if (rep.CreateUserAccount(UserAccount))
                    {
                        ViewData["Message"] = "User account created succesfully!";
                        UserAccount         = null;
                        ModelState.Clear();     //Will clear out the form

                        return(RedirectToAction("Create", "UserAccount", new { message = "User account created succesfully!" }));
                    }
                    else
                    {
                        ViewData["Message"] = "There was an error creating this user. Please contact your administrator.";
                    }

                    break;

                default:
                    ViewData["Message"] = "There was an error creating this user. Please contact your administrator.";
                    break;
                }
            }

            UserAccountView userAccView = new UserAccountView();

            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()
                });
            }

            userAccView.ExistingUserAccounts = rep.GetUserAccounts();
            userAccView.UserAccount          = UserAccount;

            return(View("Create", userAccView));
        }
示例#4
0
        public ActionResult NewOrganization(RegisterNewOrganizationView RegisterNewOrganizationView)
        {
            RegisterAccessRepository repp = new RegisterAccessRepository();
            bool status = repp.IsValidAuthorizationCode(RegisterNewOrganizationView.AuthorizationCode);

            if (status == true)
            {
                UserAccessRepository rep = new UserAccessRepository();

                RegisterNewOrganizationView.UserAccount.Role = rep.GetRole(Guid.Parse("794C2858-17DB-462C-AB13-065B8F6719BF"));
                //RegisterNewOrganizationView.UserAccount.Person.Organization.Id = Guid.NewGuid();
                RegisterNewOrganizationView.UserAccount.Person.Organization.Address.Country = "Canada";
                RegisterNewOrganizationView.UserAccount.Person.Address = RegisterNewOrganizationView.UserAccount.Person.Organization.Address;
                // RegisterNewOrganizationView.UserAccount.Person.Organization.Url = "";

                if (repp.CreateOrganizationAccount(RegisterNewOrganizationView.UserAccount))
                {
                    MembershipCreateStatus createStatus;
                    MembershipUser         newUser = Membership.CreateUser(RegisterNewOrganizationView.UserAccount.Username, RegisterNewOrganizationView.UserAccount.Password, RegisterNewOrganizationView.UserAccount.Person.Email, "Q", "P", true, out createStatus);
                    RegisterNewOrganizationView.UserAccount.Person.Type = PersonType.ThirdParty;

                    switch (createStatus)
                    {
                    case MembershipCreateStatus.DuplicateUserName:
                        ViewData["Message"] = "Duplicate username! This username already exists in the system.";

                        break;

                    case MembershipCreateStatus.InvalidPassword:
                        ViewData["Message"] = "Invalid password! Minimum password length is six characters.";

                        break;

                    case MembershipCreateStatus.Success:
                        foreach (AvailableFunction func in RegisterNewOrganizationView.UserAccount.Role.AvailableFunctions)
                        {
                            System.Web.Security.Roles.AddUserToRole(RegisterNewOrganizationView.UserAccount.Username, func.FunctionName);
                        }

                        ViewData["Message"] = "Organization created succesfully!";
                        RegisterNewOrganizationView.UserAccount = null;
                        repp.DeleteAuthorizationCode(RegisterNewOrganizationView.AuthorizationCode);
                        ModelState.Clear();         //Will clear out the form
                        RegisterNewOrganizationView = null;
                        break;

                    default:
                        ViewData["Message"] = "There was an error creating this organization. Please contact the administrator.";
                        break;
                    }
                }
                else
                {
                    ViewData["Message"] = "There was an error creating this organization. Please contact the administrator.";
                }
            }


            else
            {
                ViewData["Message"] = "Authorization Code Is Invalid.Please try again or contact administrator.";
            }



            return(View("NewOrganization", RegisterNewOrganizationView));
        }