private static async Task UpdateExistingCandidates(ContestantRepository repository, IEnumerable <Contestant> contestantsInDb, ContestantRequest[] masterContestantList, int warId, Func <Contestant, ContestantRequest, bool> IsTheSame) { var updates = masterContestantList.Where(c1 => contestantsInDb.Any(c2 => IsTheSame(c2, c1))) .Select(c => new Contestant { Definition = c.Definition, Id = contestantsInDb.Single(c1 => IsTheSame(c1, c)).Id }); foreach (var c in updates) { await repository.Update(warId, c); } }
//Uppdaterar data i grundtabeller och one to many. Använder consolen i brist på web. internal static void UpdateBasicData(string parameter) //KLAR { var spRep = new SportRepository(); var alls = spRep.GetAll(); var coRep = new CountryRepository(); var allc = coRep.GetAll(); if (parameter == "Contestant") { var mRep = new ContestantRepository(); var all = mRep.GetAll(); foreach (var x in all) { Console.WriteLine("Id " + x.Id + ":\t" + "FirstName: " + x.FirstName + "\t" + "LastName: " + x.LastName + "\t" + "Age " + x.Age + "\t" + "Gender " + x.Gender + "\t" + "CountryId " + x.CountryId + "\t" + "SportId " + x.SportId); } int id = UpdateId(); var change = mRep.FindBy(m => m.Id.Equals(id)); foreach (var x in change) { Console.Write("Enter new FirstName: "); x.FirstName = Console.ReadLine(); Console.Write("Enter new LastName: "); x.LastName = Console.ReadLine(); Console.Write("Enter new Age: "); x.Age = int.Parse(Console.ReadLine()); Console.Write("Enter new Gender (male/female): "); x.Gender = Console.ReadLine(); foreach (var y in allc) { Console.WriteLine(y.Id + " = " + y.CountryName); } Console.Write("Enter new CountryId: "); x.CountryId = int.Parse(Console.ReadLine()); foreach (var y in alls) { Console.WriteLine(y.Id + " = " + y.SportName); } Console.Write("Enter new SportId: "); x.SportId = int.Parse(Console.ReadLine()); mRep.Update(x); mRep.Save(); } } if (parameter == "Contest") { var mRep = new ContestRepository(); var all = mRep.GetAll(); foreach (var x in all) { Console.WriteLine("Id " + x.Id + ":\t" + "ContestName: " + x.ContestName + "\t\t" + "SportId " + x.SportId); } int id = UpdateId(); var change = mRep.FindBy(m => m.Id.Equals(id)); foreach (var x in change) { Console.Write("Enter new ContestName: "); x.ContestName = Console.ReadLine(); foreach (var y in alls) { Console.WriteLine(y.Id + " = " + y.SportName); } Console.Write("Enter new SportId: "); x.SportId = int.Parse(Console.ReadLine()); mRep.Update(x); mRep.Save(); } } if (parameter == "Sport") { foreach (var x in alls) { Console.WriteLine("Id " + x.Id + ":\t" + "SportName: " + x.SportName); } int id = UpdateId(); var change = spRep.FindBy(m => m.Id.Equals(id)); foreach (var x in change) { Console.Write("Enter new SportName: "); x.SportName = Console.ReadLine(); spRep.Update(x); spRep.Save(); } } if (parameter == "Country") { foreach (var x in allc) { Console.WriteLine("Id " + x.Id + ":\t" + "CountryName " + x.CountryName + "\t\t" + "Gold " + x.Gold + "\t" + "Silver " + x.Silver + "\t" + "Bronze " + x.Bronze); } int id = UpdateId(); var change = coRep.FindBy(m => m.Id.Equals(id)); foreach (var x in change) { Console.Write("Enter new CountryName: "); x.CountryName = Console.ReadLine(); Console.Write("Enter new Gold: "); x.Gold = int.Parse(Console.ReadLine()); Console.Write("Enter new Silver: "); x.Silver = int.Parse(Console.ReadLine()); Console.Write("Enter new Bronze: "); x.Bronze = int.Parse(Console.ReadLine()); coRep.Update(x); coRep.Save(); } } if (parameter == "Referee") { var mRep = new RefereeRepository(); var all = mRep.GetAll(); foreach (var x in all) { Console.WriteLine("Id " + x.Id + ":\t" + "Name: " + x.Name + "\t\t" + "CountryId " + x.CountryId); } int id = UpdateId(); var change = mRep.FindBy(m => m.Id.Equals(id)); foreach (var x in change) { Console.Write("Enter new Name: "); x.Name = Console.ReadLine(); foreach (var y in allc) { Console.WriteLine(y.Id + " = " + y.CountryName); } Console.Write("Enter new CountryId: "); x.CountryId = int.Parse(Console.ReadLine()); mRep.Update(x); mRep.Save(); } } }