public async Task<IHttpActionResult> LogTabletStatus([FromBody] ReturnTabletStatus context) { if (!ModelState.IsValid) return BadRequest("Model sent was not valid."); using (var db = new Dal.DatabaseContext()) { if (!db.TabletSerials.Where(l => l.TabletSerialNumber == context.TabletSerial) .Any(l => l.HitchBotId == context.HitchBotId)) { return BadRequest("Tablet Serial Number is not registered to this hitchBOT OR Tablet Serial is invalid."); } db.TabletStatuses.Add(new TabletStatus(context) { BatteryPercentage = context.BatteryPercentage, BatteryTemp = context.BatteryTemp, BatteryVoltage = context.BatteryVoltage, IsCharging = context.IsCharging }); await db.SaveChangesAsync(); } return Ok(); }
public async Task<IHttpActionResult> LogSpeech([FromBody] ReturnSpeech context) { if (!ModelState.IsValid) return BadRequest("Model sent was not valid."); using (var db = new Dal.DatabaseContext()) { if (!db.TabletSerials.Where(l => l.TabletSerialNumber == context.TabletSerial) .Any(l => l.HitchBotId == context.HitchBotId)) { return BadRequest("Tablet Serial Number is not registered to this hitchBOT OR Tablet Serial is invalid."); } var speechEvent = new SpeechLogEvent(context) { Speech = context.SpeechData, EnvironmentType = context.EnvironmentType, MatchAccuracy = context.MatchAccuracy, RecognitionScore = context.RecognitionScore, GoogleRecognitionScore = context.GoogleRecognitionScore, ResponseScore = context.ResponseScore, RmsDecibalLevel = context.RmsDecibalLevel, RecognizerType = context.RecognizerType }; db.SpeechLogEvents.Add(speechEvent); db.SaveChanges(); return Ok(); } }
public async Task<IHttpActionResult> LogLocation([FromBody] ReturnLocation Context) { if (!ModelState.IsValid) return BadRequest("Model sent was not valid."); using (var db = new Dal.DatabaseContext()) { if (!db.TabletSerials.Where(l => l.TabletSerialNumber == Context.TabletSerial) .Any(l => l.HitchBotId == Context.HitchBotId)) { return BadRequest("Tablet Serial Number is not registered to this hitchBOT OR Tablet Serial is invalid."); } db.Locations.Add( new Models.Location(Context) { Latitude = Context.Latitude, Longitude = Context.Longitude, Altitude = Context.Altitude, Accuracy = Context.Accuracy, Velocity = Context.Velocity, LocationProvider = Context._LocationProvider }); await db.SaveChangesAsync(); } return Ok(); }
public static void BuildLocationJS(int HitchBotID) { using (var db = new Dal.DatabaseContext()) { var locations = db.Locations.Where(l => l.HitchBotId == HitchBotID).OrderBy(l => l.TakenTime).ToList(); var slimmedLocations = LocationHelper.SlimLocations(locations); string builder = "var flightPlanCoordinates = [ "; foreach (Models.Location myLocation in slimmedLocations) { builder += "\n new google.maps.LatLng(" + myLocation.Latitude + "," + myLocation.Longitude + "),"; } builder += @" ]; var flightPath = new google.maps.Polyline({ path: flightPlanCoordinates, geodesic: true, strokeColor: '#E57373', //taken from material design by google strokeOpacity: 1.0, strokeWeight: 2 }); function AddPolyFill(map){ flightPath.setMap(map); }"; System.IO.File.WriteAllText(Helpers.PathHelper.GetJsBuildPath() + Helpers.AzureBlobHelper.JS_LOCATION_FILE_NAME + Helpers.AzureBlobHelper.JS_FILE_EXTENSION, builder); } }
public async Task<IHttpActionResult> TestDatabase() { using (var db = new Dal.DatabaseContext()) { return Ok(db.Database.Exists()); } }
protected void Button1_Click(object sender, EventArgs e) { using (var db = new Dal.DatabaseContext()) { string userName = this.userName.Text; var user = db.LoginAccounts.FirstOrDefault(l => l.Username == userName); if (user == null) { //lblError.Text = "Username not found!"; this.errorAlert.Attributes.Remove("class"); this.errorAlert.Attributes.Add("class", "alert alert-danger"); this.errorAlert.InnerText = "Username not found!"; } else { if (string.IsNullOrWhiteSpace(user.PasswordHash)) { var newCred = Helpers.AccountHelper.GetNewHashAndSalt(passWord.Text); user.PasswordHash = newCred.Hash; user.Salt = newCred.Salt; db.SaveChanges(); } else if (!Helpers.AccountHelper.VerifyPassword(passWord.Text, user.Salt, user.PasswordHash)) { //lblError.Text = "Incorrect PW"; this.errorAlert.Attributes.Remove("class"); this.errorAlert.Attributes.Add("class", "alert alert-danger"); this.errorAlert.InnerText = "Incorrect PW"; return; } Session[SessionInfo.HitchBotId] = user.HitchBotId; Session["New"] = user; Response.Redirect("LandingPage.aspx"); } } }
protected void Build_Javascript_Coords() { using (var db = new Dal.DatabaseContext()) { currentLocation = db.Locations.Where(l => l.HitchBotId == HitchBotId) .Where(l => !l.HideFromProduction) .Where(l => l.LocationProvider == LocationProvider.SpotGPS) .OrderByDescending(l => l.TakenTime) .First(); var locations = db.CleverscriptContents .Where(k => k.HitchBotId == HitchBotId && k.Location != null) .Select(l => new { l.Location, l.CleverText, l.CleverscriptContext.HumanReadableBaseLabel, l.Id, l.EntryName, l.RadiusKm, l.isBucketList }).ToList(); var polys = db.CleverscriptContents.Include(l => l.PolgonVertices) .Where(l => l.HitchBotId == HitchBotId && l.Location == null) .Select(l => new { poly = l.PolgonVertices.Select(a => a.Location), l.CleverText, l.CleverscriptContext.HumanReadableBaseLabel, l.Id, l.EntryName, l.isBucketList }).ToList(); StringBuilder buildOutput = new StringBuilder(); buildOutput.Append(@"<script type=""text/javascript"">"); buildOutput.Append(@"var coords = ["); buildOutput.Append(string.Join(",\n", locations.Select(coord => string.Format("{{ coord : new google.maps.LatLng({0},{1}), radius : {2}, title : '{3}', content : '{4}', bucketList: {5}}}", coord.Location.Latitude, coord.Location.Longitude, coord.RadiusKm, "Id: " + coord.Id + " - " + coord.EntryName + " - " + coord.HumanReadableBaseLabel, EntryToParagraphs(coord.CleverText).Replace("'", "\'"), coord.isBucketList.ToString().ToLower())).ToList())); buildOutput.Append(@"];" + "\n"); buildOutput.Append(@"var polys = ["); buildOutput.Append(string.Join(",\n", polys.Select(coords => string.Format("{{ coord: [{0}], title : '{1}', content : '{2}', bucketList: {3}}}", string.Join(",", coords.poly.Select(loc => string.Format("new google.maps.LatLng({0},{1})", loc.Latitude, loc.Longitude))), "Id: " + coords.Id + " - " + coords.EntryName + " - " + coords.HumanReadableBaseLabel, EntryToParagraphs(coords.CleverText).Replace("'", "\'"), coords.isBucketList.ToString().ToLower() )))); buildOutput.Append(@"];"); buildOutput.Append(@"</script>"); coordsOutput.Text = buildOutput.ToString(); } }
protected void buttonSubmit_Click(object sender, EventArgs e) { try { var wikiEntry = inputWiki1.InnerText; var radius = inputRadiusValue.Value; var name = inputName.Value; var lat = inputLat.Value; var lng = inputLong.Value; double? radiusActual = null; double latActual; double lngActual; using (var db = new Dal.DatabaseContext()) { var user = (Models.LoginAccount)Session["New"]; var hitchbotId = user.HitchBotId; Models.Location location = null; Models.CleverscriptContext context = null; if (!bucketCheckBox.Checked) { var contextID = int.Parse(selectedLabelID.Value); context = db.CleverscriptContexts.FirstOrDefault(l => l.Id == contextID); if (context == null) { setErrorMessage("Error with the cleverscript label!!"); return; } } if (LocationCheckBox.Checked) { /* nullable double parse code borrowed from http://stackoverflow.com/questions/3390750/how-to-use-int-tryparse-with-nullable-int */ double tmp; if (!double.TryParse(radius, out tmp)) { setErrorMessage("Selected Radius is not valid!"); return; } radiusActual = tmp; if (!double.TryParse(lat, out latActual)) { setErrorMessage("Latitude is not valid number!"); return; } if (!double.TryParse(lng, out lngActual)) { setErrorMessage("Longitude is not valid number!"); return; } location = new Models.Location { Latitude = latActual, Longitude = lngActual, TimeAdded = DateTime.UtcNow, TakenTime = DateTime.UtcNow }; db.Locations.Add(location); db.SaveChanges(); } var wiki = new Models.CleverscriptContent { LocationId = location.Id, CleverText = wikiEntry, EntryName = name, RadiusKm = radiusActual, HitchBotId = hitchbotId, TimeAdded = DateTime.UtcNow, isBucketList = bucketCheckBox.Checked }; if (context != null) { wiki.CleverscriptContextId = context.Id; } db.CleverscriptContents.Add(wiki); db.SaveChanges(); } Response.Redirect("AddTargetSuccess.aspx"); } catch { setErrorMessage("An unknown error occurred. let the sys admin know you saw this message."); } }
protected void Page_Load(object sender, EventArgs e) { if (Session["New"] != null) { int hitchBotId = (int)Session[SessionInfo.HitchBotId]; using (var db = new Dal.DatabaseContext()) { var labels = db.CleverscriptContexts.Where(l => l.HitchBotId == hitchBotId).Select(l => new { l.Id, l.HumanReadableBaseLabel }).AsEnumerable(); labelLiterals.Text += string.Join("", labels.Select(l => string.Format(@"<li><a class=""fake-link label-option"" value=""{1}"">{0}</a></li>", l.HumanReadableBaseLabel, l.Id))); } } else { Response.Redirect("Unauthorized.aspx"); } }