public IEnumerable <MatchAndUserView> GetMatches(int userId) { var allUserGames = userGames.GetAllUserGames(); var allUserSearches = userSearches.GetAllUserSearches(); var allGames = games.GetGames(" "); var myForExchangeIds = allUserGames.Where(g => g.UserId == userId).Select(g => g.GameId); var mySearchesIds = allUserSearches.Where(g => g.UserId == userId).Select(g => g.GameId); var matchedBySearches = allUserGames.Where(g => mySearchesIds.Contains(g.GameId) && g.UserId != userId).Select(g => g.UserId).Distinct(); var matchedByForExchange = allUserSearches.Where(g => myForExchangeIds.Contains(g.GameId) && g.UserId != userId).Select(g => g.UserId).Distinct(); var matchedUsers = matchedByForExchange.Where(u => matchedBySearches.Contains(u)); List <MatchAndUserView> myMatches = new List <MatchAndUserView>(); foreach (var user in matchedUsers) { var gamesTheyHaveIds = allUserGames.Where(g => g.UserId == user).Select(g => g.GameId); var gamesTheyWantIds = allUserSearches.Where(g => g.UserId == user).Select(g => g.GameId); var profile = userProfiles.GetUserProfile(user); var comments = userProfiles.GetComments(user); var avgMark = comments.Select(c => c.Mark).Sum() / comments.Count(); avgMark = !(avgMark > 0) ? 0 : Math.Round(avgMark, 2); myMatches.Add(new MatchAndUserView() { OtherUserId = user, Name = profile.Name + " " + profile.Surname, AvgMark = avgMark, Location = profile.Location, UserImageUrl = profile.ImageUrl, GamesTheyHave = allGames.Where(g => gamesTheyHaveIds.Contains(g.GameId)).Select(g => g.Title).ToArray(), GamesTheyWant = allGames.Where(g => gamesTheyWantIds.Contains(g.GameId)).Select(g => g.Title).ToArray() }); } return(myMatches); }
public IEnumerable <DropDownItem> GetGamesList(string query) { var games = gamesDao.GetGames(query); return(games.Select(g => new DropDownItem { Id = g.GameId, Name = g.Title })); }
public IEnumerable <GameView> GetAllGames(string query) { var gamesDetails = games.GetGames(query); List <GameView> gameDtos = new List <GameView>(); foreach (var game in gamesDetails) { var genre = games.GetGenre(game.GenreId).Name; gameDtos.Add(mappingService.GetGameViewFromGame(game, genre)); } return(gameDtos); }
private bool NotChallenged(string name, string first, string last, int contestNr) { var yourValues = contestNr + " " + first.ToLower() + " " + last.ToLower(); var count = 0; var personsName = ""; var isNull = 0; var personList = _game.GetPersons(); var gameList = _game.GetGames(); string[] arrayValue = new string[300]; int i = 0; var isGame = 0; foreach (var item in gameList) { if (item.PersonOne.ToLower() == yourValues.ToLower()) //Kollar om du är på plats 1 { arrayValue[i] = item.PersonTwo.ToLower(); count++; i++; } else if (item.PersonTwo.ToLower() == yourValues.ToLower()) //Kollar om du är på plats 2 { arrayValue[i] = item.PersonOne.ToLower(); count++; i++; } isGame = 1; } if (isGame == 1) { if (count >= 10) { Console.WriteLine("Du har redan {0} matcher, vill du skriva upp dig för att kunna spela {1}?", count, count + 1); var value = Console.ReadLine(); if (value.Contains("Ja")) { var items = _game.PathWriting(first, last, count + 1, contestNr); Console.WriteLine(items); var builder = _game.RequestMessageToSystem(first, last, contestNr); } } else { foreach (var values in personList.Distinct()) { var number = values.ContestNumber; var other = number + " " + values.FirstName.ToLower() + " " + values.LastName.ToLower(); arrayValue[i + 1] = yourValues.ToLower(); var isTrue = arrayValue.Contains(other.ToLower()); if (isTrue == true) { count++; } else { Console.WriteLine($"Välj: {values.ContestNumber} Om du vill möta {values.FirstName} {values.LastName}"); } } } isNull = 1; } if (isNull == 0) //Om inga spel finns! { foreach (var values in personList.Distinct()) { if (values.ContestNumber != contestNr) { Console.WriteLine("Välj: {0} Om du vill möta {1} {2}", values.ContestNumber, values.FirstName, values.LastName); } } } try { if (count < 10) //Kolla om matcher är mindre än 10 { isNull = 1; var id = int.Parse(Console.ReadLine()); foreach (var foreachs in personList) { if (foreachs.ContestNumber == id) { personsName = foreachs.ContestNumber + " " + foreachs.FirstName.ToLower() + " " + foreachs.LastName.ToLower(); } } //Kolla om personen har matcher med den utvalda! foreach (var items in gameList) { if (items.PersonOne.ToLower() == yourValues.ToLower() && items.PersonTwo.ToLower() == personsName.ToLower() || items.PersonTwo.ToLower() == yourValues.ToLower() && items.PersonOne.ToLower() == personsName.ToLower()) { isNull = 0; Console.WriteLine("Du har redan en match med den utvalda personen!"); return(false); } else if (items.PersonOne.ToLower() == yourValues.ToLower() && items.PersonTwo.ToLower() == yourValues.ToLower()) { isNull = 0; Console.WriteLine("Du kan inte ha en match med dig själv...."); return(false); } } if (isNull == 1) { var getNumber = 0; foreach (var number in gameList) { if (getNumber < number.GameNumber) { getNumber = number.GameNumber; } } var countings = getNumber + 1; var value = new Game(name, countings, yourValues, personsName); //email var addingToGame = _game.GameToFile(value); Console.WriteLine("Välj vilken bowlinghall ni ska spela på: "); Console.WriteLine("1) Bowling Discos"); Console.WriteLine("2) Monas bowlinghall"); Console.WriteLine("3) LunaBowl"); Console.Write("Ange antingen nummer eller namn: "); var input = Console.ReadLine(); PathCompound enviro = new PathCompound(input); enviro.Display(); var addingToPath = _game.PathToFile(getNumber, yourValues, personsName, input, enviro._paths); } } } catch (FormatException) { Console.WriteLine("Du kan bara skriva in siffror.."); } return(true); }
public async Task <ActionResult <IEnumerable <GamesDTO> > > GetGames() { return(await _games.GetGames()); }