public HttpResponseMessage GetImage(Guid predictionId) { using (var db = new DogsVsCatsEntities()) { var prediction = db.Predictions.First(p => p.Id == predictionId); HttpResponseMessage response = new HttpResponseMessage(); response.Content = new StreamContent(new MemoryStream(prediction.Data)); response.Content.Headers.ContentType = new MediaTypeHeaderValue(prediction.ContentType); return(response); } }
public IList <PredictionResult> Get() { using (var db = new DogsVsCatsEntities()) { return(db.Predictions .OrderByDescending(p => p.CreatedOn) .Select( p => new PredictionResult() { Id = p.Id, DogProbability = p.DogProbability, CatProbability = p.CatProbability }) .Take(20) .ToList()); } }
private void PredictAndSaveRequest(MultipartParser parser) { using (var db = new DogsVsCatsEntities()) { Predictor predictor = new Predictor(); var predictionResult = predictor.PredictImage(parser.FileContents); var prediction = new Prediction { Id = Guid.NewGuid(), ContentType = parser.ContentType, FileName = parser.Filename, CreatedOn = DateTimeOffset.UtcNow, Data = parser.FileContents, DogProbability = predictionResult.dogProbability, CatProbability = predictionResult.catProbability }; db.Predictions.Add(prediction); db.SaveChanges(); } }