// GET: User public ActionResult AllPost(string pageNumber) { Account account = new Account(); if (Session["account"] == null) { return(RedirectToAction("Index", "Home")); } else { account = Session["account"] as Account; if (account.Role == 0) { return(RedirectToAction("AllPost", "Admin")); } else if (account.Role == 2) { return(RedirectToAction("ChangeInfo", "Account")); } } int pageN = 1; if (pageNumber != null) { pageN = Int32.Parse(pageNumber); } List <PostManagerModel> list = new List <PostManagerModel>(); var listSearchResult = SearchResult.CreateListSearchResult().Where(p => p.AccountID == account.AccountID).ToList(); var postList = listSearchResult.Skip((pageN - 1) * PageSize).Take(PageSize).ToList(); if (postList != null && postList.Count() > 0) { foreach (var item in postList) { list.Add(new PostManagerModel() { Post = item, ImageList = GetImage.getListImage(item.MotelID), motelID = item.MotelID }); } } var subTotalPage = listSearchResult.Count / PageSize; var totalPage = (listSearchResult.Count % PageSize == 0) ? subTotalPage : subTotalPage + 1; ViewBag.PageNumber = pageN; ViewBag.TotalPage = totalPage; return(View(list)); }
private List <PostViewModel> CreateListPostViewModel(List <SearchResult> listPosts) { List <PostViewModel> list = new List <PostViewModel>(); using (var db = new QLTroEntities()) { if (listPosts != null && listPosts.Count > 0) { foreach (var item in listPosts) { list.Add(new PostViewModel() { Post = item, ImageList = GetImage.getListImage(item.MotelID) }); } } } return(list); }
public static List <PostViewModel> CreateListPostViewModel(int provinceID, int districtID) { List <PostViewModel> list = new List <PostViewModel>(); using (var db = new QLTroEntities()) { var searchResult = SearchResult.CreateListSearchResult().Where(p => p.ProvinceID == provinceID && p.DistrictID == districtID && p.AccountStatus == 1 && p.PostStatus == true).ToList(); if (searchResult != null && searchResult.Count > 0) { foreach (var item in searchResult) { list.Add(new PostViewModel() { Post = item, ImageList = GetImage.getListImage(item.MotelID) }); } } } return(list); }
public ActionResult PostDetails(string postID) { PostDetailsViewModel post = new PostDetailsViewModel(); var success = UpdatePostView(postID); if (success) { var temp = Int32.Parse(postID); post.Post = KhoaLuan.ViewModels.SearchResult.CreateListSearchResult().FirstOrDefault(p => p.PostID.Equals(temp)); post.ImageList = GetImage.getListImage(post.Post.MotelID); if (Session["historyPost"] != null) { var history = Session["historyPost"] as historyPost; if (history.ListID.Count > 2) { var x = history.ListID[0]; history.ListID.Remove(x); } if (history.ListID.Count > 0) { post.ViewedPost = new List <SearchResult>(); var n = history.ListID.Count; for (int i = n - 1; i >= 0; i--) { post.ViewedPost.Add(KhoaLuan.ViewModels.SearchResult.CreateListSearchResult().FirstOrDefault(p => p.PostID == history.ListID[i])); } var reslult = true; foreach (var item in history.ListID) { if (item == temp) { reslult = false; } } if (reslult) { history.ListID.Add(temp); } } else { var h = new historyPost() { ListID = new List <int>() { temp } }; Session["historyPost"] = h; } } else { if (Session["historyPost"] == null) { var h = new historyPost() { ListID = new List <int>() { temp } }; Session["historyPost"] = h; Session.Timeout = 10; } } post.SuggestPost = new List <SearchResult>(); var q = from s in KhoaLuan.ViewModels.SearchResult.CreateListSearchResult() where s.ProvinceID == post.Post.ProvinceID && s.DistrictID == post.Post.DistrictID orderby s.PostView descending select s; int j = 0; foreach (var i in q) { post.SuggestPost.Add(i); j++; if (j > 3) { break; } } return(View(post)); } return(View(post)); }