public ActionResult Index() { HahaVilleContext db = new HahaVilleContext(); List<Category> listOfCategory = db.Category.ToList(); List<Game> listOfGames = new List<Game>(); List<GameInfo> listOfGameInfos = new List<GameInfo>(); foreach (var category in listOfCategory) { listOfGames.AddRange((from g in db.Games where g.Category.Id == category.Id select g).Take(4)); } int[] arrOfGameIds = null; arrOfGameIds = listOfGames.Select(x => x.Id).ToArray(); LocalizedProperty[] arrProps = (from props in db.LocalizedProperties where arrOfGameIds.Contains(props.EntityId) && props.LanguageId == 1 select props).ToArray(); foreach (var category in listOfCategory) { foreach (var game in listOfGames.Where(x => x.CategoryId == category.Id)) { LocalizedProperty[] arrGameProps = arrProps.Where(x => x.EntityId == game.Id).ToArray(); GameInfo objGI = new GameInfo() { Id = game.Id, LanguageId = 1, CategoryId = category.Id, Thumbnail = game.Thumbnail, Uri = game.GamePath}; if (arrGameProps.Length > 0) { LocalizedProperty lpName = arrGameProps.Where(x => x.LocaleKey.Equals("game.name")).FirstOrDefault(); LocalizedProperty lpTitle = arrGameProps.Where(x => x.LocaleKey.Equals("game.metatitle")).FirstOrDefault(); LocalizedProperty lpDesc = arrGameProps.Where(x => x.LocaleKey.Equals("game.desc")).FirstOrDefault(); LocalizedProperty lpKeyword = arrGameProps.Where(x => x.LocaleKey.Equals("game.metakeyword")).FirstOrDefault(); LocalizedProperty lpCatName = arrGameProps.Where(x => x.LocaleKey.Equals("category.name")).FirstOrDefault(); objGI.Name = lpName != null ? lpName.LocaleValue : string.Empty; objGI.Title = lpTitle != null ? lpTitle.LocaleValue : string.Empty; objGI.Description = lpDesc != null ? StringHtmlExtensions.TruncateHtml(lpDesc.LocaleValue, 90, "... <br /> <a href=\"games/" + game.Name.Replace(" ","-") + "\" >(View Details)</a>") : string.Empty; objGI.Keyword = lpKeyword != null ? lpKeyword.LocaleValue : string.Empty; objGI.CategoryName = lpCatName != null ? lpCatName.LocaleValue : category.Name; } listOfGameInfos.Add(objGI); } } //List<User> listOfUsers = db.Users.ToList(); return View(listOfGameInfos); }
public ActionResult Details(string name) { //int nGameId = 0; GameInfo objGI = null; //if (int.TryParse(name, out nGameId)) //{ HahaVilleContext db = new HahaVilleContext(); var objTargetGame = (from g in db.Games where g.Name == name.Replace("-", " ") select new { Id = g.Id, Thumbnail = g.Thumbnail, Uri = g.GamePath, CategoryId = g.CategoryId, Props = g.LocalizedProperties, }).FirstOrDefault(); if (objTargetGame != null) { objGI = new GameInfo() { Id = objTargetGame.Id, LanguageId = 1, CategoryId = objTargetGame.CategoryId, Thumbnail = objTargetGame.Thumbnail, Uri = objTargetGame.Uri, }; if (objTargetGame.Props != null && objTargetGame.Props.Count > 0) { LocalizedProperty lpName = objTargetGame.Props.Where(x => x.LocaleKey.Equals("game.name")).FirstOrDefault(); LocalizedProperty lpTitle = objTargetGame.Props.Where(x => x.LocaleKey.Equals("game.metatitle")).FirstOrDefault(); LocalizedProperty lpDesc = objTargetGame.Props.Where(x => x.LocaleKey.Equals("game.desc")).FirstOrDefault(); LocalizedProperty lpKeyword = objTargetGame.Props.Where(x => x.LocaleKey.Equals("game.metakeyword")).FirstOrDefault(); LocalizedProperty lpCatName = objTargetGame.Props.Where(x => x.LocaleKey.Equals("category.name")).FirstOrDefault(); objGI.Name = lpName != null ? lpName.LocaleValue : string.Empty; objGI.Title = lpTitle != null ? lpTitle.LocaleValue : string.Empty; objGI.Description = lpDesc != null ? lpDesc.LocaleValue : string.Empty; objGI.Keyword = lpKeyword != null ? lpKeyword.LocaleValue : string.Empty; objGI.CategoryName = lpCatName != null ? lpCatName.LocaleValue : string.Empty; } } //} if (objGI != null) { return View(objGI); } else { return RedirectToAction("Index", "Home"); } }