public async Task <IActionResult> AnnotateHeadline(string headlineId, NewSessionAnnotationRequest annotation) { INewsHeadline headline = await _headlineRepository.GetById(headlineId); var session = await _sessionRepository.GetById(annotation.SessionToken); if (headline == null) { return(NotFound("Headline not found")); } if (session == null) { return(NotFound("Session not found")); } var annotations = headline.Annotations.ToList(); annotations.Add(new HeadlineAnnotation() { SessionId = annotation.SessionToken, Vote = annotation.Annotation == Models.HeadlineSentiment.POSITIVE ? 1 : -1, CreatedAt = DateTime.Now }); headline.Annotations = annotations; await _headlineRepository.UpdateHeadline(headline); return(NoContent()); }
private List <IHeadlineAnnotation> FilterHeadlineAnnotations(INewsHeadline headline, string session) { return(String.IsNullOrEmpty(session) ? new List <IHeadlineAnnotation>() : headline.Annotations .Where(a => a.SessionId.Equals(session)) .ToList()); }