コード例 #1
0
        // public async Task<IEnumerable<PostViewModel>> GetByUser(UserViewModel user, PageViewModel pageViewModel)
        // {
        //     // var specification = new PostFilterSpecification(user.Email);
        //     // return (await _repository.List(specification)
        //     // .Skip(pageViewModel.PageSkip).Take(pageViewModel.PageMargin)
        //     // .Select(x => _mapper.Map<PostViewModel>(x))
        //     // .ToListAsync());
        // }

        public async Task <ListPostViewModel> GetNewestPostViewModel(PageViewModel pageInfo)
        {
            var listPost = new ListPostViewModel();
            var posts    = _repository.ListAll()
                           .Skip(pageInfo.PageSkip).Take(pageInfo.PageMargin)
                           .Select(x => new ListPostItem {
                CarType         = x.Category.CarType.ToString(),
                City            = x.City,
                CreatedDate     = x.CreatedDate,
                DrivenDistance  = x.Car.DrivenDistance,
                Id              = x.Id.ToString(),
                Images          = x.Car.Images,
                IsImported      = x.Category.IsImported,
                IsUsed          = x.Category.IsUsed,
                ManufactureYear = x.Car.ManufactureYear,
                Phone           = x.User.PhoneNumber,
                Price           = x.Car.Price,
                Title           = x.Title,
                Tranmission     = x.Category.Transmission.ToString()
            });

            listPost.Items = await posts.ToListAsync();

            return(listPost);
        }
コード例 #2
0
        public async Task <IActionResult> FilterPost(string country)
        {
            var posts = _fixtures.GetCountryPosts(country);

            ViewBag.Country = country;

            var modelList = new List <ListPostViewModel>();

            foreach (var post in posts)
            {
                var user = await userManager.FindByIdAsync(post.AppUserId.ToString());

                var streak = _fixtures.GetUserStreak(post.AppUserId);
                var model  = new ListPostViewModel
                {
                    Fixture  = _fixtures.GetMatchById(post.MatchId),
                    Id       = post.Id,
                    Thoughts = post.Thoughts,
                    Tip      = post.Tip,
                    UserId   = post.AppUserId,
                    PostDate = post.PostDate.Humanize(),
                    Comments = post.Comments,
                    Image    = user.Image,
                    Streak   = streak
                };
                modelList.Add(model);
            }
            return(View(modelList.Reverse <ListPostViewModel>().ToList()));
        }
コード例 #3
0
        public async Task <ListPostViewModel> GetByBrandName(string brandName)
        {
            var specification = new PostFilterSpecification(brandName);
            var listPost      = new ListPostViewModel();
            var posts         = _repository.List(specification)
                                .Select(x => new ListPostItem {
                CarType         = x.Category.CarType.ToString(),
                City            = x.City,
                CreatedDate     = x.CreatedDate,
                DrivenDistance  = x.Car.DrivenDistance,
                Id              = x.Id.ToString(),
                Images          = x.Car.Images,
                IsImported      = x.Category.IsImported,
                IsUsed          = x.Category.IsUsed,
                ManufactureYear = x.Car.ManufactureYear,
                Phone           = x.User.PhoneNumber,
                Price           = x.Car.Price,
                Title           = x.Title,
                Tranmission     = x.Category.Transmission.ToString()
            });

            listPost.Items = await posts.ToListAsync();

            return(listPost);
        }
コード例 #4
0
ファイル: PostController.cs プロジェクト: npelle/seia-gpv
        public ActionResult List(int?idCategory, string tag)
        {
            var postService     = new PostService();
            var categoryService = new CategoryService();

            var model = new ListPostViewModel();

            if (idCategory.HasValue)
            {
                model.Posts = postService.SearchPostsByCategoryId(new SearchPostsByCategoryIdRequest {
                    IdCategory = idCategory.Value
                }).Posts.Where(x => !x.IsDraft).OrderByDescending(x => x.EffectDate).ToList();
            }
            else if (!string.IsNullOrEmpty(tag))
            {
                model.Posts = postService.SearchPostsByTag(new SearchPostsByTagRequest {
                    Tag = tag
                }).Posts.Where(x => !x.IsDraft).OrderByDescending(x => x.EffectDate).ToList();
            }
            else
            {
                model.Posts = postService.SearchPosts(new SearchPostsRequest()).Posts.Where(x => !x.IsDraft).OrderByDescending(x => x.EffectDate).ToList();
            }

            ViewBag.Categories = categoryService.SearchCategories(new SearchCategoriesRequest()).Categories;

            return(View(model));
        }
