Exemplo n.º 1
0
        public async Task <IActionResult> Index(string search = "")
        {
            var hasPermission = await _accessManager.HasPermission(User.Identity.Name, _organizationSubsystemName);

            if (hasPermission)
            {
                var userData = await _userData.GetUserData(User.Identity.Name);

                var isAdmin = await _accessManager.IsAdmin(userData.Id);

                var organizations = _organizationService.GetAll();
                search ??= "";

                if (!isAdmin)
                {
                    var id = userData.Organization.Id;
                    return(RedirectToAction("Details", "Organization", new { organizationId = id }));
                }

                var organizationTableViewModels = organizations
                                                  .Select(o =>
                {
                    string userName = null;
                    string phone    = null;
                    if (o.User != null)
                    {
                        userName = $"{o.User.LastName} {o.User.Name} {o.User.Patronymic}";
                        phone    = o.User.Phone;
                    }

                    return(new OrganizationTableViewModel()
                    {
                        Id = o.Id,
                        Name = o.Name,
                        UserName = userName,
                        UserPhone = phone
                    });
                })
                                                  .Where(o =>
                {
                    if (o.UserName != null)
                    {
                        return(o.Name.Contains(search, StringComparison.OrdinalIgnoreCase) ||
                               o.UserName.Contains(search, StringComparison.OrdinalIgnoreCase));
                    }

                    return(o.Name.Contains(search, StringComparison.OrdinalIgnoreCase));
                });

                var organizationMasterViewModel = new OrganizationMasterViewModel()
                {
                    Organizations = organizationTableViewModels,
                    SearchString  = search
                };

                return(View(organizationMasterViewModel));
            }

            return(Forbid(CookieAuthenticationDefaults.AuthenticationScheme));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Index()
        {
            var hasPermission = await _accessManager.HasPermission(User.Identity.Name, _adminSubsystemName);

            if (hasPermission)
            {
                var users = _userDataService.GetAllUsers();
                var roles = _userDataService.GetAllRoles();

                var userViewModel = users.Select(u => new UserViewModel()
                {
                    Id       = u.Id,
                    Email    = u.Email,
                    Name     = $"{u.LastName} {u.Name} {u.Patronymic}",
                    Roles    = string.Join(", ", _userDataService.GetUserRoles(u.Id).Result),
                    Accesses = string.Join(", ", _accessManager.GetAccessibleSubsystems(u.Id).Result)
                });

                var roleViewModel = roles.Select(r => new RoleViewModel()
                {
                    Name = r,
                    AccessibleSubsystems = string.Join(", ", _accessManager.GetAccessibleSubsystemsByRole(r).Result)
                });

                var adminViewModel = new AdminViewModel()
                {
                    RoleViewModels = roleViewModel,
                    UserViewModels = userViewModel
                };

                return(View(adminViewModel));
            }

            return(Forbid(CookieAuthenticationDefaults.AuthenticationScheme));
        }
        public async Task <IActionResult> Index(string userSearch = "", string roleSearch = "", string positionSearch = "")
        {
            var hasPermission = await _accessManager.HasPermission(User.Identity.Name, _adminSubsystemName);

            if (hasPermission)
            {
                var users     = _userDataService.GetAllUsers();
                var roles     = _userDataService.GetAllRoles();
                var positions = _positionService.GetAll();
                userSearch ??= "";
                roleSearch ??= "";
                positionSearch ??= "";

                var userViewModel = users
                                    .Select(u => new UserViewModel()
                {
                    Id       = u.Id,
                    Email    = u.Email,
                    Name     = $"{u.LastName} {u.Name} {u.Patronymic}",
                    Roles    = string.Join(", ", _userDataService.GetUserRoles(u.Id).Result),
                    Accesses = string.Join(", ", _accessManager.GetAccessibleSubsystems(u.Id).Result)
                })
                                    .Where(u =>
                                           u.Name.Contains(userSearch, StringComparison.OrdinalIgnoreCase) ||
                                           u.Email.Contains(userSearch, StringComparison.OrdinalIgnoreCase));

                var roleViewModel = roles
                                    .Select(r => new RoleViewModel()
                {
                    Name = r,
                    AccessibleSubsystems = string.Join(", ", _accessManager.GetAccessibleSubsystemsByRole(r).Result)
                })
                                    .Where(r => r.Name.Contains(roleSearch, StringComparison.OrdinalIgnoreCase));

                var positionViewModel = positions
                                        .Select(p => new PositionViewModel()
                {
                    Id   = p.Id,
                    Name = p.Name
                })
                                        .Where(p => p.Name.Contains(positionSearch, StringComparison.OrdinalIgnoreCase));

                var adminViewModel = new AdminViewModel()
                {
                    RoleViewModels     = roleViewModel,
                    UserViewModels     = userViewModel,
                    PositionViewModels = positionViewModel,
                    UserSearch         = userSearch,
                    PositionSearch     = positionSearch,
                    RoleSearch         = roleSearch
                };

                return(View(adminViewModel));
            }

            return(Forbid(CookieAuthenticationDefaults.AuthenticationScheme));
        }
Exemplo n.º 4
0
 protected override void OnActionExecuting(ActionExecutingContext filterContext)
 {
     base.OnActionExecuting(filterContext);
     if (!accessManager.HasPermission(HttpContext))
     {
         //filterContext.Result = new RedirectResult("/Account/Login");
     }
 }
Exemplo n.º 5
0
        public async Task <IActionResult> Index()
        {
            var hasPermission = await _accessManager.HasPermission(User.Identity.Name, _organizationSubsystemName);

            if (hasPermission)
            {
                var userData = await _userData.GetUserData(User.Identity.Name);

                var isAdmin = await _accessManager.IsAdmin(userData.Id);

                var organizations = _organizationService.GetAll();

                if (!isAdmin)
                {
                    var id = userData.Organization.Id;
                    return(RedirectToAction("Details", "Organization", new { organizationId = id }));
                }

                var organizationViewModel = organizations.Select(o =>
                {
                    string userName = null;
                    string phone    = null;
                    if (o.User != null)
                    {
                        userName = $"{o.User.LastName} {o.User.Name} {o.User.Patronymic}";
                        phone    = o.User.Phone;
                    }

                    return(new OrganizationTableViewModel()
                    {
                        Id = o.Id,
                        Name = o.Name,
                        UserName = userName,
                        UserPhone = phone
                    });
                });

                return(View(organizationViewModel));
            }

            return(Forbid(CookieAuthenticationDefaults.AuthenticationScheme));
        }
Exemplo n.º 6
0
        public async Task <IActionResult> Registration()
        {
            var hasPermission = await _accessManager.HasPermission(User.Identity.Name, _adminSubsystem);

            if (hasPermission)
            {
                var roles   = _userData.GetAllRoles();
                var options = roles.Select(r => new Option()
                {
                    Name = r
                }).ToList();
                var viewModel = new RegistrationViewModel()
                {
                    Roles = options
                };
                return(View(viewModel));
            }

            return(Forbid(CookieAuthenticationDefaults.AuthenticationScheme));
        }