Beispiel #1
0
        public MyPostsPage()
        {
            var myPostsViewModel = new MyPostsViewModel();

            this.BindingContext = myPostsViewModel;

            InitializeComponent();
        }
        public ViewResult Index()
        {
            int accountId          = Convert.ToInt32(User.Identity.Name.Split('|')[1]);
            MyPostsViewModel model = new MyPostsViewModel();

            model.MyPosts = _authorService.GetMyPosts(accountId);
            var        allCategories = _authorService.GetAllCategories();
            SelectList categoryList  = new SelectList(allCategories.ToList(), "CategoryId", "Name");

            model.Categories = categoryList;

            return(View(model));
        }
Beispiel #3
0
        public ActionResult Recent()
        {
            MyPostsViewModel myPostsVM = new MyPostsViewModel();
            string           userName  = User.Identity.GetUserName();

            using (var ctx = new ApplicationDbContext())
            {
                myPostsVM.AddedPosts = ctx.Posts.Where(m => m.IsResolved == true).OrderByDescending(m => m.DateAdded).Take(5).ToList();
                //var upvotedPostsIdList
                myPostsVM.UpvotedPosts = ctx.Posts.Where(m => m.IsApproved == true).OrderByDescending(m => m.DateAdded).Take(5).ToList();
            }
            return(View(myPostsVM));
        }
 public JsonResult SaveNewPost(MyPostsViewModel model)
 {
     if (model.CategoriesValue != "")
     {
         int accountId = Convert.ToInt32(User.Identity.Name.Split('|')[1]);
         if (_authorService.IsNewPostSaved(accountId, model.NewTitle, model.NewDescription, Convert.ToInt32(model.CategoriesValue), model.NewMainImage.Replace(" ", "")))
         {
             return(Json(new { success = true, message = "Your post has been saved" }, JsonRequestBehavior.AllowGet));
         }
         else
         {
             return(Json(new { success = false, message = "An error occurred while trying to save your post" }, JsonRequestBehavior.AllowGet));
         }
     }
     else
     {
         return(Json(new { success = false, message = "Please choose a category for your post." }, JsonRequestBehavior.AllowGet));
     }
 }
Beispiel #5
0
        public ActionResult MyPosts()
        {
            MyPostsViewModel myPostsVM = new MyPostsViewModel();
            string           userName  = User.Identity.GetUserName();

            using (var ctx = new ApplicationDbContext())
            {
                myPostsVM.AddedPosts = ctx.Posts.Where(m => m.UserName == userName).ToList();
                //var upvotedPostsIdList
                List <int> upvotedPostsIdList = ctx.UserPostUpvotes.Where(m => m.UserName == userName).Select(m => m.PostId).ToList();
                foreach (var postId in upvotedPostsIdList)
                {
                    var post = ctx.Posts.Where(m => m.Id == postId).FirstOrDefault();
                    if (post != null)
                    {
                        myPostsVM.UpvotedPosts.Add(post);
                    }
                }
            }
            return(View(myPostsVM));
        }
Beispiel #6
0
        public ActionResult MyPosts(int Page)
        {
            using (ForumRespository db = new ForumRespository())
            {

                var Model = new MyPostsViewModel();
                Model.AddNavigation("My Posts");

                if (!Request.IsAuthenticated)
                    return AuthenticationHelper.AccessDeniedView(Model); // Regardless of permissions, requires an account by neccecity

                Forum_User CurrentUser = GetCurrentUser(db);

                var Threads = db.GetSortedThreads(CurrentUser);

                Model.PageCount = (Threads.Count() - 1) / THREADS_PER_PAGE + 1;
                Model.Page = Page;

                ThreadInfoModelFromThread(db, CurrentUser, Threads.Skip(THREADS_PER_PAGE * (Page - 1)).Take(THREADS_PER_PAGE), Model.ThreadInfoList);

                return View(Model);
            }
        }