コード例 #5
0
ファイル: HomeController.cs プロジェクト: Ipaskakal/TestBlog
        public IActionResult Index(int id)// id of page of posts
        {
            var model = new ListPostViewModel
            {
                PageCount = _unitOfWork.PostRepository.GetPageCount(ON_PAGE)
            };

            if (id > model.PageCount)
            {
                id = model.PageCount;
            }
            model.PageNum = id;
            var Posts = _unitOfWork.PostRepository.GetPage(model.PageNum, ON_PAGE);//Get posts displaying on this page

            if (Posts != null)
            {
                _mapper.Map(Posts, model.BlogPosts);
                int i = 0;
                foreach (var post in Posts)
                {
                    model.BlogPosts[i].CommentsCount = post.Comments.Count;
                    i++;
                }
                return(View(model));
            }
            return(View("Error"));
        }
コード例 #6
0
        public async Task <IActionResult> Index()
        {
            var posts = _fixtures.GetAllPosts();


            var modelList = new List <ListPostViewModel>();


            foreach (var post in posts)
            {
                var user = await userManager.FindByIdAsync(post.AppUserId.ToString());

                var streak = _fixtures.GetUserStreak(post.AppUserId);
                var model  = new ListPostViewModel
                {
                    Fixture  = _fixtures.GetMatchById(post.MatchId),
                    Id       = post.Id,
                    Thoughts = post.Thoughts,
                    Tip      = post.Tip,
                    UserId   = post.AppUserId,
                    PostDate = post.PostDate.Humanize(),
                    Comments = post.Comments,
                    Image    = user.Image,
                    //Streak = streak
                    Streak = _fixtures.GetUserStreak(post.AppUserId)
                };
                modelList.Add(model);
            }
            return(View(modelList));
        }
コード例 #7
0
        // GET: /<controller>/
        public async Task <IActionResult> Index(Guid id)
        {
            var user = await userManager.FindByIdAsync(id.ToString());

            var viewerId = User.FindFirstValue(ClaimTypes.NameIdentifier);

            if (user.Id == viewerId)
            {
                ViewBag.editable = true;
            }
            else
            {
                ViewBag.editable = false;
            }

            var posts = _fixtures.GetUsersPost(id);

            var userStreak = _fixtures.GetUserStreak(id);

            var userPosts = new List <ListPostViewModel>();

            foreach (var post in posts)
            {
                var poster = await userManager.FindByIdAsync(post.AppUserId.ToString());

                var streak = _fixtures.GetUserStreak(post.AppUserId);

                var up = new ListPostViewModel
                {
                    PostDate = post.PostDate.Humanize(),
                    Comments = post.Comments,
                    Fixture  = _fixtures.GetMatchById(post.MatchId),
                    Id       = post.Id,
                    Image    = poster.Image,
                    Thoughts = post.Thoughts,
                    Tip      = post.Tip,
                    UserId   = post.AppUserId,
                    Streak   = streak
                };
                userPosts.Add(up);
            }

            ProfileDetailsViewModel model = new ProfileDetailsViewModel
            {
                User       = user,
                Posts      = userPosts,
                UserStreak = userStreak
            };

            if (user != null)
            {
                //Instantiate and return ProfileVM
                return(View(model));
            }

            return(NotFound());
        }
コード例 #8
0
        public ActionResult PostList(string id, string userid)
        {
            ListPostViewModel listPostViewModel = new ListPostViewModel();
            var posts = _context.Posts.ToList().Where(p => p.BlogID == id);

            listPostViewModel.Posts  = posts;
            listPostViewModel.BlogID = id;
            listPostViewModel.UserId = userid;
            return(View(listPostViewModel));
        }
コード例 #9
0
        public ActionResult Index()
        {
            var posts =
                this.Cache.Get(
                    "posts",
                    () => this.posts.GetMostRecent(4).To <PostViewModel>().ToList(),
                    10 * 60);

            var viewModel = new ListPostViewModel
            {
                Posts = posts
            };

            return(this.View(viewModel));
        }
