public static string ImportFollowers(InstagraphContext context, string jsonString) { var followers = JsonConvert.DeserializeObject <FollowersDto[]>(jsonString); var sb = new StringBuilder(); var validatedFollowers = new List <UserFollower>(); foreach (var followerDto in followers) { bool isValid = !string.IsNullOrWhiteSpace(followerDto.Follower) && followerDto.Follower.Length <= 30 && !string.IsNullOrWhiteSpace(followerDto.User) && followerDto.User.Length <= 30; var user = context.Users .FirstOrDefault(u => u.Username == followerDto.User); var follower = context.Users .FirstOrDefault(u => u.Username == followerDto.Follower); bool FollowerExists = validatedFollowers .Any(f => f.Follower == follower && f.User == user); if (!isValid || user == null || follower == null || FollowerExists) { sb.AppendLine(ErrorMsg); continue; } var validFollower = Mapper.Map <UserFollower>(followerDto); validFollower.Follower = follower; validFollower.User = user; validatedFollowers.Add(validFollower); sb.AppendLine( String.Format(SuccessMsg, $"Follower {validFollower.Follower.Username} to User {validFollower.User.Username}")); } context.UsersFollowers.AddRange(validatedFollowers); context.SaveChanges(); return(sb.ToString().TrimEnd()); }
public static string ImportPosts(InstagraphContext context, string xmlString) { var xml = XDocument.Parse(xmlString); var str = new StringBuilder(); var posts = new List <Post>(); foreach (var e in xml.Root.Elements()) { var caption = e.Element("caption")?.Value; var username = e.Element("user")?.Value; var pic = e.Element("picture")?.Value; if (string.IsNullOrWhiteSpace(caption) || string.IsNullOrWhiteSpace(username) || string.IsNullOrWhiteSpace(pic)) { str.AppendLine("Error: Invalid data."); continue; } var user = context.Users.FirstOrDefault(x => x.Username == username)?.Id; var picture = context.Pictures.FirstOrDefault(x => x.Path == pic)?.Id; if (picture == null || user == null) { str.AppendLine("Error: Invalid data."); continue; } var post = new Post() { Caption = caption, UserId = user.Value, PictureId = picture.Value }; posts.Add(post); str.AppendLine($"Successfully imported Post {caption}."); } context.Posts.AddRange(posts); context.SaveChanges(); return(str.ToString()); }
public static string ExportCommentsOnPosts(InstagraphContext context) { var userCommentDtos = context.Users .ProjectTo <UserCommentDto>() .OrderByDescending(u => u.MostComments) .ThenBy(u => u.Username) .ToArray(); var namespaces = new XmlSerializerNamespaces(new[] { XmlQualifiedName.Empty }); var serializer = new XmlSerializer(typeof(UserCommentDto[]), new XmlRootAttribute("users")); var sb = new StringBuilder(); serializer.Serialize(new StringWriter(sb), userCommentDtos, namespaces); return(sb.ToString()); }
public static string ExportUncommentedPosts(InstagraphContext context) { var posts = context.Posts .Where(p => p.Comments.Count == 0) .OrderBy(p => p.Id) .Select(p => new PostExportDto { Id = p.Id, PicturePath = p.Picture.Path, Username = p.User.Username }) .ToArray(); var result = JsonConvert.SerializeObject(posts, Newtonsoft.Json.Formatting.Indented); return(result); }
public static string ImportUsers(InstagraphContext context, string jsonString) { var usersDto = JsonConvert.DeserializeObject <ImportUsersDto[]>(jsonString); var users = new List <User>(); var sb = new StringBuilder(); foreach (var userDto in usersDto) { if (!IsValid(userDto) || string.IsNullOrEmpty(userDto.ProfilePicture) || userDto.Username == null || userDto.Password == null) { sb.AppendLine("Error: Invalid data."); continue; } foreach (var impUser in users) { if (impUser.Username == userDto.Username) { sb.AppendLine("Error: Invalid data."); continue; } } var user = new User { Username = userDto.Username, Password = userDto.Password, ProfilePicture = new Picture { Path = userDto.ProfilePicture } }; users.Add(user); sb.AppendLine($"Successfully imported User {userDto.Username}."); } context.Users.AddRange(users); context.SaveChanges(); var result = sb.ToString().TrimEnd(); return(result); }
public static string ExportUncommentedPosts(InstagraphContext context) { var posts = context.Posts .Where(p => p.Comments.Count == 0) .OrderBy(p => p.Id) .Select(p => new { Id = p.Id, Picture = p.Picture.Path, User = p.User.Username }) .ToArray(); var jsonString = JsonConvert.SerializeObject(posts, Formatting.Indented); return(jsonString); }
public static string ImportUsers(InstagraphContext context, string jsonString) { var deserializedUsers = JsonConvert.DeserializeObject <UserDto[]>(jsonString); var validUsers = new List <User>(); var sb = new StringBuilder(); foreach (var userDto in deserializedUsers) { if (!IsValid(userDto)) { sb.AppendLine(ErrorMessage); continue; } bool usernameExists = validUsers.Any(u => u.Username == userDto.Username); bool pictureExists = context.Pictures.Any(p => p.Path == userDto.ProfilePicture); if (usernameExists || !pictureExists) { sb.AppendLine(ErrorMessage); continue; } int?pictureId = context.Pictures.AsNoTracking().SingleOrDefault(p => p.Path == userDto.ProfilePicture)?.Id; User user = new User { Username = userDto.Username, Password = userDto.Password, ProfilePictureId = pictureId.Value, }; validUsers.Add(user); sb.AppendLine(string.Format(SuccessfullyImportedUsersMessage, user.Username)); } context.Users.AddRange(validUsers); context.SaveChanges(); string result = sb.ToString().TrimEnd(); return(result); }
public static string ImportComments(InstagraphContext context, string xmlString) { var xDoc = XDocument.Parse(xmlString); var elements = xDoc.Root.Elements(); var sb = new StringBuilder(); var comments = new List <Comment>(); foreach (var element in elements) { string content = element.Element("content")?.Value; string userName = element.Element("user")?.Value; string postIdString = element.Element("post")?.Attribute("id")?.Value; bool inputIsValid = !string.IsNullOrWhiteSpace(content) && !string.IsNullOrWhiteSpace(userName) && !string.IsNullOrWhiteSpace(postIdString); if (!inputIsValid) { sb.AppendLine(ErrorMsg); continue; } int postId = int.Parse(postIdString); int?userId = context.Users.FirstOrDefault(u => u.Username == userName)?.Id; bool postExists = context.Posts.Any(p => p.Id == postId); if (userId == null || !postExists) { sb.AppendLine(ErrorMsg); continue; } var comment = new Comment(content, userId.Value, postId); comments.Add(comment); sb.AppendLine(string.Format(SuccessMsg, $"Comment {comment}")); } context.Comments.AddRange(comments); context.SaveChanges(); return(sb.ToString().TrimEnd()); }
public static string ExportUncommentedPosts(InstagraphContext context) { var posts = context.Posts .Where(p => p.Comments.Count < 1) .OrderBy(i => i.Id) .Select(c => new { Id = c.Id, Picture = c.Picture.Path, User = c.User.Username }) .ToList(); var jsonString = JsonConvert.SerializeObject(posts, Newtonsoft.Json.Formatting.Indented); return(jsonString); }
public static string ImportComments(InstagraphContext context, string xmlString) { var result = new StringBuilder(); var serializer = new XmlSerializer(typeof(List <ImportCommentDto>), new XmlRootAttribute("comments")); var importedComments = (List <ImportCommentDto>)serializer.Deserialize(new StringReader(xmlString)); var users = context.Users.ToList(); var posts = context.Posts.ToList(); var comments = new List <Comment>(); foreach (var importCommentDto in importedComments) { if (string.IsNullOrEmpty(importCommentDto.Username) || importCommentDto.ImportSinglePostDto == null) { result.AppendLine("Error: Invalid data."); continue; } var user = users.FirstOrDefault(u => u.Username == importCommentDto.Username); var post = posts.FirstOrDefault(p => p.Id == importCommentDto.ImportSinglePostDto.Id); if (user == null || post == null) { result.AppendLine("Error: Invalid data."); continue; } comments.Add(new Comment { User = user, Post = post, Content = importCommentDto.Content }); result.AppendLine($"Successfully imported Comment {importCommentDto.Content}."); } context.AddRange(comments); context.SaveChanges(); return(result.ToString().TrimEnd()); }
public static string ExportPopularUsers(InstagraphContext context) { var users = context.Users .Where(u => u.Posts .Any(p => p.Comments .Any(c => u.Followers .Any(f => f.FollowerId == c.UserId)))) .OrderBy(u => u.Id) .Select(u => new { Username = u.Username, Followers = u.Followers.Count }) .ToArray(); return(JsonConvert.SerializeObject(users, Formatting.Indented)); }
private static void ExportData() { using (var context = new InstagraphContext()) { string uncommentedPostsOutput = Serializer.ExportUncommentedPosts(context); File.WriteAllText("files/output/UncommentedPosts.json", uncommentedPostsOutput); string usersOutput = Serializer.ExportPopularUsers(context); File.WriteAllText("files/output/PopularUsers.json", usersOutput); string commentsOutput = Serializer.ExportCommentsOnPosts(context); File.WriteAllText("files/output/CommentsOnPosts.xml", commentsOutput); } }
private static void ExportData() { using (var context = new InstagraphContext()) { string uncommentedPostsOutput = Serializer.ExportUncommentedPosts(context); File.WriteAllText(@"C:\Users\proha\source\repos\AdvancedDB\Instagraph\Instagraph.App\files\output\UncommentedPosts.json", uncommentedPostsOutput); string usersOutput = Serializer.ExportPopularUsers(context); File.WriteAllText(@"C:\Users\proha\source\repos\AdvancedDB\Instagraph\Instagraph.App\files\output\PopularUsers.json", usersOutput); string commentsOutput = Serializer.ExportCommentsOnPosts(context); File.WriteAllText(@"C:\Users\proha\source\repos\AdvancedDB\Instagraph\Instagraph.App\files\output\CommentsOnPosts.xml", commentsOutput); } }
public static string ImportComments(InstagraphContext context, string xmlString) { XDocument xDoc = XDocument.Parse(xmlString); var elements = xDoc.Root.Elements(); StringBuilder sb = new StringBuilder(); List <Comment> comments = new List <Comment>(); foreach (XElement element in elements) { string content = element.Element("content")?.Value; string username = element.Element("user")?.Value; string postIdString = element.Element("post")?.Attribute("id")?.Value; bool isValid = !string.IsNullOrWhiteSpace(content) && !string.IsNullOrWhiteSpace(username) && !string.IsNullOrWhiteSpace(postIdString); if (!isValid) { sb.AppendLine(errorMessage); continue; } User user = context.Users.FirstOrDefault(u => u.Username == username); Post post = context.Posts.FirstOrDefault(p => p.Id == int.Parse(postIdString)); if (user == null || post == null) { sb.AppendLine(errorMessage); continue; } Comment comment = new Comment() { Content = content, User = user, Post = post }; comments.Add(comment); sb.AppendLine(string.Format(successMessage, $"Comment {content}")); } context.Comments.AddRange(comments); context.SaveChanges(); return(sb.ToString().Trim()); }
public static string ImportPosts(InstagraphContext context, string xmlString) { var xDoc = XDocument.Parse(xmlString); var elements = xDoc.Root.Elements(); var sb = new StringBuilder(); var postsList = new List <Post>(); foreach (var e in elements) { var caption = e.Element("caption")?.Value; var user = e.Element("user")?.Value; var picture = e.Element("picture")?.Value; var isValid = !String.IsNullOrWhiteSpace(caption) || !String.IsNullOrWhiteSpace(user) || !String.IsNullOrWhiteSpace(picture); var userId = context.Users.FirstOrDefault(u => u.Username == user)?.Id; var currentPictureId = context.Pictures.FirstOrDefault(p => p.Path == picture)?.Id; if (!isValid || userId == null || currentPictureId == null) { sb.AppendLine(errorMsg); continue; } var newPost = new Post() { Caption = caption, UserId = userId.Value, PictureId = currentPictureId.Value }; postsList.Add(newPost); sb.AppendLine(String.Format(successMsg, $"Post {caption}")); } context.Posts.AddRange(postsList); context.SaveChanges(); var result = sb.ToString().Trim(); return(result); }
public static string ImportComments(InstagraphContext context, string xmlString) { StringBuilder result = new StringBuilder(); XDocument commentsXml = XDocument.Parse(xmlString); CommentDto[] comments = commentsXml.Root.Elements() .Select(c => new CommentDto { Content = c.Element("content")?.Value, User = c.Element("user")?.Value, PostId = c.Element("post") != null && c.Element("post").Attribute("id") != null ? int.Parse(c.Element("post").Attribute("id").Value) : default(int?) }) .ToArray(); List <Comment> validComments = new List <Comment>(); foreach (var c in comments) { User user = context.Users.SingleOrDefault(u => u.Username == c.User); Post post = context.Posts.SingleOrDefault(p => p.Id == c.PostId); if (user == null || post == null) { result.AppendLine(Error); continue; } Comment toAdd = new Comment { Content = c.Content, UserId = user.Id, PostId = post.Id }; validComments.Add(toAdd); result.AppendLine($"Successfully imported Comment {c.Content}."); } context.Comments.AddRange(validComments); context.SaveChanges(); return(result.ToString().Trim()); }
public static string ExportCommentsOnPosts(InstagraphContext context) { var users = context.Users .Select(u => new { Username = u.Username, PostsCommentCount = u.Posts.Select(p => p.Comments.Count).ToArray() }); var userDtos = new List <UserTopPostDto>(); var xDoc = new XDocument(); xDoc.Add(new XElement("users")); foreach (var u in users) { int mostComments = 0; if (u.PostsCommentCount.Any()) { mostComments = u.PostsCommentCount.OrderByDescending(c => c).First(); } var userDto = new UserTopPostDto() { Username = u.Username, MostComments = mostComments }; userDtos.Add(userDto); } userDtos = userDtos.OrderByDescending(u => u.MostComments) .ThenBy(u => u.Username).ToList(); var sb = new StringBuilder(); var serializer = new XmlSerializer(typeof(List <UserTopPostDto>), new XmlRootAttribute("users")); serializer.Serialize(new StringWriter(sb), userDtos, new XmlSerializerNamespaces(new[] { XmlQualifiedName.Empty })); var result = sb.ToString(); return(result); }
public static string ImportPosts(InstagraphContext context, string xmlString) { var xDoc = XDocument.Parse(xmlString); var elements = xDoc.Root.Elements(); var sb = new StringBuilder(); var posts = new List <Post>(); foreach (var element in elements) { string caption = element.Element("caption")?.Value; string username = element.Element("user")?.Value; string picturePath = element.Element("picture")?.Value; bool inputIsValid = !string.IsNullOrWhiteSpace(caption) && !string.IsNullOrWhiteSpace(username) && !string.IsNullOrWhiteSpace(picturePath); if (!inputIsValid) { sb.AppendLine(ErrorMsg); continue; } int?userId = context.Users.FirstOrDefault(u => u.Username == username)?.Id; int?pictureId = context.Pictures.FirstOrDefault(u => u.Path == picturePath)?.Id; if (userId == null || pictureId == null) { sb.AppendLine(ErrorMsg); continue; } var post = new Post(caption, userId.Value, pictureId.Value); posts.Add(post); sb.AppendLine(string.Format(SuccessMsg, $"Post {caption}")); } context.Posts.AddRange(posts); context.SaveChanges(); return(sb.ToString().TrimEnd()); }
public static string ImportFollowers(InstagraphContext context, string jsonString) { UserFollowerDto[] deserializedFollowers = JsonConvert.DeserializeObject <UserFollowerDto[]>(jsonString); StringBuilder sb = new StringBuilder(); var userFollowers = new List <UserFollower>(); foreach (var dto in deserializedFollowers) { var user = context.Users .FirstOrDefault(x => x.Username == dto.User); var follower = context.Users .FirstOrDefault(x => x.Username == dto.Follower); bool bothExist = user != null && follower != null; if (!bothExist) { sb.AppendLine(errorMessage); continue; } bool alreadyFollower = userFollowers.Any(x => x.UserId == user.Id && x.FollowerId == follower.Id); if (alreadyFollower) { sb.AppendLine(errorMessage); continue; } var userFollower = new UserFollower() { UserId = user.Id, FollowerId = follower.Id }; userFollowers.Add(userFollower); sb.AppendLine(String.Format(successMessage, $"Follower {dto.Follower} to User {dto.User}")); } context.UsersFollowers.AddRange(userFollowers); context.SaveChanges(); return(sb.ToString().Trim()); }
public static string ImportComments(InstagraphContext context, string xmlString) { var xDoc = XDocument.Parse(xmlString); var validComments = new List <Comment>(); var sb = new StringBuilder(); foreach (var element in xDoc.Root.Elements()) { var content = element.Element("content")?.Value; var username = element.Element("user")?.Value; var postIdString = element.Element("post")?.Attribute("id")?.Value; if (string.IsNullOrWhiteSpace(content) || string.IsNullOrWhiteSpace(username) || string.IsNullOrWhiteSpace(postIdString)) { sb.AppendLine("Error: Invalid data."); continue; } var postId = context.Posts.FirstOrDefault(p => p.Id == int.Parse(postIdString))?.Id; var userId = context.Users.FirstOrDefault(u => u.Username == username)?.Id; if (userId == null || postId == null) { sb.AppendLine("Error: Invalid data."); continue; } sb.AppendLine($"Successfully imported Comment {content}."); var comment = new Comment() { Content = content, PostId = postId.Value, UserId = userId.Value }; validComments.Add(comment); } context.Comments.AddRange(validComments); context.SaveChanges(); return(sb.ToString().Trim()); }
public static string ImportComments(InstagraphContext context, string xmlString) { var sb = new StringBuilder(); var serializer = new XmlSerializer(typeof(CommentDto[]), new XmlRootAttribute("comments")); var deserializedComments = (CommentDto[])serializer.Deserialize(new MemoryStream(Encoding.UTF8.GetBytes(xmlString))); var validComments = new List <Comment>(); foreach (var commentDto in deserializedComments) { var user = context.Users.SingleOrDefault(u => u.Username == commentDto.User); if (!IsValid(commentDto) || user == null) { sb.AppendLine("Error: Invalid data."); continue; } bool isParsed = int.TryParse(commentDto.PostId?.Id, out var parsedId); if (!isParsed) { sb.AppendLine("Error: Invalid data."); continue; } var postId = context.Posts.SingleOrDefault(p => p.Id == parsedId)?.Id; if (postId == null) { sb.AppendLine("Error: Invalid data."); continue; } sb.AppendLine($"Successfully imported Comment {commentDto.Content}."); var comment = Mapper.Map <Comment>(commentDto); comment.User = user; comment.PostId = postId.Value; validComments.Add(comment); } context.Comments.AddRange(validComments); context.SaveChanges(); return(sb.ToString()); }
public static string ImportFollowers(InstagraphContext context, string jsonString) { var sb = new StringBuilder(); var deserializedFollowers = JsonConvert.DeserializeObject <List <UserFollowerDto> >(jsonString); var userFollowers = new List <UserFollower>(); foreach (var userFollowerDto in deserializedFollowers) { int?userId = context.Users.FirstOrDefault(u => u.Username == userFollowerDto.User)?.Id; int?followerId = context.Users.FirstOrDefault(u => u.Username == userFollowerDto.Follower)?.Id; if (userId == null || followerId == null) { sb.AppendLine(ERROR_MESSAGE); continue; } bool alreadyFollowed = userFollowers.Any(f => f.UserId == userId && f.FollowerId == followerId); if (alreadyFollowed) { sb.AppendLine(ERROR_MESSAGE); continue; } var userFollower = new UserFollower { UserId = userId.Value, FollowerId = followerId.Value }; userFollowers.Add(userFollower); sb.AppendLine(string.Format(SUCCESS_MESSAGE, $"Follower {userFollowerDto.Follower} to User {userFollowerDto.User}")); } context.UsersFollowers.AddRange(userFollowers); context.SaveChanges(); string result = sb.ToString().TrimEnd(); return(result); }
public static string ImportComments(InstagraphContext context, string xmlString) { var xDoc = XDocument.Parse(xmlString); var elements = xDoc.Root.Elements(); var sb = new StringBuilder(); var validComments = new List <Comment>(); foreach (var el in elements) { string content = el.Element("content")?.Value; string username = el.Element("user")?.Value; bool postIdExists = int.TryParse(el.Element("post")?.Attribute("id")?.Value, out int postId); bool contentIsValid = content.Length <= 250; bool userExists = context.Users.Any(u => u.Username == username); bool postExists = context.Posts.Any(p => p.Id == postId); if (!contentIsValid || !userExists || !postExists || !postIdExists) { sb.AppendLine(ErrorMessage); continue; } User user = FindUser(context, username); Comment comment = new Comment { Content = content, PostId = postId, User = user, }; validComments.Add(comment); sb.AppendLine(string.Format(SuccessfullyImportedCommentsMessage, comment.Content)); } context.Comments.AddRange(validComments); context.SaveChanges(); string result = sb.ToString().TrimEnd(); return(result); }
public static string ImportComments(InstagraphContext context, string xmlString) { var sb = new StringBuilder(); var elements = XDocument.Parse(xmlString).Root.Elements(); var comments = new List <Comment>(); foreach (var xElement in elements) { var content = xElement.Element("content")?.Value; var username = xElement.Element("user")?.Value; var postIdAsString = xElement.Element("post")?.Attribute("id")?.Value; if (string.IsNullOrWhiteSpace(content) || string.IsNullOrWhiteSpace(username) || postIdAsString == null) { sb.AppendLine(ErrorMessage.InvalidData); continue; } var postId = int.Parse(postIdAsString); var post = context.Posts.SingleOrDefault(p => p.Id == postId); var user = context.Users.SingleOrDefault(u => u.Username.Equals(username)); if (post == null || user == null) { sb.AppendLine(ErrorMessage.InvalidData); continue; } var comment = new Comment { Content = content, Post = post, User = user }; comments.Add(comment); sb.AppendLine(string.Format(SuccessMessage.Comment, content)); } context.Comments.AddRange(comments); context.SaveChanges(); return(sb.ToString().Trim()); }
public static string ExportPopularUsers(InstagraphContext context) { PopularUserDto[] popularUsers = context.Users .Include(u => u.Followers) .Include(u => u.Posts) .ThenInclude(p => p.Comments) .Where(u => u.Posts.Any(p => p.Comments.Any(c => u.Followers.Any(f => f.FollowerId == c.UserId)))) .Select(u => new PopularUserDto { Username = u.Username, Followers = u.Followers.Count }) .ToArray(); string serializedPopularUsers = JsonConvert.SerializeObject(popularUsers, Formatting.Indented); return(serializedPopularUsers); }
public static string ExportPopularUsers(InstagraphContext context) { var users = context .Users .OrderBy(u => u.Id) .Include(u => u.Posts) .Include(u => u.Comments) .Include(u => u.Followers) .Include(u => u.UsersFollowing) .Where(u => u.Posts.Any(p => p.Comments.Any(c => u.Followers.Any(uc => uc.Follower.Username.Equals(c.User.Username))))) .Select(e => new { Username = e.Username, Followers = e.Followers.Count }).ToArray(); return(JsonConvert.SerializeObject(users)); }
public static string ExportPopularUsers(InstagraphContext context) { var users = context.Users //brykni v userite .Where(u => u.Posts //ot tehnite postove .Any(p => p.Comments // vzemi komentarite .Any(c => u.Followers //chiito user - avtor .Any(f => f.FollowerId == c.UserId)))) // e nqkoi ot posledovatelite .OrderBy(u => u.Id) .Select(x => new { User = x.Username, Followers = x.Followers.Count }); var result = JsonConvert.SerializeObject(users, Formatting.Indented); return(result); }
public static string ExportPopularUsers(InstagraphContext context) { var users = context.Users.Include(x => x.Posts).ThenInclude(a => a.Comments) .Where(u => u.Posts .Any(p => p.Comments .Any(c => u.Followers .Any(f => f.FollowerId == c.UserId)))) .Select(u => new { u.Username, Followers = u.Followers.Count }) .ToArray(); var jsonString = JsonConvert.SerializeObject(users); return(jsonString); }
public static string ExportPopularUsers(InstagraphContext context) { var users = context.Users .Where(p => p.Posts .Any(c => c.Comments .Any(f => p.Followers .Any(fi => fi.FollowerId == f.UserId)))) .Select(u => new { Username = u.Username, Followers = u.Followers.Count }) .ToList(); var jsonString = JsonConvert.SerializeObject(users, Newtonsoft.Json.Formatting.Indented); return(jsonString); }
public static string ExportUncommentedPosts(InstagraphContext context) { UncommentedPostDto[] uncommentedPosts = context.Posts .Include(p => p.Comments) .Where(p => p.Comments.Count == 0) .OrderBy(p => p.Id) .Select(p => new UncommentedPostDto { Id = p.Id, Picture = p.Picture.Path, User = p.User.Username }) .ToArray(); string serializedUncommentedPosts = JsonConvert.SerializeObject(uncommentedPosts, Formatting.Indented); return(serializedUncommentedPosts); }