private IList <ReviewDesc> GetAllReviews(int?pageIndex) { ITaxonRepository Taxon = new TaxonRepository(); IReviewRepository reviews = new ReviewRepository(); // IList<ReviewDesc> review = Taxon.GetAllReviews(); int currentIndex = (int)(pageIndex ?? 1); //int count = review.Count; // int count = Taxon.getAllReviews().Count; SqlQuery query = Select.AllColumnsFrom <VwAllReview>(); int count = query.GetRecordCount(); ViewData["TotalItemCount"] = count; ViewData["PageNumber"] = currentIndex; ViewData["PageSize"] = UpdateUtils.DEFAULT_PAGE_SIZE; IList <ReviewDesc> review = Taxon.GetAllReviewsPaged(currentIndex, UpdateUtils.DEFAULT_PAGE_SIZE); var sortedReviews = from r in review orderby r.CtyShort select r; int pagedCount = review.Count; if (pagedCount > 0) { for (int i = 0; i < pagedCount; i++) { review[i].TaxonName = Taxon.getReviewTaxonName(review[i].ID, review[i].Taxontype, review[i].Kingdom); review[i].Paragraph = Taxon.getParagraphStagePerReview(review[i].ID); review[i].Concern = reviews.getConcernForReview(review[i].ID); review[i].DeadlineDate = Taxon.getDeadlineDatePerReview(review[i].ID); } } if (pagedCount <= 0) { review = null; } return(review); }
//GET: /AddReview/ListAll public ActionResult ListAll(int?page, int?searched) { if (page.HasValue) { //return RedirectToAction("ListAll", new { collection = (FormCollection)Session["search_form"], page = page, searched = 1 }); ITaxonRepository RPtaxons = new TaxonRepository(); IReviewRepository RPreviews = new ReviewRepository(); string freesearch, searchcountry, searchall = ""; FormCollection collection = (FormCollection)Session["search_form"]; try { //freesearch = collection["search1"]; freesearch = collection["search_free"]; searchcountry = collection["search2"]; searchall = collection["search3"]; IList <ReviewDesc> reviews = null; IList <ReviewDesc> reviews2 = null; //return reviews; string nodata = "No search results found"; if (freesearch != null) { var search = collection["searchspecies"]; if (search.IndexOf('-') == -1) { return(RedirectToAction("Search", "SearchReview")); } string searchstring = collection["searchspecies"]; searchstring = searchstring.Trim(); string[] splitstring = searchstring.Split('-'); //Have changed coding now - the genus species is returned, so need to split further to keep same method string[] taxonString = splitstring[0].Split(' '); reviews = RPreviews.getAllReviewsbyFreeSearch(taxonString[0].Trim(), taxonString[1].Trim()); } else if (searchcountry != null) { string countryID = collection["searchcountry"]; if (countryID.ToUpper().Contains(UpdateUtils.SELECT_ALL)) { reviews = this.GetAllReviews(null); } else { int country = int.Parse(countryID); reviews = RPreviews.getAllReviewsbyCountry(country); } } else if (searchall != null) { int phase = int.Parse(collection["phase"]); string kingdom = collection["kingdom"]; //-2 is for select all int genus = -2; int species = -2; int country = -2; if (collection["agenus"] != null) { genus = int.Parse(collection["agenus"]); } if (collection["aspecies"] != null) { species = int.Parse(collection["aspecies"]); } if (collection["acountries"] != null) { country = int.Parse(collection["acountries"]); } if (kingdom.Equals(UpdateUtils.ALL_KINGDOM.ToString())) { IList <ReviewDesc> reviewstemp = RPreviews.getAllReviewsbySearchAll(phase, UpdateUtils.ANIMALS, genus, species, country); reviews2 = RPreviews.getAllReviewsbySearchAll(phase, UpdateUtils.PLANTS, genus, species, country); if (reviewstemp != null && reviews2 != null) { reviews = reviewstemp.Concat(reviews2).ToList(); } if (reviewstemp == null && reviews2 != null) { reviews = reviews2; } if (reviewstemp != null && reviews2 == null) { reviews = reviewstemp; } else { reviews = null; } } else { reviews = RPreviews.getAllReviewsbySearchAll(phase, kingdom, genus, species, country); } } int count = 0; if (reviews != null) { count = reviews.Count; } if (count > 0) { for (int i = 0; i < count; i++) { // reviews[i].TaxonName = RPtaxons.getReviewTaxonName(reviews[i].TaxonID, reviews[i].Taxontype, // reviews[i].Kingdom); reviews[i].Paragraph = RPtaxons.getParagraphStagePerReview(reviews[i].ID); reviews[i].Concern = RPreviews.getConcernForReview(reviews[i].ID); reviews[i].DeadlineDate = RPtaxons.getDeadlineDatePerReview(reviews[i].ID); } } int ij = 10; if (reviews == null) { return(RedirectToAction("Search", "SearchReview", new { NoSearchResults = true })); } var sortedReviews = from r in reviews orderby r.DateAdded select r; //PageIndex int PageIndex = 0; if (page.HasValue) { PageIndex = (int)page; } IPagedList <ReviewDesc> pagedReview = sortedReviews.ToPagedList(PageIndex, UpdateUtils.DEFAULT_PAGE_SIZE); ViewData["AllReviews"] = pagedReview;//sortedReviews.ToPagedList(1,count); ViewData["PageSize"] = UpdateUtils.DEFAULT_PAGE_SIZE; ViewData["PageNumber"] = PageIndex; ViewData["TotalItemCount"] = count; return(View()); } catch { return(RedirectToAction("Search", "SearchReview")); } } ViewData["AllReviews"] = this.GetAllReviews(page); return(View()); }