public IActionResult Details(long id, string type, string screenshot = null) { var userId = this.User.FindFirst(ClaimTypes.NameIdentifier)?.Value; List <ItemUser> joinList = _db.ItemUser.Where(join => join.UserId == userId).Include(join => join.Item).ToList(); List <long> userApiIds = new List <long>(); foreach (ItemUser join in joinList) { userApiIds.Add(join.Item.ApiId); } ItemDetailsViewModel model = new ItemDetailsViewModel(); model.ApiIds = userApiIds; if (type == "game") { RawgIdRoot result = Rawg.GetGameById(id); model.GameDetails = result; model.ScreenShot = screenshot; } else if (type == "movie") { TmdbMovieRoot result = Tmdb.GetMovieById(id); model.MovieDetails = result; } else if (type == "tv") { TmdbTvRoot result = Tmdb.GetTvById(id); model.TvDetails = result; } return(View(model)); }
public async Task <IActionResult> Create(long id, string type, string screenshot) { var userId = this.User.FindFirst(ClaimTypes.NameIdentifier)?.Value; var currentUser = await _userManager.FindByIdAsync(userId); Item newItem = new Item(); if (type == "game") { RawgIdRoot itemDetails = Rawg.GetGameById(id); newItem.GetRawgValues(itemDetails); newItem.Poster = screenshot; newItem.Priority = currentUser.PriorityValue; _db.Items.Add(newItem); ItemUser newItemUser = new ItemUser { Item = newItem, User = currentUser, ItemId = newItem.ItemId, UserId = userId }; _db.ItemUser.Add(newItemUser); currentUser.PriorityValue++; var result = await _userManager.UpdateAsync(currentUser); _db.SaveChanges(); } else if (type == "movie") { TmdbMovieRoot itemDetails = Tmdb.GetMovieById(id); newItem.GetTmdbMovieValues(itemDetails); newItem.Priority = currentUser.PriorityValue; _db.Items.Add(newItem); ItemUser newItemUser = new ItemUser { Item = newItem, User = currentUser, ItemId = newItem.ItemId, UserId = userId }; _db.ItemUser.Add(newItemUser); currentUser.PriorityValue++; var result = await _userManager.UpdateAsync(currentUser); _db.SaveChanges(); } else if (type == "tv") { TmdbTvRoot itemDetails = Tmdb.GetTvById(id); newItem.GetTmdbTvValues(itemDetails); newItem.Priority = currentUser.PriorityValue; _db.Items.Add(newItem); ItemUser newItemUser = new ItemUser { Item = newItem, User = currentUser, ItemId = newItem.ItemId, UserId = userId }; _db.ItemUser.Add(newItemUser); currentUser.PriorityValue++; var result = await _userManager.UpdateAsync(currentUser); _db.SaveChanges(); } return(RedirectToAction("Index", new { typeFilter = type })); }
public void GetRawgValues(RawgIdRoot input) { this.Type = "game"; this.ApiId = input.Id; this.Name = input.Name; if (input.DescriptionRaw.Length > 500) { this.Description = input.DescriptionRaw.Substring(0, 500) + "...(CONT.)"; } else { this.Description = input.DescriptionRaw; } this.Released = input.Released; this.BackgroundImage = input.BackgroundImage; }