コード例 #10
0
        public ActionResult ListPost(int?page, string url)
        {
            var category = _db.Table_PostCategory.SingleOrDefault(a => a.Active && a.Url == url);

            if (category == null)
            {
                return(RedirectToAction("ListPost"));
            }
            var posts = _db.Posts.Where(x => x.Active && (x.PostCategoryID == category.Id || x.PostCategory.ParentCategoryId == category.Id)).OrderByDescending(x => x.CreateDate).ToPagedList(page ?? 1, 12);

            var model = new ListPostViewModel
            {
                Posts           = posts,
                PostCategory    = category,
                ChildCategories = _db.Table_PostCategory.Where(a => a.ParentCategoryId == category.Id)
            };

            return(View(model));
        }
コード例 #11
0
        // GET: /<controller>/
        public IActionResult Index()
        {
            var posts = _fixtures.GetAllPosts();

            var modelList = new List <ListPostViewModel>();

            foreach (var post in posts)
            {
                var model = new ListPostViewModel
                {
                    Fixture  = _fixtures.GetMatchById(post.MatchId),
                    Id       = post.Id,
                    Thoughts = post.Thoughts,
                    Tip      = post.Tip,
                    UserId   = post.AppUserId
                };
                modelList.Add(model);
            }
            return(View(modelList));
        }
コード例 #12
0
 public ActionResult Indexx(ListPostViewModel model, int postId)
 {
     //            postService.createPost(model.Title, model.Id);
     //return PartialView("TimeLine");
     return(RedirectToAction("TimeLine"));
 }
コード例 #13
0
        // GET: Posts
        public ActionResult List(string area_sl, string loc_sl, string cate_sl, string subc_sl, string keyword, int Page = 1)
        {
            var         searchviewmodel = new SearchViewModel();
            Area        area            = null;
            Locale      locale          = null;
            Category    category        = null;
            Subcategory subcategory     = null;
            List <Post> posts           = null;

            if (cate_sl == null)
            {
                if (keyword == null)
                {
                    return(HttpNotFound());
                }
                else
                {
                    // locale, area legal
                    var check = acl.CheckSearchLegal(area_sl, loc_sl, ref area, ref locale);
                    if (check == false)
                    {
                        return(HttpNotFound());
                    }
                    else
                    {
                        posts = postl.Search(keyword, area.Id, locale == null ? (int?)null : locale.Id, ref category);
                        if (posts.Count == 0)
                        {
                            //no match post
                            TempData["Error_Keyword"] = "no posts related to " + keyword;
                            return(RedirectToAction("List", "Index", new { area_sl = area_sl, loc_sl = loc_sl }));
                        }
                    }
                }
            }
            else
            {
                var check = acl.CheckSearchLegal(area_sl, loc_sl, cate_sl, subc_sl, ref area, ref locale, ref category, ref subcategory);
                if (check == false)
                {
                    return(HttpNotFound());
                }
                else
                {
                    if (keyword == null)
                    {
                        posts = postl.PostFilter(area.Id, locale == null ? (int?)null : locale.Id, category.Id, subcategory == null ? (int?)null : subcategory.Id);
                        if (posts.Count == 0)
                        {
                            ModelState.AddModelError("Filter", "No posts");
                        }
                    }
                    else
                    {
                        posts = postl.Search(keyword, area.Id, locale == null ? (int?)null : locale.Id, category.Id, subcategory == null ? (int?)null : subcategory.Id);
                        if (posts.Count == 0)
                        {
                            ModelState.AddModelError("Filter", "No posts related to " + keyword);
                        }
                    }
                }
            }

            var tmpposts  = postl.PostFilterPartial(posts, (Page - 1) * 5, 5);
            var partposts = new List <ListPostViewModel>();

            foreach (var p in tmpposts)
            {
                var tmppost = new ListPostViewModel()
                {
                    Title     = p.Title,
                    Timestamp = p.Timestamp,
                    PostId    = p.Id,
                    Email     = db.Users.Find(p.Owner).Email
                };
                partposts.Add(tmppost);
            }

            searchviewmodel.CurrentPage   = Page;
            searchviewmodel.PageCount     = (posts.Count + 4) / 5; //every page show 5 posts
            searchviewmodel.Area          = area;
            searchviewmodel.Locale        = locale;
            searchviewmodel.Category      = category;
            searchviewmodel.Subcategory   = subcategory;
            searchviewmodel.Posts         = partposts;
            searchviewmodel.Areas         = locl.Area_List();
            searchviewmodel.Locales       = locl.Locale_List(area.Id);
            searchviewmodel.Categories    = typel.Category_List();
            searchviewmodel.Subcategories = typel.Subcategory_List(category.Id);
            searchviewmodel.Keyword       = keyword;
            return(View(searchviewmodel));
        }