public ViewResult Detail(string slug, CurrentUserInformation currentUser) { //ToDo: Number of Request 2 - not 1. Include doesn´t work. Term word = Session.Query <Term>().Where(x => x.Slug == slug) .SingleOrDefault(); word.Views = word.Views + 1; Session.Store(word); DetailTermViewModel model = new DetailTermViewModel(); if (word.Supporters != null) { model.Supporters = Session.Query <User>().Where(x => x.Id.In(word.Supporters)).ToList(); } else { model.Supporters = new List <User>(); } model.Id = word.Id; model.Views = word.Views; model.Title = word.Title; model.DownVotes = word.DownVotes; model.UpVotes = word.UpVotes; model.Slug = word.Slug; model.CreatedOn = word.CreatedOn.ToShortDateString(); model.Resources = new List <DetailResourceViewModel>(); if (word.Resources != null) { foreach (var resource in word.Resources) { DetailResourceViewModel viewModelForResource = new DetailResourceViewModel(); viewModelForResource.Title = resource.Title; viewModelForResource.Url = resource.Url; viewModelForResource.Description = resource.Description; viewModelForResource.Votes = resource.Upvotes - resource.Downvotes; if (resource.Type == "link") { viewModelForResource.Thumbnail = "http://image.thumber.de/?size=L&url=" + resource.Url; } else { viewModelForResource.Thumbnail = resource.ThumbnailUrl; } viewModelForResource.Html = resource.EmbedCode; model.Resources.Add(viewModelForResource); } } if (word.Reactions != null) { model.PositiveReaction = word.Reactions.Where(x => x.IsPositive == true).ToList(); model.NegativeReaction = word.Reactions.Where(x => x.IsPositive == false).ToList(); } else { model.PositiveReaction = new List <Reaction>(); model.NegativeReaction = new List <Reaction>(); } model.CurrentUserInformation = currentUser; return(View(model)); }
public ViewResult Detail(string slug, CurrentUserInformation currentUser) { //ToDo: Number of Request 2 - not 1. Include doesn´t work. Term word = Session.Query<Term>().Where(x => x.Slug == slug) .SingleOrDefault(); word.Views = word.Views + 1; Session.Store(word); DetailTermViewModel model = new DetailTermViewModel(); if (word.Supporters != null) { model.Supporters = Session.Query<User>().Where(x => x.Id.In(word.Supporters)).ToList(); } else { model.Supporters = new List<User>(); } model.Id = word.Id; model.Views = word.Views; model.Title = word.Title; model.DownVotes = word.DownVotes; model.UpVotes = word.UpVotes; model.Slug = word.Slug; model.CreatedOn = word.CreatedOn.ToShortDateString(); model.Resources = new List<DetailResourceViewModel>(); if (word.Resources != null) { foreach (var resource in word.Resources) { DetailResourceViewModel viewModelForResource = new DetailResourceViewModel(); viewModelForResource.Title = resource.Title; viewModelForResource.Url = resource.Url; viewModelForResource.Description = resource.Description; viewModelForResource.Votes = resource.Upvotes - resource.Downvotes; if(resource.Type == "link") { viewModelForResource.Thumbnail = "http://image.thumber.de/?size=L&url=" + resource.Url; } else { viewModelForResource.Thumbnail = resource.ThumbnailUrl; } viewModelForResource.Html = resource.EmbedCode; model.Resources.Add(viewModelForResource); } } if (word.Reactions != null) { model.PositiveReaction = word.Reactions.Where(x => x.IsPositive == true).ToList(); model.NegativeReaction = word.Reactions.Where(x => x.IsPositive == false).ToList(); } else { model.PositiveReaction = new List<Reaction>(); model.NegativeReaction = new List<Reaction>(); } model.CurrentUserInformation = currentUser; return View(model); }