public object Make(Sighting sighting, SightingNote sightingNote, User user, User authenticatedUser) { dynamic viewModel = new ExpandoObject(); viewModel.Id = sightingNote.Id; viewModel.SightingId = sighting.Id; viewModel.CreatedOn = sightingNote.CreatedOn; viewModel.NoteComments = sightingNote.Comments; viewModel.Descriptions = sightingNote.Descriptions; viewModel.Tags = sightingNote.Tags; viewModel.User = _userViewFactory.Make(user, authenticatedUser); viewModel.TagCount = sightingNote.Tags.Count(); viewModel.DescriptionCount = sightingNote.Descriptions.Count(); viewModel.AllTags = string.Join(", ", sightingNote.Tags); viewModel.CreatedOnDescription = sightingNote.CreatedOn.ToString("d MMMM yyyy"); viewModel.TotalVoteScore = sightingNote.Votes.Sum(x => x.Score); // Current user-specific properties if (authenticatedUser != null) { var userId = authenticatedUser.Id; viewModel.UserVoteScore = sightingNote.Votes.Any(x => x.User.Id == userId) ? sightingNote.Votes.Single(x => x.User.Id == userId).Score : 0; viewModel.IsOwner = sightingNote.User.Id == authenticatedUser.Id; } return viewModel; }
public object Make(Sighting sighting, SightingNote sightingNote, User user, User authenticatedUser) { dynamic viewModel = new ExpandoObject(); viewModel.Id = sightingNote.Id; viewModel.SightingId = sighting.Id; viewModel.CreatedOn = sightingNote.CreatedOn; viewModel.NoteComments = sightingNote.Comments; viewModel.Descriptions = sightingNote.Descriptions; viewModel.Tags = sightingNote.Tags; viewModel.User = _userViewFactory.Make(user, authenticatedUser); viewModel.TagCount = sightingNote.Tags.Count(); viewModel.DescriptionCount = sightingNote.Descriptions.Count(); viewModel.AllTags = string.Join(", ", sightingNote.Tags); viewModel.CreatedOnDescription = sightingNote.CreatedOn.ToString("d MMMM yyyy"); viewModel.TotalVoteScore = sightingNote.Votes.Sum(x => x.Score); // Current user-specific properties if (authenticatedUser != null) { var userId = authenticatedUser.Id; viewModel.UserVoteScore = sightingNote.Votes.Any(x => x.User.Id == userId) ? sightingNote.Votes.Single(x => x.User.Id == userId).Score : 0; viewModel.IsOwner = sightingNote.User.Id == authenticatedUser.Id; } return(viewModel); }