public ActionResult SearchNotes() { var notes = _context.GetSellerNote(); string[] rating = { "1+", "2+", "3+", "4+", "5" }; List <string> ratings = new List <string>(rating); SearchNotes model = new SearchNotes { sellerNotes = notes.Skip(0).Take(6), Categories = _context.GetCategories(), Types = _context.GetTypes(), Universities = _context.GetUniversities(), Courses = _context.GetCourses(), Countries = _context.GetCountries(), RatingList = ratings, totalCount = notes.Count(), perPageCount = 6 }; foreach (var note in model.sellerNotes) { note.avg = _context.GetAvgRatingByNoteId(note.ID); note.count = _context.GetRatingCount(note.ID); note.inappropriateCount = _context.GetNotesReportedIssueCount(note.ID); } return(View(model)); }
public ActionResult SearchNotesPagination(int start = 0, int count = 6) { var notes = _context.GetSellerNote(); SearchNotes model = new SearchNotes { sellerNotes = notes.Skip(start).Take(count) }; foreach (var note in model.sellerNotes) { note.avg = _context.GetAvgRatingByNoteId(note.ID); note.count = _context.GetRatingCount(note.ID); note.inappropriateCount = _context.GetNotesReportedIssueCount(note.ID); } return(Json(model, JsonRequestBehavior.AllowGet)); }
public ActionResult SearchNotes(string search, string type, string category, string university, string course, string country, string ratings, int?page) { //if logged in user's userrole is not member then redirect to admin dashboard if (User.Identity.IsAuthenticated) { var user = dobj.Users.Where(x => x.EmailID == User.Identity.Name).FirstOrDefault(); if (user.RoleID != dobj.UserRole.Where(x => x.Name.ToLower() == "member").Select(x => x.ID).FirstOrDefault()) { return(RedirectToAction("Dashboard", "Admin")); } } ViewBag.SearchNotes = "active"; ViewBag.Search = search; ViewBag.Category = category; ViewBag.Type = type; ViewBag.University = university; ViewBag.Course = course; ViewBag.Country = country; ViewBag.Rating = ratings; //for dropdown ViewBag.CategoryList = dobj.NoteCategories.Where(x => x.IsActive == true).ToList(); ViewBag.TypeList = dobj.NoteTypes.Where(x => x.IsActive == true).ToList(); ViewBag.CountryList = dobj.Countries.Where(x => x.IsActive == true).ToList(); ViewBag.UniversityList = dobj.NoteDetail.Where(x => x.IsActive == true && x.UniversityName != null && x.Status == 9).Select(x => x.UniversityName).Distinct(); ViewBag.CourseList = dobj.NoteDetail.Where(x => x.IsActive == true && x.Course != null && x.Status == 9).Select(x => x.Course).Distinct(); ViewBag.RatingList = new List <SelectListItem> { new SelectListItem { Text = "1+", Value = "1" }, new SelectListItem { Text = "2+", Value = "2" }, new SelectListItem { Text = "3+", Value = "3" }, new SelectListItem { Text = "4+", Value = "4" }, new SelectListItem { Text = "5", Value = "5" } }; //details of publish notes var noteslist = dobj.NoteDetail.Where(x => x.Status == 9); // search field is fillup if (!String.IsNullOrEmpty(search)) { noteslist = noteslist.Where(x => x.Title.ToLower().Contains(search.ToLower()) || x.NoteCategories.Name.ToLower().Contains(search.ToLower()) ); } // for note type of notes if (!String.IsNullOrEmpty(type)) { noteslist = noteslist.Where(x => x.NoteType.ToString().ToLower().Contains(type.ToLower())); } // for note category of notes if (!String.IsNullOrEmpty(category)) { noteslist = noteslist.Where(x => x.Category.ToString().ToLower().Contains(category.ToLower())); } // for university if (!String.IsNullOrEmpty(university)) { noteslist = noteslist.Where(x => x.UniversityName.ToLower().Contains(university.ToLower())); } // for course detail if (!String.IsNullOrEmpty(course)) { noteslist = noteslist.Where(x => x.Course.ToLower().Contains(course.ToLower())); } // for country detail if (!String.IsNullOrEmpty(country)) { noteslist = noteslist.Where(x => x.Country.ToString().ToLower().Contains(country.ToLower())); } List <SearchNotes> searchnoteslist = new List <SearchNotes>(); if (String.IsNullOrEmpty(ratings)) { foreach (var item in noteslist) { var review = dobj.NotesReview.Where(x => x.NoteID == item.ID && x.IsActive == true).Select(x => x.Ratings); var totalreview = review.Count(); var avgreview = totalreview > 0 ? Math.Ceiling(review.Average()) : 0; var spamcount = dobj.SpamReport.Where(x => x.NoteID == item.ID).Count(); SearchNotes note = new SearchNotes() { Note = item, AverageRating = Convert.ToInt32(avgreview), TotalRating = totalreview, TotalSpam = spamcount }; //add obj in searchnoteslist searchnoteslist.Add(note); } } else { foreach (var item in noteslist) { var review = dobj.NotesReview.Where(x => x.NoteID == item.ID).Select(x => x.Ratings); var totalreview = review.Count(); var avgreview = totalreview > 0 ? Math.Ceiling(review.Average()) : 0; var spamcount = dobj.SpamReport.Where(x => x.NoteID == item.ID).Count(); if (avgreview >= Convert.ToInt32(ratings)) { SearchNotes note = new SearchNotes() { Note = item, AverageRating = Convert.ToInt32(avgreview), TotalRating = totalreview, TotalSpam = spamcount }; // add object into list searchnoteslist.Add(note); } } } ViewBag.ResultCount = searchnoteslist.Count(); return(View(searchnoteslist.ToList().AsQueryable().ToPagedList(page ?? 1, 9))); }