예제 #1
0
        public async Task <IActionResult> OnGetAsync(int companyId)
        {
            Employee = await userManager.GetUserAsync(User).ConfigureAwait(false);

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

            CompanyId = companyId;

            if (!Role.CanAdministerSystem && Employee.CompanyId != companyId)
            {
                return(RedirectToPage("/Index"));
            }

            if (!Role.CanAdministerVenue)
            {
                return(RedirectToPage("/Index"));
            }

            var task = string.IsNullOrWhiteSpace(Query)
                ? venues.FetchCountedCompanyVenues(companyId, PageNumber, 20)
                : venues.FetchCountedQueriedCompanyVenues(companyId, Query, PageNumber, 20);

            var results = (await task.ConfigureAwait(false))
                          .Ensure(e => e.HasValue, "Venues found")
                          .OnSuccess(e => e.Value)
                          .OnBoth(e => e.IsSuccess ? e.Value : new PaginatedResult <Venue> {
                Data = new List <Venue>(), Count = 0
            });

            TotalResults = results.Count;
            Venues       = results.Data;
            Title        = $"Venues ({TotalResults})";
            HasNextPage  = (PageNumber + 1) <= (TotalResults / 20);

            return(Page());
        }