Example #1
0
        public async Task <IActionResult> Get([FromRoute] string panelId)
        {
            var panel = await _panelRepository.GetAsync(panelId); //Changed the Query() to GetAsync()

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

            var analytics = _analyticsRepository.Query().Where(x => x.PanelId.Equals(panelId, StringComparison.CurrentCultureIgnoreCase)).AsEnumerable();

            var result = new OneHourElectricityListModel
            {
                OneHourElectricitys = analytics.Select(c => new OneHourElectricityModel
                {
                    Id       = c.Id,
                    KiloWatt = c.KiloWatt,
                    DateTime = c.DateTime
                }).ToList()
            };

            return(Ok(result));
        }
        public async Task <IActionResult> Get([FromRoute] int panelId)
        {
            var panel = await _panelRepository.GetAsync(panelId);

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

            var analytics = await _analyticsRepository.GetByPanelId(panelId);

            var result = new OneHourElectricityListModel
            {
                OneHourElectricitys = analytics.Select(c => new OneHourElectricityModel
                {
                    Id       = c.Id,
                    KiloWatt = c.KiloWatt,
                    DateTime = c.DateTime
                })
            };

            return(Ok(result));
        }