コード例 #1
0
        public async Task <IActionResult> Register([FromBody] PanelModel value)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                var panel = new Panel
                {
                    Latitude  = value.Latitude,
                    Longitude = value.Longitude,
                    Serial    = value.Serial,
                    Brand     = value.Brand
                };

                await _panelRepository.InsertAsync(panel);

                return(Created($"panel/{panel.Id}", panel));
            }
            catch (System.Exception)
            {
                throw;
            }
        }
コード例 #2
0
        public async Task GetPanelsByPanelId_ShouldGetPanelist()
        {
            // Arrange
            var id = 1;
            await _analyticsRepository.GetAsync(id);

            var temp = new OneHourElectricity()
            {
                KiloWatt = 1,
                PanelId  = "AAAA1111BBBB2222",
                DateTime = DateTime.Now
            };
            await _analyticsRepository.InsertAsync(temp);

            // Act
            _analyticsRepository.GetOneDayMetrics(temp.PanelId);
            var panel = new Panel
            {
                Brand     = "Areva",
                Latitude  = 12.345678,
                Longitude = 98.7655432,
                Serial    = "AAAA1111BBBB2222"
            };
            await _panelRepository.InsertAsync(panel);

            // Act
            var result = _panelRepository.GetPanelsByPanelId(panel.Serial);

            // Assert
            Assert.NotNull(result);
        }
コード例 #3
0
        public async void RegisterNewPanels()
        {
            var panel = new Panel
            {
                Brand     = "Areva",
                Latitude  = 12.345678,
                Longitude = 98.7655432,
                Serial    = "AAAA1111BBBB2222"
            };

            await _panelRepository.InsertAsync(panel);
        }
コード例 #4
0
        public async Task <IActionResult> Register([FromBody] PanelModel item)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var panel = new Panel
            {
                Latitude  = item.Latitude,
                Longitude = item.Longitude,
                Serial    = item.Serial,
                Brand     = item.Brand
            };

            await _panelRepository.InsertAsync(panel);

            return(Created($"panel/{panel.Id}", panel));
        }
コード例 #5
0
        public async Task <IActionResult> Register([FromBody] PanelModel value)
        {
            try
            {
                Regex regexObj = new Regex(@"-?\d{1,2}\.\d{6}");

                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                if (!regexObj.Match(value.Latitude.ToString(CultureInfo.InvariantCulture)).Success)
                {
                    return(BadRequest(ModelState));
                }

                if (!regexObj.Match(value.Longitude.ToString(CultureInfo.InvariantCulture)).Success)
                {
                    return(BadRequest(ModelState));
                }

                var panel = new Panel
                {
                    Latitude  = Convert.ToDouble(value.Latitude),
                    Longitude = Convert.ToDouble(value.Longitude),
                    Serial    = value.Serial,
                    Brand     = value.Brand
                };

                await _panelRepository.InsertAsync(panel);

                return(Created($"panel/{panel.Id}", panel));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #6
0
        public async Task <IActionResult> Register([FromBody] PanelModel value)
        {
            if (value.Serial.Length != 16)
            {
                return(BadRequest("Invalid Serial Number"));
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var panel = new Panel
            {
                Latitude  = value.Latitude,
                Longitude = value.Longitude,
                Serial    = value.Serial,
                Brand     = value.Brand
            };

            await _panelRepository.InsertAsync(panel);

            return(Created($"panel/{panel.Id}", panel));
        }
コード例 #7
0
        public async Task <IActionResult> Register([FromBody] PanelModel value)
        {
            //if (!ModelState.IsValid) return BadRequest(ModelState);
            var context = new ValidationContext(value, null, null);
            var result  = new List <ValidationResult>();
            var valid   = Validator.TryValidateObject(value, context, result, true);

            if (!valid)
            {
                return(BadRequest(ModelState));
            }

            var panel = new Panel
            {
                Latitude  = value.Latitude,
                Longitude = value.Longitude,
                Serial    = value.Serial,
                Brand     = value.Brand
            };

            await _panelRepository.InsertAsync(panel);

            return(Created($"panel/{panel.Id}", panel));
        }