public IActionResult CreatePost(PostViewModel postViewModel) { PostBL postBL = new PostBL((PostRepository)this._repository); postBL.CreatePost(postViewModel); return(RedirectToAction("AccountController/Index")); }
public IActionResult PostListFilter(int id) { var postBL = new PostBL(_uow, _mapper); var postFilter = postBL.PostListFilter(id); return(View(postFilter)); }
public ActionResult CreatePost(Post p, string text, string text_lng) { string filename = "blog1.jpg"; if (p.upload != null) { filename = System.IO.Path.GetFileName(p.upload.FileName); p.upload.SaveAs(Server.MapPath("~/Assets/img/bg-img/" + filename)); } p.image = "/Assets/img/bg-img/" + filename; p.date = DateTime.Now; p.numOfComments = 0; p.text = text; p.text_lng = text_lng; PostBL postBL = new PostBL(); if (ModelState.IsValid) { postBL.AddPost(p); return(RedirectToAction("News", "Home")); } return(View()); }
public IActionResult UserPosts() { var currentUser = _uow.UserManager.FindByNameAsync(HttpContext.User?.Identity?.Name).Result; var currentUserPL = _mapper.Map <Data.Models.User, User>(currentUser); var postBL = new PostBL(_uow, _mapper); IEnumerable <Data.Models.Post> postsDAL; if (currentUser.Email == "*****@*****.**") { postsDAL = _uow.PostRepository.List(); } else { postsDAL = postBL.UserPostList(currentUser.Id); } IEnumerable <Data.Models.User> usersDAL = this._uow.UserRepository.List(); IEnumerable <Data.Models.Product> productsDAL = this._uow.ProductRepository.List(); IEnumerable <Data.Models.ProductType> productTypesDAL = this._uow.ProductTypeRepository.List(); IEnumerable <Data.Models.Order> ordersDAL = this._uow.OrderRepository.List(); var lists = Core.Mapper.MapperModels(postsDAL, usersDAL, productsDAL, ordersDAL, productTypesDAL, _mapper); return(View(new PostViewModel { Posts = lists.postsPL, Users = lists.usersPL, Products = lists.productsPL, ProductTypes = lists.productTypesPL, CurrentUser = currentUserPL, })); }
public ActionResult EditPost(int id) { PostBL postBL = new PostBL(); List <Post> postList = postBL.GetPosts(); Post post = postList.Where(u => u.PostId == id).Single(); return(View(post)); }
public static async Task DisplaySubMenu1Async() { while (true) { Console.WriteLine("-------------------------"); Console.WriteLine("1. Get posts of category."); Console.WriteLine("2. Update new post of category"); Console.WriteLine("0. Back to main menu"); Console.WriteLine("-------------------------"); int subMenu1Choice = InputChoice(); switch (subMenu1Choice) { case 1: Console.Write("Enter id of category: "); int id = Int32.Parse(Console.ReadLine()); Category category = listCategories.Single(s => s.Id == id); int numberOfPage = 0; if (category.NumberOfPost % 20 != 0) { numberOfPage = category.NumberOfPost / 20 + 1; } else { numberOfPage = category.NumberOfPost / 20; } Console.WriteLine("Your choice is {0} with {1} pages!", category.Title, numberOfPage); List <Post> allPosts = new List <Post>(); PostService postService = new PostService(); Console.WriteLine("Getting post..."); for (int i = 1; i <= numberOfPage; i++) { string html = postService.GetHtmlData(category, i); List <Post> postsOfPage = await postService.GetPostsOfCategoryAsync(html); allPosts.AddRange(postsOfPage); await Task.Delay(1000); } // Console.WriteLine(allPosts.Count); PostBL postBL = new PostBL(); bool result = postBL.AddPostsIntoDatabase(allPosts, category.Id); Console.WriteLine("Done!!!"); break; case 0: await DisplayMainMenuAsync(); break; default: break; } } }
public ActionResult News() { PostBL postBL = new PostBL(); NewsVM news = new NewsVM(); news.posts = postBL.GetPosts(); news.posts.Reverse(); return(View(news)); }
public DiscussionDetailsVM(Discussion d) { discussion = d; posts = new PostBL().GetPosts(); posts.Where(x => x.DiscussionId == d.DiscussionId); posts.OrderBy(x => x.Posted); ForumContext db = new ForumContext(); var r = db.userDB.Where(b => b.username == name).ToList().First(); isAdmin = r.isAdmin; }
public ActionResult DeletePost(int id) { PostBL postBL = new PostBL(); List <Post> postList = postBL.GetPosts(); Post post = postList.Where(u => u.PostId == id).Single(); postBL.DeletePost(post); NewsVM news = new NewsVM(); news.posts = postBL.GetPosts(); news.posts.Reverse(); return(RedirectToAction("News", "Home", news)); }
public IActionResult CreatePost(PostCreateModel postAdd) { postAdd.PostDate = DateTime.Now; var validator = new PostCreateValidator(); if (validator.Validate(postAdd).IsValid) { var postBL = new PostBL(_uow, _mapper); var currentUserName = HttpContext.User?.Identity?.Name; if (postBL.AddPost(postAdd, currentUserName)) { return(RedirectToAction("AccountPage", "Account")); } } return(RedirectToAction("")); }
public ActionResult Wall() { var userID = User.Identity.GetUserId(); if (Request.QueryString["user"] != null && Request.QueryString["user"] != "") { userID = Request.QueryString["user"].ToString(); } else { userID = new UserProfileBL().GetProfileByUserIdentity(userID).UserProfileID.ToString(); } var postVM = new PostBL().GetPostsWithLikesAndComments(Convert.ToInt32(userID)); return(View(postVM)); }
public ActionResult EditPost(Post p, string text, string text_lng) { if (p.upload != null) { string filename = System.IO.Path.GetFileName(p.upload.FileName); p.upload.SaveAs(Server.MapPath("~/Assets/img/bg-img/" + filename)); p.image = "/Assets/img/bg-img/" + filename; } p.date = DateTime.Now; p.text = text; p.text_lng = text_lng; PostBL postBL = new PostBL(); postBL.EditPost(p); return(RedirectToAction("News", "Home")); }
public async Task <ResultResponse <Post> > Post([FromBody] Post post) { var postBL = new PostBL(_postRepository); try { await postBL.AddPost(post); return(new ResultResponse <Post> { Success = true, Item = post }); } catch (Exception ex) { return(GetErrorResponse <Post>(ex, "Error creating post! Please try again.")); } }
public async Task <ResultResponse <List <Post> > > GetPostsByUserId(string userId) { var postBL = new PostBL(_postRepository); try { var posts = await postBL.GetPostsByUserId(userId); await postBL.SetCommentsForPosts(posts, _commentRepository); return(new ResultResponse <List <Post> > { Success = true, Item = posts }); } catch (Exception ex) { return(GetErrorResponse <List <Post> >(ex, "Error getting post!")); } }
public ActionResult CommentList(CommentsVM comVM) { comVM.newComment.date = DateTime.Now; CommentBL commentBL = new CommentBL(); commentBL.AddComment(comVM.newComment); int postId = comVM.newComment.PostId; comVM.commentsList = commentBL.FindComments(postId); comVM.commentsList.Reverse(); PostBL postBL = new PostBL(); List <Post> list = postBL.GetPosts(); Post post = list.Where(u => u.PostId == postId).Single(); post.numOfComments += 1; postBL.EditPost(post); return(PartialView("CommentList", comVM)); }
public ActionResult DeleteComment(int id) { CommentBL commentBL = new CommentBL(); Comment c = commentBL.GetComments().Where(u => u.CommentId == id).Single(); commentBL.DeleteComment(c); int postId = c.PostId; PostBL postBL = new PostBL(); List <Post> list = postBL.GetPosts(); Post post = list.Where(u => u.PostId == postId).Single(); post.numOfComments -= 1; postBL.EditPost(post); CommentsVM comVM = new CommentsVM(); comVM.commentsList = commentBL.FindComments(postId); comVM.commentsList.Reverse(); return(PartialView("CommentList", comVM)); }