Exemplo n.º 1
0
 public async Task <IActionResult> GetRoles()
 {
     return(await employeeRoles.FetchEmployeeRoles(0, 2000)
            .OnSuccess(e => e.HasValue ? e.Value : new List <EmployeeRole>())
            .OnBoth(e => e.IsFailure ? StatusCode(500, "") : StatusCode(200, e.Value))
            .ConfigureAwait(false));
 }
Exemplo n.º 2
0
        private async Task <bool> FetchData(int employeeId)
        {
            Employee = await userManager.GetUserAsync(User).ConfigureAwait(false);

            Role = await roleManager.FindByIdAsync(Employee.RoleId.ToString()).ConfigureAwait(false);

            if (!Role.CanAdministerCompany)
            {
                return(false);
            }

            var employee = (await employees.FetchEmployee(employeeId).ConfigureAwait(false))
                           .Ensure(e => e.HasValue, "Employee found")
                           .OnSuccess(e => e.Value);

            if (employee.IsFailure)
            {
                return(false);
            }

            if (employee.Value.CompanyId != Employee.CompanyId && !Role.CanAdministerSystem)
            {
                return(false);
            }

            EditingEmployee = employee.Value;
            Title           = employee.Value.EmployeeName;

            var allRoles = await roles.FetchEmployeeRoles(0, int.MaxValue)
                           .Ensure(t => t.HasValue, "Roles were found")
                           .OnSuccess(t => t.Value)
                           .OnBoth(t => t.IsSuccess ? t.Value : new List <EmployeeRole>())
                           .ConfigureAwait(false);

            Roles = allRoles.Where(r => !r.IsMorePrivilegedThanRole(Role)).ToList();

            Input ??= new InputModel
            {
                EmployeeName = employee.Value.EmployeeName,
                Username     = employee.Value.Username
            };

            return(true);
        }
Exemplo n.º 3
0
        private async Task <bool> FetchData(int?companyId)
        {
            Employee = await userManager.GetUserAsync(User).ConfigureAwait(false);

            Role = await roleManager.FindByIdAsync(Employee.RoleId.ToString()).ConfigureAwait(false);

            if (Employee.CompanyId != companyId && !Role.CanAdministerSystem)
            {
                return(false);
            }

            Venues = await venues.FetchVenueItems(Role.CanAdministerSystem?null : companyId)
                     .Ensure(t => t.HasValue, "Venue items were found")
                     .OnSuccess(t => t.Value)
                     .OnBoth(t => t.IsSuccess ? t.Value : new List <VenueItem>())
                     .ConfigureAwait(false);

            if (Role.CanAdministerSystem)
            {
                Companies = await companies.FetchCompanies(0, int.MaxValue)
                            .Ensure(t => t.HasValue, "Companies were found")
                            .OnSuccess(t => t.Value)
                            .OnBoth(t => t.IsSuccess ? t.Value : new List <Company>())
                            .ConfigureAwait(false);
            }

            var allRoles = await roles.FetchEmployeeRoles(0, int.MaxValue)
                           .Ensure(t => t.HasValue, "Roles were found")
                           .OnSuccess(t => t.Value)
                           .OnBoth(t => t.IsSuccess ? t.Value : new List <EmployeeRole>())
                           .ConfigureAwait(false);

            Roles = allRoles.Where(r => !r.IsMorePrivilegedThanRole(Role)).ToList();

            return(Role.CanAdministerCompany);
        }