Exemplo n.º 1
0
        public async Task Post([FromBody] GrazingDto value)
        {
            var grazing = new Grazing
            {
                Coordinates = value.Coordinates
                              .Select(x => new Coordinate
                {
                    Longitude = x.Longitude,
                    Latitude  = x.Latitude
                }).ToList()
            };

            await _context.Grazings.AddAsync(grazing);

            await _context.SaveChangesAsync();
        }
Exemplo n.º 2
0
        public async Task<ActionResult> Post([FromBody] Rootobject rootobject)
        {
            var playload = Convert.FromBase64String(rootobject.PayloadRaw);

            var cow = await _context.Cows.FirstOrDefaultAsync(x => x.HardwareSerial == rootobject.HardwareSerial);
            if (cow == null)
            {
                cow = new Cow
                {
                    Name = "Marguerite",
                    HardwareSerial = rootobject.HardwareSerial
                };

                await _context.Cows.AddAsync(cow);
            }

            var dateTime = new DateTime(rootobject.Metadata.Time.Ticks, DateTimeKind.Utc);

            var gpsEntry = new GpsEntry
            {
                Cow = cow,
                DateTime = dateTime,
                LatitudeDeg = Convert.ToInt32(playload[0]),
                LatitudeMinutes = Convert.ToInt32(playload[1]),
                LatitudeMinutesDecimals = Convert.ToInt32($"{Convert.ToInt32(playload[2]):00}" + $"{Convert.ToInt32(playload[3]):00}"),
                LatitudeDirection = Convert.ToChar(playload[4]),
                LongitudeDeg = Convert.ToInt32(playload[5]),
                LongitudeMinutes = Convert.ToInt32(playload[6]),
                LongitudeMinutesDecimals = Convert.ToInt32($"{Convert.ToInt32(playload[7]):00}" + $"{Convert.ToInt32(playload[8]):00}"),
                LongitudeDirection = Convert.ToChar(playload[9])
            };

            cow.GpsEntries.Add(gpsEntry);

            var temperatureEntry = new TemperatureEntry
            {
                Cow = cow,
                DateTime = dateTime,
                Temperature = Convert.ToSingle(Convert.ToInt32(playload[10]) + "." + Convert.ToInt32(playload[11]))
            };

            cow.TemperatureEntries.Add(temperatureEntry);

            var positionEntry = new PositionEntry
            {
                Cow = cow,
                DateTime = dateTime,
                IsUp = Convert.ToBoolean(Convert.ToInt32(playload[12])),
                X = Convert.ToInt32(playload[13]),
                Y = Convert.ToInt32(playload[14]),
                Z = Convert.ToInt32(playload[15])
            };

            cow.PositionEntries.Add(positionEntry);

            await _context.SaveChangesAsync();

            return Ok();
        }
Exemplo n.º 3
0
        public async Task <IActionResult> ClearGpsEntries(long?gpsEntryId)
        {
            var gpsEntries = await _context.GpsEntries
                             .Where(x => !gpsEntryId.HasValue || gpsEntryId.Value == x.Id)
                             .ToListAsync();

            foreach (var gpsEntry in gpsEntries)
            {
                _context.Remove(gpsEntry);
            }

            await _context.SaveChangesAsync();

            return(Ok());
        }