public void LoadUsersAllDreams() { CheckConnection(); int id = Convert.ToInt32(Session["usId"]); string name = _db.Users.Where(x => x.ID == id).Select(e => e.UserName).FirstOrDefault(); ViewBag.username = name; var dreams = _db.Dreams.Where(x => x.UserID == id && x.isPublic == true).OrderByDescending(e => e.CreateDate).ToList(); var dataFinal = new List <DreamViewModel>(); foreach (var dream in dreams) { var dreamcustom = new DreamViewModel() { Id = dream.ID, UserID = dream.UserID, Title = dream.Title, Description = dream.Description, CreateDate = dream.CreateDate, Categories = dream.DreamAndCategories.Select(e => e.Category.Name).ToList(), CategoryIcon = dream.DreamAndCategories.First().Category.Icon, Tags = dream.DreamAndTags.Select(e => e.Tag.Name).ToList() }; dataFinal.Add(dreamcustom); } int dreamIndex = 1; HttpContext.Cache["Dreams"] = dataFinal.ToDictionary(x => dreamIndex++, x => x); ViewBag.TotalNumberDreams = dataFinal.Count(); }
public ActionResult Search() { CheckConnection(); var dreams = _db.Dreams.Where(x => x.isPublic == true).OrderByDescending(x => x.CreateDate).ToList(); var dataFinal = new List <DreamViewModel>(); foreach (var dream in dreams) { var dreamcustom = new DreamViewModel() { Id = dream.ID, UserID = dream.UserID, Title = dream.Title, Description = dream.Description, CreateDate = dream.CreateDate, Categories = dream.DreamAndCategories.Select(e => e.Category.Name).ToList(), CategoryIcon = dream.DreamAndCategories.First().Category.Icon, Tags = dream.DreamAndTags.Select(e => e.Tag.Name).ToList() }; dataFinal.Add(dreamcustom); } return(View(dataFinal)); }