public async Task <IActionResult> PutSat(string id, Sat sat) { if (id != sat.Id) { return(BadRequest()); } _context.Entry(sat).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SatExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <Sat> > PostSat(Sat sat) { _context.Sats.Add(sat); try { await _context.SaveChangesAsync(); } catch (DbUpdateException) { if (SatExists(sat.Id)) { return(Conflict()); } else { throw; } } return(CreatedAtAction("GetSat", new { id = sat.Id }, sat)); }
public async Task <bool> AddRxLine(string rxLine) { try { string[] words = rxLine.Split(' ', StringSplitOptions.RemoveEmptyEntries); string[] words1 = words[1].Split('-'); DateTimeOffset satTime = DateTimeOffset.FromUnixTimeSeconds(Convert.ToInt64(words1[1])).AddMilliseconds(Convert.ToInt64(words[2])).ToLocalTime(); long utcTicks = satTime.ToUniversalTime().UtcTicks; int quality = Convert.ToInt32(words[4].TrimEnd('%')); int satNo; //Debug.WriteLine("{0} {1}", words[0], satTime); if (words[0] == "IRA:") { //Debug.WriteLine("{0} {1} {2}", words[0], satTime, utcTicks); Ira ira = new Ira { Id = rxLine, Time = satTime, UtcTicks = utcTicks, Quality = quality }; //sat:26 -> [8] satNo = Convert.ToInt32(words[8].Substring(4)); ira.SatNo = satNo; //beam:44 -> [9] ira.Beam = Convert.ToInt32(words[9].Substring(5)); //pos=(+51.18/-068.82) -> [10] string[] words2 = words[10].Split('(', '/', ')'); ira.Lat = Convert.ToDouble(words2[1]); ira.Lon = Convert.ToDouble(words2[2]); //alt=796 -> [11] ira.Alt = Convert.ToDouble(words[11].Substring(4)); _context.Iras.Add(ira); try { await _context.SaveChangesAsync(); } catch (DbUpdateException) { return(false); } } else if (words[0] == "IBC:") { Ibc ibc = new Ibc { Id = rxLine, Time = satTime, UtcTicks = utcTicks, Quality = quality }; //sat:26 -> [9] satNo = Convert.ToInt32(words[9].Substring(4)); ibc.SatNo = satNo; //cell:31 -> [10] ibc.Cell = Convert.ToInt32(words[10].Substring(5)); _context.Ibcs.Add(ibc); try { await _context.SaveChangesAsync(); } catch (DbUpdateException) { return(false); } } else { return(false); } Sat sat = new Sat { Id = Guid.NewGuid().ToString(), SatNo = satNo, Name = satNo.ToString() }; if (!SatExists(satNo)) { _context.Sats.Add(sat); try { await _context.SaveChangesAsync(); } catch (DbUpdateException ex) { Debug.WriteLine(ex.Message); return(false); } } return(true); } catch (Exception ex) { Debug.WriteLine(ex.Message); return(false); } }