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

            this.BindingContext = myPostsViewModel;

            InitializeComponent();
        }
예제 #2
0
        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));
        }
예제 #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));
        }
예제 #4
0
 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));
     }
 }
예제 #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));
        }
예제 #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);
            }
        }