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(); } }
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 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."); } }