public IList<QuackDto> GetAllQuacks() { var userName = HttpContext.Current.User.Identity.Name; var user = _userFacade.GetUserDetails(userName); var quacks = _quackRepository.GetAllQuacks(); var quackResults = new List<QuackDto>(); foreach (var quack in quacks) { var q = new QuackDto(); q = QuackMapper(quack, user.ID); var replies = _quackRepository.GetAllReplies(quack.ID); var qReplies = (from reply in replies let qreply = new QuackDto() select QuackMapper(reply)).ToList(); q.QuackReplies = qReplies; q.Replies = replies.Count(qq => qq.Active); quackResults.Add(q); } return quackResults; }
private QuackDto GetRepliesInformation(int quackId) { var resultQuack = new QuackDto(); var commentInfo = ""; var quacks = _quackRepository.GetAllReplies(quackId); if (quacks != null && quacks.Any()) { var latestQuackIndex = quacks.Count() - 1; resultQuack.UserDisplayName = quacks[latestQuackIndex].User.FirstName + " " + quacks[latestQuackIndex].User.LastName; resultQuack.UserImage = quacks[latestQuackIndex].User.ProfileImage; resultQuack.TimeSpan = GetTimeSpanInformation(quacks[latestQuackIndex].LastModifiedDate); resultQuack.Id = quacks[latestQuackIndex].ID; resultQuack.UserId = quacks[latestQuackIndex].UserID; resultQuack.Message = quacks[latestQuackIndex].QuackContent.MessageText; switch (quacks.Count()) { case 1: commentInfo = ""; break; case 2: commentInfo = quacks[0].User.FirstName + " also commented on this Quack..."; break; case 3: commentInfo = quacks[0].User.FirstName + " and " + quacks[1].User.FirstName + " also commented on this Quack..."; break; case 4: commentInfo = quacks[0].User.FirstName + ", " + quacks[1].User.FirstName + " and " + quacks[2].User.FirstName + " also commented on this Quack..."; break; default: for (var i = 0; i < quacks.Count(); i++) { switch (i) { case 0: commentInfo = commentInfo + quacks[i].User.FirstName; break; case 1: commentInfo = commentInfo + ", " + quacks[i].User.FirstName; break; } } commentInfo = commentInfo + " and " + (quacks.Count() - 2) + " others also replied to this Quack..."; break; } resultQuack.CommentsInfo = commentInfo; } return resultQuack; }