public ActionResult DeleteConfirmed(string id) { UserToCategory userToCategory = db.UserToCategories.Find(id); db.UserToCategories.Remove(userToCategory); db.SaveChanges(); return(RedirectToAction("Index")); }
//increase in 1 the NumOfVisits and updateds the LastTouched date public void categoryWasViewd(string CategoryName, string userName) { UserToCategory userCategory = db.UserToCategories.Where(d => d.CategoryName == CategoryName && d.UserName == userName).ToList().ElementAt(0); userCategory.NumOfVisits++; userCategory.LastTouched = DateTime.Today; db.SaveChanges(); }
public ActionResult Edit([Bind(Include = "UserName,CategoryName")] UserToCategory userToCategory) { if (ModelState.IsValid) { db.Entry(userToCategory).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CategoryName = new SelectList(db.Categories, "Name", "Name", userToCategory.CategoryName); ViewBag.UserName = new SelectList(db.Users, "UserName", "FirstName", userToCategory.UserName); return(View(userToCategory)); }
public ActionResult Create([Bind(Include = "UserName,CategoryName,NumOfVisits,LastTouched")] UserToCategory userToCategory) { if (ModelState.IsValid) { db.UserToCategories.Add(userToCategory); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CategoryName = new SelectList(db.Categories, "Name", "Name", userToCategory.CategoryName); ViewBag.UserName = new SelectList(db.Users, "UserName", "FirstName", userToCategory.UserName); return(View(userToCategory)); }
// GET: UserToCategories/Details/5 public ActionResult Details(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } UserToCategory userToCategory = db.UserToCategories.Find(id); if (userToCategory == null) { return(HttpNotFound()); } return(View(userToCategory)); }
// GET: UserToCategories/Edit/5 public ActionResult Edit(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } UserToCategory userToCategory = db.UserToCategories.Find(id); if (userToCategory == null) { return(HttpNotFound()); } ViewBag.CategoryName = new SelectList(db.Categories, "Name", "Name", userToCategory.CategoryName); ViewBag.UserName = new SelectList(db.Users, "UserName", "FirstName", userToCategory.UserName); return(View(userToCategory)); }
public ActionResult statisticList() { var v = Session["UserName"]; User user = db.Users.Find(v); int sumEntry = 0; // List <UserToCategory> intrests = user.Interests.OrderBy(c => c.NumOfVisits).ToList(); List <UserToCategory> top10 = new List <UserToCategory>(); // List <Post> allPost = db.Posts.OrderBy(p => p.Rating).ToList(); List <Post> recommended = new List <Post>(); // int numOfCategorys = Math.Min(10, intrests.Count()); //in case the user is new and did not watch any content yet if (intrests.Where(i => i.NumOfVisits > 0).Count() == 0) { allPost = db.Posts.OrderBy(p => p.Rating).OrderBy(o => o.Date).ToList(); Session["recommended"] = allPost; return(View("Home")); } //adding the top 10 categorys into an orgenaized list for (int i = 0; i < numOfCategorys; i++) { var elemnt = intrests.ElementAt(i); top10.Add(elemnt); sumEntry += elemnt.NumOfVisits; } int num; for (int i = 0; i < numOfCategorys; i++) { //calculating the num of of posts that we wiil display for the spec category UserToCategory current = top10.ElementAt(i); double cerunt = ((double)current.NumOfVisits / sumEntry); List <Post> fromCategory = allPost.Where((p) => p.Categories.Where(c => c.CategoryName == current.CategoryName).Count() > 0).ToList(); num = Math.Min((int)(Math.Round(cerunt * 20)), fromCategory.Count()); //adding the posts from the spec category into the recomended list for (int j = 0; j < num; j++) { recommended.Add(fromCategory.ElementAt(j)); } } Session["recommended"] = recommended; return(View("Home")); }