示例#1
0
        public UserManagerViewModel GetUsers(ContextModel context)
        {
            var    userManager      = new UserManagerViewModel();
            string usernameCustomer = null;

            if (context.User.Role != enRole.Administrator && context.User.Role != enRole.Demo)
            {
                usernameCustomer = context.User.Username;
            }

            var usersModel = _userManagerService.GetUsers(usernameCustomer);

            if (context.User.Role == enRole.Demo)
            {
                usersModel = _userManagerService.FilterRoleUsers(context.User.Role, usersModel);
            }

            // users
            userManager.users = usersModel.Select(s => new UserViewModel
            {
                ID             = s.ID,
                Username       = s.Username,
                FirstName      = s.FirstName,
                LastName       = s.LastName,
                Email          = s.Email,
                CustomerName   = s.CustomerName,
                RoleCode       = (int)s.Role,
                RoleName       = LocalizationService.GetResource(s.Role.GetDescription()),
                LanguageId     = s.Language.ID,
                LanguageName   = s.Language.Name,
                Enabled        = s.Enabled,
                MachineSerials = s.Machines.Select(sel => sel.Serial).ToList(),
                TimeZone       = s.TimeZone
            }).ToList();

            //roles
            var rolesModel = _userManagerService.GetRoles();

            userManager.roles = rolesModel.Select(s => new UserRoleViewModel
            {
                Code    = s.Code,
                Name    = LocalizationService.GetResource(s.Name),
                status  = s.status,
                enabled = s.enabled
            }).ToList();

            //customers
            userManager.customers = _userManagerService.GetCustomerNames();

            //machines
            if (context.User.Role == enRole.Customer)
            {
                var machinesModel = _userManagerService.GetCustomerMachines(usernameCustomer);
                userManager.machines = machinesModel.Select(s => new UserMachineViewModel {
                    Id = s.Id, Serial = s.Serial, MachineName = s.MachineName
                }).ToList();
            }

            //languages
            var languagesModel = _userManagerService.GetLanguages();

            userManager.languages = languagesModel.Select(s => new UserLanguageViewModel {
                Id = s.ID, Name = s.Name
            }).ToList();

            return(userManager);
        }