public static Tracking ToEntity(this TrackingBinding tb, Tracking t = null) { t = t.DefaultIfNull(); t.Accuracy = tb.Accuracy.HasValue ? (double)Math.Round(tb.Accuracy.Value, 2) : (double?)null; t.Altitude = tb.Altitude.HasValue ? (double)Math.Round(tb.Altitude.Value, 2) : (double?)null; t.Latitude = tb.Latitude; t.Longitude = tb.Longitude; t.Speed = tb.Speed.HasValue ? (double)Math.Round(tb.Speed.Value, 2) : (double?)null; t.Timestamp = tb.Timestamp; return(t); }
public bool Create(TrackingBinding binding) { using (var db = GetMainContext()) { var geohasher = new Geohasher(); var tracking = binding.ToEntity(); tracking.Geohash = geohasher.Encode((double)binding.Latitude, (double)binding.Longitude, 9); tracking.UserId = UserId; db.Trackings.Add(tracking); db.SaveChanges(); return(true); } }
public bool Put([FromBody] TrackingBinding binding) => _trackingHandler.Create(binding);