Пример #1
0
        public async Task <IActionResult> Get([FromRoute] string panelId)
        {
            var panel = _panelRepository.Query()
                        .Where(x => x.Serial.Equals(panelId, StringComparison.CurrentCultureIgnoreCase));

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

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

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

            return(Ok(result));
        }
Пример #2
0
        public async Task <IActionResult> Get([FromRoute] string panelId)
        {
            if (string.IsNullOrWhiteSpace(panelId))
            {
                return(BadRequest());
            }
            if (panelId.Trim().Length != 16)
            {
                return(BadRequest("Panel ID should have 16 characters"));
            }
            var panel = await _panelRepository.Query()
                        .FirstOrDefaultAsync(x => x.Serial.Equals(panelId, StringComparison.CurrentCultureIgnoreCase));

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

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

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

            return(Ok(result));
        }
Пример #3
0
        public async Task <IActionResult> Get([FromRoute] int panelId)
        {
            var panel = await _panelRepository.Query()
                        .FirstOrDefaultAsync(x => x.Serial.Equals(panelId));

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

            var analytics = await _analyticsRepository.Query()
                            .Where(x => x.PanelId.Equals(panelId)).ToListAsync();

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

            return(Ok(result));
        }
Пример #4
0
        public async void QueryPanles()
        {
            var panel = new Panel
            {
                Brand     = "Areva",
                Latitude  = 12.345678,
                Longitude = 98.7655432,
                Serial    = "AAAA1111BBBB2222"
            };

            _testDBContext.Add(panel);
            await _testDBContext.SaveChangesAsync();

            var result = await _panelRepository.Query().ToListAsync();

            Assert.True(result.Count > 0);
        }
        public async Task <IActionResult> GetPanelsAsync()
        {
            var panels = _panelRepository.Query();

            return(Ok(panels));
        }
Пример #6
0
 private async Task <IActionResult> CheckPanelId(string panelId)
 {
     return(await _panelRepository.Query()
            .FirstOrDefaultAsync(x => x.Serial.Equals(panelId, StringComparison.CurrentCultureIgnoreCase)) == null
         ? NotFound() : null);
 }