コード例 #1
0
        public async Task <IActionResult> GetAllDailyResourceUsage()
        {
            var currentBillingPeriod = await _billRepository.GetCurrentBillingPeriod();

            if (this.UserInRole(Role.Tenant))
            {
                var userId   = this.UserIdFromApiKey();
                var tenantId = await _tenantRepository.TenantIdFromUserId(userId);

                if (tenantId == null)
                {
                    var err = new DTO.ErrorBuilder()
                              .Message("Not a tenant")
                              .Code(400)
                              .Build();
                    return(err);
                }

                var usages = await _billRepository.GetDailyResourceUsage((int)tenantId, currentBillingPeriod);

                return(new ObjectResult(usages));
            }
            else
            {
                var err = new DTO.ErrorBuilder()
                          .Message("You are not authorized to view resource usage.")
                          .Code(403)
                          .Build();
                _logger.LogWarning($"Unauthorized access attempt to view resource usage.");
                return(err);
            }
        }