public bool AddFeedback(string feedbackTypeStr, string phoneid, string textmessage, double reporttype, double lat, double lon, ref string errorMessage, ref long newid) { bool retVal = true; try { using (COPDBContext.monica_cnetContext context = new COPDBContext.monica_cnetContext()) { //Find type var FeedbackType = context.ProAcousticFeedbackTypes .Single(b => b.Name == feedbackTypeStr); if (FeedbackType == null) { errorMessage = "Non-Existing Feedback type"; retVal = false; } else { ProAcousticFeedback a = new ProAcousticFeedback(); a.ProAcousticFeedbackType = FeedbackType.Id; a.ReportType = reporttype; a.Textmessage = textmessage; a.Phoneid = phoneid; a.Lat = lat; a.Lon = lon; context.ProAcousticFeedback.Add(a); context.SaveChanges(); newid = a.Id; } } return(retVal); } catch (Exception e) { errorMessage = "Database Excaption:" + e.Message + " " + e.StackTrace; return(false); } }
public virtual IActionResult ProacousticfeedbackPost([FromBody] ProAcousticFeedback pubfeedback, [FromHeader] string Authorization) { { if (!ModelState.IsValid) { var error = ModelState.SelectMany(x => x.Value.Errors).First(); if (error.ErrorMessage != null && error.ErrorMessage != String.Empty) { return(BadRequest(error.ErrorMessage)); } else if (error.Exception?.Message != null) { return(BadRequest("Faulty input")); } else { return(BadRequest(ModelState)); } } long newThingID = 0; string errorMessage = ""; try { DatabaseInterface.DBProfAcousticFeedback dBpaf = new DatabaseInterface.DBProfAcousticFeedback(); if (!dBpaf.AddFeedback(pubfeedback.FeedbackType, pubfeedback.Phoneid, pubfeedback.FeedbackMessage, (double)pubfeedback.FeedbackValue, (double)pubfeedback.FeedbackLat, (double)pubfeedback.FeedbackLon, ref errorMessage, ref newThingID)) { return(BadRequest("Internal Server Error:" + errorMessage)); } else { dynamic message = new JObject(); message.type = "new"; message.SoundIncidentsId = newThingID; message.timestamp = DateTime.Now; string strMessage = message.ToString(); _hubContext.Clients.All.SendAsync("SoundIncidents", strMessage); } } catch (Exception e) { return(BadRequest("Internal Server Error:" + e.Message)); } //TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ... // return StatusCode(200, default(GeneralResponse)); //TODO: Uncomment the next line to return response 0 or use other options such as return this.NotFound(), return this.BadRequest(..), ... // return StatusCode(0, default(ErrorResponse)); string exampleJson = null; exampleJson = "{\n \"success\" : true,\n \"newid\" : " + newThingID.ToString() + "\n}"; var example = exampleJson != null ? JsonConvert.DeserializeObject <GeneralPostResponse>(exampleJson) : default(GeneralPostResponse); //TODO: Change the data returned return(new ObjectResult(example)); } }