Example #1
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);
        }