public async Task <IActionResult> Posts(int page = 0) { var(total, posts) = await apiClient.GetBlogPostsAsync(page, PageSize); var vm = new PostsVM { Posts = posts, Total = total, Page = page, PageSize = PageSize }; return(View(vm)); }
private async void GetDatabase(bool updateAll = false) { await UpdateDatabase(updateAll); PostsVM = postDatabase.Get() .Where(i => i.AlbumId == albumModel.Id) .Select(i => new PostModel { Id = i.Id, Title = i.Title, Body = i.Body, AlbumId = i.AlbumId, AlbumTitle = albumModel.Title }).ToList(); if (PostsVM == null || !PostsVM.Any()) { Dialog.Toast("No posts found.", new TimeSpan(5)); } }
public PostsVM GetOwn(PostAndUserVM userPost) { userPost.User = UserService.userLogedin; try { if (userPost.User != null) { var ownPosts = new PostsVM(); ownPosts.Posts = _context.Posts.Where(p => p.UserId == userPost.User.Id).ToList(); return(ownPosts); //var vmPosts = userVM.Posts; //vmPosts = ownPosts; //return vmPosts; } throw new NotImplementedException(); } catch (Exception) { throw; } }
public async Task <IActionResult> AddPost([FromBody] PostsVM post) { Posts newPost = new Posts(); newPost.Body = post.Body; newPost.Title = post.Title; newPost.Tags = post.Tags; newPost.CreatedAt = DateTime.Now; newPost.CreatedBy = Convert.ToInt32(HttpContext.Session.GetInt32("userid")); //using (var ms = new MemoryStream()) //{ // post.Thumbnail.CopyTo(ms); // var fileBytes = ms.ToArray(); // string s = Convert.ToBase64String(fileBytes); // newPost.Thumbnail = fileBytes; //} var result = await _postService.AddNewPost(newPost); return(Ok(1)); }
/// <summary> /// Maps an IEnumerable of all posts to an all posts view model /// </summary> /// <param name="posts"></param> /// <returns></returns> public static AllEditorDataVM ReturnAllPosts(IEnumerable <Post> posts) { AllEditorDataVM allPosts = new AllEditorDataVM(); List <PostsVM> allSinglePosts = new List <PostsVM>(); foreach (var post in posts) { PostsVM PostsVM = new PostsVM { PostCreatorName = post.PostCreator.FirstName + " " + post.PostCreator.LastName, PostId = post.PostId, PostTitle = post.PostTitle, ImagePath = post.ImagePath, CreationDate = post.CreationDate, PostCategories = string.Join(", ", ReturnCategories(post.PostCategories)), ApprovalState = post.ApprovalState, }; allSinglePosts.Add(PostsVM); } allPosts.AllSinglePosts = allSinglePosts; allPosts.PostCount = posts.Count(); return(allPosts); }