Exemplo n.º 1
0
        public async Task <ActionResult> EnvironmentCosts(string environmentName, [FromQuery] DateTimeOffset?from, [FromQuery] DateTimeOffset?to)
        {
            var environment = await _environmentCoordinator.GetEnvironment(environmentName);

            if (environment == null)
            {
                return(NotFound());
            }

            var period = new CostPeriod(nameof(EnvironmentCosts), Url, from, to);

            var cost = await _costCoordinator.GetCost(environment, period.QueryTimePeriod);

            cost.CurrentMonthLink  = period.GetCurrentMonthLink();
            cost.NextMonthLink     = period.GetNextMonthLink();
            cost.PreviousMonthLink = period.GetPrevMonthLink();

            return(Ok(cost));
        }
        public async Task <ActionResult> Index([FromQuery] DateTimeOffset?from, [FromQuery] DateTimeOffset?to)
        {
            var envs = (await Environments()).Where(env => !env.InProgress);

            var period = new CostPeriod(nameof(Index), Url, from, to);

            var nextMonthLink    = period.GetNextMonthLink();
            var currentMonthLink = period.GetCurrentMonthLink();
            var prevMonthLink    = period.GetPrevMonthLink();

            return(View(
                       new IndexModel(
                           period.QueryTimePeriod.From,
                           period.QueryTimePeriod.To,
                           envs,
                           nextMonthLink,
                           currentMonthLink,
                           prevMonthLink)));
        }
Exemplo n.º 3
0
        public async Task <ActionResult> AllCosts([FromQuery] DateTimeOffset?from, [FromQuery] DateTimeOffset?to)
        {
            var envs = (await Environments()).Where(env => !env.InProgress);

            var period = new CostPeriod(nameof(AllCosts), Url, from, to);

            var usages = await Task.WhenAll(envs
                                            .Where(env => !env.InProgress)
                                            .Select(env => _costCoordinator.GetCost(env, period.QueryTimePeriod)));

            var squishedCosts = usages?.Where(u => u.Cost != null).Select(u => u.Cost.Recategorize(u.EnvironmentId));

            var summaryCost = CalculateSummarySafely(squishedCosts);

            return(Ok(new EnvironmentCost("Total Costs", summaryCost)
            {
                CurrentMonthLink = period.GetCurrentMonthLink(),
                NextMonthLink = period.GetNextMonthLink(),
                PreviousMonthLink = period.GetPrevMonthLink(),
            }));
        }