public async Task <JsonResult> GetById(Guid Id) { var item = (await NewsArticleService.GetAsQueriable()).Where(q => q.Id == Id).FirstOrDefault(); if (item == null) { Response.StatusCode = StatusCodes.Status404NotFound; } return(new JsonResult(item)); }
public async Task <Guid> AddOrUpdate(VoteViewModel model) { var userId = (await applicationUserService.GetAsQueriable()).Where(x => x.UserId == model.ApplicationUserId).Select(x => x.Id).FirstOrDefault(); if (userId == Guid.Empty) { userId = await applicationUserService.Add(new ApplicationUser { UserId = model.ApplicationUserId, Username = model.ApplicationUserId, CredibilityScore = 50 }); } var newsArtileId = (await newsArticleService.GetAsQueriable()).Where(n => n.Source == model.NewsArticleUrl).Select(q => q.Id).FirstOrDefault(); if (newsArtileId == Guid.Empty) { throw new Exception("Invalid Article Url"); } var vote = (await GetAsQueriable()).Where(x => x.ApplicationUserId == userId).FirstOrDefault(); if (vote == null) { return(await Add(new Vote { ApplicationUserId = userId, NewsArticleId = newsArtileId, IsTrue = model.IsTrue })); } else { vote.IsTrue = model.IsTrue; return(await Update(vote)); } }
public async Task <JsonResult> GetFiltered(NewsArticleFilterViewModel model) { var items = await model.ApplyFilter(await NewsArticleService.GetAsQueriable()); if (items.Count == 0) { Response.StatusCode = StatusCodes.Status404NotFound; } return(new JsonResult(items)); }
private async Task <XmlDocument> AddTwitterUsers(XmlDocument doc, XmlElement rdfElement) { var users = await twitterUserService.GetAll(); foreach (var user in users) { XmlElement element = doc.CreateElement("rdf:Description"); var uri = BaseUrl + "api/twitterUsers/Id/" + user.Id; element.SetAttribute("about", uri); var property = doc.CreateElement("Username"); property.InnerText = user.Username; element.AppendChild(property); property = doc.CreateElement("CredibilityScore"); property.InnerText = string.Empty + user.CredibilityScore ?? "0"; element.AppendChild(property); var newsArticlles = (await newsArticleService.GetAsQueriable()).Where(n => n.UserId == user.Id); foreach (var newsArticle in newsArticlles) { var applicationUserURI = BaseUrl + "api/newsArticles/Id/" + newsArticle.Id; property = doc.CreateElement("Posted"); property.InnerText = applicationUserURI; element.AppendChild(property); } rdfElement.AppendChild(element); } return(doc); }