public void BuildModelForUser(long id) { using (var conn = new ifollowdatabaseEntities4()) { user currentUser = conn.users.First(u => u.id == id); wallElements = new List <FollowerData>(); List <user> existingUsers = conn.users.ToList(); foreach (user u in existingUsers) { if (u.id != currentUser.id && conn.followers.Any(f => f.followedId == u.id && f.followerId == currentUser.id) == false) { FollowerData fd = new FollowerData(); fd.id = u.id; fd.firstName = u.firstName; fd.lastName = u.lastName; if (u.images.Any(i => i.isAvatar == true)) { image av = u.images.First(i => i.isAvatar == true); fd.avatar = av.url; } else { fd.avatar = "Images/placeholderProfile.jpg"; } wallElements.Add(fd); } } } }
public void BuildFromImagesAndPosts(ICollection <post> posts, ICollection <image> images) { List <post> orderedList = posts.ToList(); orderedList.Sort(new PostsComparer()); wallElements = new List <WallData>(); for (int index = orderedList.Count() - 1; index >= 0; index--) { post currentPost = orderedList.ElementAt(index); WallData newModel = new WallData(); newModel.Message = currentPost.message; using (var conn = new ifollowdatabaseEntities4()) { user author = conn.users.First(u => u.id == currentPost.ownerId); newModel.Author = author.firstName + " " + author.lastName; } if (orderedList.ElementAt(index).imageId != null) { string imagePath = images.First(i => i.id == currentPost.imageId).url; string path = @"~/Images/UserPhotos/" + imagePath; newModel.Path = path; } else { newModel.Path = "";//"~/Images/1.jpg"; } wallElements.Add(newModel); } }