Exemplo n.º 1
0
        public ActionResult DeleteRole(int hierarchyLevelTypeId, int administratorRoleId, string id, FormCollection collection)
        {
            AdministratorRoleHierarchyLevelTypeSystemUser administratorRoleHierarchyLevelTypeSystemUser = new AdministratorRoleHierarchyLevelTypeSystemUser();

            administratorRoleHierarchyLevelTypeSystemUser = systemUserRepository.GetUserRole(administratorRoleId, hierarchyLevelTypeId, id);

            //Get SystemUser
            SystemUser systemUser = new SystemUser();

            systemUser = systemUserRepository.GetUserBySystemUserGuid(administratorRoleHierarchyLevelTypeSystemUser.SystemUserGuid);

            //Check Exists
            if (systemUser == null)
            {
                ViewData["ActionMethod"] = "DeletePost";
                return(View("RecordDoesNotExistError"));
            }

            //AccessRights
            RolesRepository rolesRepository = new RolesRepository();

            if (!rolesRepository.HasWriteAccessToSystemUserRoles(administratorRoleHierarchyLevelTypeSystemUser.SystemUserGuid))
            {
                ViewData["Message"] = "You do not have access to this item";
                return(View("Error"));
            }
            try{
                administratorRoleHierarchyLevelTypeSystemUser.VersionNumber = Int32.Parse(collection["VersionNumber"]);
                systemUserRepository.DeleteRole(administratorRoleHierarchyLevelTypeSystemUser);
            }
            catch (SqlException ex)
            {
                logRepository.LogError(ex.Message);

                ViewData["Message"] = "There was a problem with your request, please see the log file or contact an administrator for details";
                return(View("Error"));
            }



            //Return
            ViewData["NewSortOrder"] = 0;
            return(RedirectToAction("ListRoles", new { id = administratorRoleHierarchyLevelTypeSystemUser.SystemUserGuid }));
        }