Example #1
0
        public IEnumerable <Jump> GetAllForAthlete(int idAthlete)
        {
            ICompetitionRepository competitionRepository = new CompetitionRepository(context: _context);
            IEliminationRepository eliminationRepository = new EliminationRepository(_context);
            IContestRepository     contestRepository     = new ContestRepository(_context);

            var         competitions = competitionRepository.GetAllForAthlete(idAthlete);
            List <Jump> result       = new List <Jump>();

            foreach (var competition in competitions)
            {
                var elimination = eliminationRepository.GetEliminationByCompetitionID(competition.IdCompetition);
                var contest     = contestRepository.GetContestByCompetitionID(competition.IdCompetition);

                if (elimination != null)
                {
                    var jumps = GetAllForElimination(elimination.IdElimination).ToList();
                    result = result.Concat(second: jumps).ToList();
                }
                if (contest != null)
                {
                    var jumps = GetAllForContest(contest.IdContest).ToList();
                    result = result.Concat(second: jumps).ToList();
                }
            }

            return(result);
        }
Example #2
0
        public IEnumerable <ContestBO> GetAllContests()
        {
            using (var context = new aspnet_learningEntities())
            {
                var repository = new ContestRepository(context);
                var contests   = repository.GetAllContests();

                return(contests.Select(c => new ContestBO(
                                           c.id,
                                           c.name,
                                           c.food_item,
                                           c.location,
                                           c.date ?? new DateTime(),
                                           c.contest_participations.ToList().Count)));
            }
        }
Example #3
0
 public ContestBO GetContestById(int contestId)
 {
     using (var context = new aspnet_learningEntities())
     {
         var repository = new ContestRepository(context);
         var DALContest = repository.GetContestById(contestId);
         var contest    = DALContest != null ?
                          new ContestBO(
             DALContest.id,
             DALContest.name,
             DALContest.food_item,
             DALContest.location,
             DALContest.date ?? new DateTime(),
             DALContest.contest_participations.Count) :
                          null;
         return(contest);
     }
 }
        internal static void StactisticsForContests()//KLAR
        {
            var cRep = new ContestRepository();

            var stats = cRep.GetAllAsyncStats();

            Console.WriteLine("waiting for results");
            foreach (var entry in stats.Result)
            {
                Console.WriteLine(entry.ContestName);
                Console.WriteLine("\tTotal Participants: " + entry.Sport.Contestants.Count);

                foreach (var x in entry.Sport.Contestants)
                {
                    Console.WriteLine("\t\tContestants: " + x.FullName);
                }
            }
        }
Example #5
0
        public IEnumerable <ContestParticipantBO> GetParticipantsFromContestById(int contestId)
        {
            using (var context = new aspnet_learningEntities())
            {
                var repository      = new ContestRepository(context);
                var rawParticipants = repository.GetParticipantsFromContestById(contestId);

                return(rawParticipants.Select(cp => new ContestParticipantBO(
                                                  cp.score,
                                                  cp.placement,
                                                  new UserBO(
                                                      cp.users.id,
                                                      cp.users.alias,
                                                      cp.users.first_name,
                                                      cp.users.last_name,
                                                      cp.users.registration_date),
                                                  null)));
            }
        }
Example #6
0
        private IEnumerable <JumpChartDTO> GetJumpsForChart(DateTime beginDate, DateTime endDate, int id)
        {
            ICompetitionRepository competitionRepository = new CompetitionRepository(context: _context);
            IEliminationRepository eliminationRepository = new EliminationRepository(_context);
            IContestRepository     contestRepository     = new ContestRepository(_context);

            List <JumpChartDTO> result = new List <JumpChartDTO>();

            var competitions = competitionRepository.GetAllForAthlete(id).Where(x => x.BeginDate >= beginDate && x.EndDate <= endDate).ToList();

            foreach (var competition in competitions)
            {
                var elimination = eliminationRepository.GetEliminationByCompetitionID(competition.IdCompetition);
                var contest     = contestRepository.GetContestByCompetitionID(competition.IdCompetition);

                if (elimination != null)
                {
                    var jump = GetAllForElimination(elimination.IdElimination).Where(x => x.IdJumpStatus1 == 1 || x.IdJumpStatus2 == 1 || x.IdJumpStatus3 == 1).OrderByDescending(x => x.Height).FirstOrDefault();
                    if (jump != null)
                    {
                        result.Add(new JumpChartDTO()
                        {
                            DateOfCompetition = elimination.EliminationDate, MaxHeight = jump.Height
                        });
                    }
                }
                if (contest != null)
                {
                    var jump = GetAllForContest(contest.IdContest).Where(x => x.IdJumpStatus1 == 1 || x.IdJumpStatus2 == 1 || x.IdJumpStatus3 == 1).OrderByDescending(x => x.Height).FirstOrDefault();
                    if (jump != null)
                    {
                        result.Add(new JumpChartDTO()
                        {
                            DateOfCompetition = contest.ContestDate, MaxHeight = jump.Height
                        });
                    }
                }
            }
            return(result);
        }
Example #7
0
        public JumpDTO GetBestResultForAthlete(int idAthlete)
        {
            ICompetitionRepository competitionRepository = new CompetitionRepository(context: _context);
            IEliminationRepository eliminationRepository = new EliminationRepository(_context);
            IContestRepository     contestRepository     = new ContestRepository(_context);

            JumpDTO jump          = new JumpDTO();
            var     jumps         = GetAllForAthlete(idAthlete).OrderByDescending(x => x.Height);
            var     onlyGoodJumps = jumps.Where(x => x.IdJumpStatus1 == 1 || x.IdJumpStatus2 == 1 || x.IdJumpStatus3 == 1).FirstOrDefault();

            if (onlyGoodJumps == null)
            {
                return(null);
            }

            jump.Height = onlyGoodJumps.Height;
            if (onlyGoodJumps.IdContest != null)
            {
                jump.IsContest     = true;
                jump.IsElimination = false;
                var contest     = contestRepository.FindById(onlyGoodJumps.IdContest.Value);
                var competition = competitionRepository.GetAllForAthlete(idAthlete).Where(x => x.IdCompetition == contest.IdCompetition).FirstOrDefault();

                jump.DateOfRecord    = contest.ContestDate;
                jump.CompetitionName = competition.Name;
            }
            else if (onlyGoodJumps.IdElimination != null)
            {
                jump.IsContest     = false;
                jump.IsElimination = true;
                var elimination = eliminationRepository.FindById(onlyGoodJumps.IdElimination.Value);
                var competition = competitionRepository.GetAllForAthlete(idAthlete).Where(x => x.IdCompetition == elimination.IdCompetition).FirstOrDefault();

                jump.DateOfRecord    = elimination.EliminationDate;
                jump.CompetitionName = competition.Name;
            }
            return(jump);
        }
Example #8
0
 public ContestController(ContestRepository repo)
 {
     contest_repository = repo;
 }
Example #9
0
 public ContestController()
 {
     contest_repository = new ContestRepository();
 }
Example #10
0
 public ContestsController()
 {
     this.contestRepo = new ContestRepository();
 }
 public ContestController(MysqlDBContext c, ContestRepository repo, IModelService modelServices)
 {
     this._repo          = repo;
     this._modelServices = modelServices;
 }
        //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();
                }
            }
        }
Example #13
0
        // Lägger till Basic data samt till one to many tabeller.
        // För övrigt gäller samma kommentarer som till metoden under.
        internal static void AddBasicData(string olympicModel, string contestantFirstName, string contestantLastName, int age,
                                          string gender, string country, string sport, string contestName, string refereeName) //KLAR
        {
            int sportID      = 0;
            int countryID    = 0;
            int contestID    = 0;
            int refereeID    = 0;
            int contestantID = 0;

            var conRep = new ContestantRepository();
            var conId  = conRep.FindBy(m => m.FirstName.Equals(contestantFirstName) && m.LastName.Equals(contestantLastName));

            foreach (var c in conId)
            {
                contestantID = c.Id;
            }
            var cRep = new CountryRepository();
            var cId  = cRep.FindBy(m => m.CountryName.StartsWith(country));

            foreach (var c in cId)
            {
                countryID = c.Id;
            }

            var sRep = new SportRepository();
            var sId  = sRep.FindBy(m => m.SportName.Equals(sport));

            foreach (var c in sId)
            {
                sportID = c.Id;
            }
            var coRep = new ContestRepository();
            var coId  = coRep.FindBy(m => m.ContestName.Equals(contestName));

            foreach (var c in coId)
            {
                contestID = c.Id;
            }
            var reRep = new RefereeRepository();
            var reId  = reRep.FindBy(m => m.Name.Equals(refereeName));

            foreach (var c in reId)
            {
                refereeID = c.Id;
            }
            try
            {
                if (olympicModel == "Country" && countryID == 0)
                {
                    var addCountry = new CountryRepository();
                    addCountry.Add(new Country {
                        CountryName = country
                    });
                    addCountry.Save();
                }
            }
            catch
            {
                Console.WriteLine("{0} already exists in db.", olympicModel);
            }
            try
            {
                if (olympicModel == "Sport" && sportID == 0)
                {
                    var addSport = new SportRepository();
                    addSport.Add(new Sport {
                        SportName = sport
                    });
                    addSport.Save();
                }
            }
            catch
            {
                Console.WriteLine("{0} already exists in db.", olympicModel);
            }
            try
            {
                if (olympicModel == "Contest" && contestID == 0 && sportID != 0)
                {
                    var addContest = new ContestRepository();
                    addContest.Add(new Contest {
                        ContestName = contestName, SportId = sportID
                    });
                    addContest.Save();
                }
                else if (olympicModel == "Contest" && contestID != 0)
                {
                    Console.WriteLine("{0} already exists in db.", olympicModel);
                }
            }
            catch
            {
                Console.WriteLine("{0} is not added yet. You have to register OlympicModel: {1}, first.", olympicModel, sport);
            }
            try
            {
                if (olympicModel == "Contestant" && contestantID == 0 && sportID != 0 && countryID != 0)
                {
                    var addContestant = new ContestantRepository();
                    addContestant.Add(new Contestant {
                        FirstName = contestantFirstName, LastName = contestantLastName, Age = age, CountryId = countryID, Gender = gender, SportId = sportID
                    });
                    addContestant.Save();
                }
                else if (olympicModel == "Contestant" && contestantID != 0)
                {
                    Console.WriteLine("{0} already exists in db.", olympicModel);
                }
            }
            catch
            {
                Console.WriteLine("This sport or country is not added yet. Select OlympicModel: Sport/Country, first.");
            }
            try
            {
                if (olympicModel == "Referee" && refereeID == 0 && countryID != 0)
                {
                    var addReferee = new RefereeRepository();
                    addReferee.Add(new Referee {
                        Name = refereeName, CountryId = countryID
                    });
                    addReferee.Save();
                    Console.WriteLine("Data is now added!");
                }
            }
            catch
            {
                Console.WriteLine("This country is not added yet. Select OlympicModel: Country, first.");
                Console.ReadKey();
            }
            if (olympicModel == "Match")
            {
                Console.WriteLine("This method doesen't work for many to many. Select AddManyToMany(), instead.");
            }
        }
Example #14
0
        //Lägger till many to many baserat på tänkt input från Gui, i detta fall manuell input från Program.
        //i verkligt scenario skulle jag valt dropdowns från UI/Web som hämtar querys från db baserat på tidigare dropdown val
        // så att användaren aldrig kan välja alternativ som inte finns/uppfyller db-kriterier.
        // i detta exempel blir minsta felstavning fel och har varit väldigt tröttsamt att testa igenom, då jag inte har alla id:n i huvudet.....
        internal static void AddManyToMany(string contestantFirst, string contestantLast, string contest, string refereeName,
                                           string arena, DateTime dateTime, string country)
        {
            int refereeID    = 0;
            int contestantID = 0;
            int contestID    = 0;
            int sportId      = 0;
            int sportID      = 0;
            var refRep       = new RefereeRepository();
            var coRep        = new ContestantRepository();
            var conRep       = new ContestRepository();
            var mRep         = new MatchRepository();
            var re           = refRep.FindBy(r => r.Name.EndsWith(refereeName)); // lärdom: endswith funkar inte när man länkar hela strängen....
            var refe         = refRep.GetAll();
            var con          = conRep.FindBy(c => c.ContestName.Equals(contest));
            var co           = coRep.FindBy(m => m.FirstName.Equals(contestantFirst) && m.LastName.Equals(contestantLast));

            foreach (var c in co)
            {
                contestantID = c.Id;
                sportId      = c.SportId;
            }
            foreach (var c in con)
            {
                contestID = c.Id;
                sportID   = c.SportId;
            }
            foreach (var c in re)
            {
                if (refereeName == c.Name)
                {
                    refereeID = c.Id;
                }
            }

            var ma = mRep.GetAll();

            foreach (var c in ma)
            {
                try  //kollar att arenan inte dubbelbokas
                {
                    if (arena == c.Arena && c.DateTime == dateTime && c.ContestId != contestID)
                    {
                    }
                }
                catch
                {
                    Console.WriteLine("This arena is already booked for another event at this date. Please correct input.");
                }
            }

            if (contestantID == 0 || contestID == 0 || sportId != sportID || refereeID == 0)
            {
                Console.WriteLine("Some info didn't match.\nContestantid: {0}\nContestid: {1}\nSportidn: {2} and {3} has to be the same.\nRefereeId: {4}", contestantID, contestID, sportId, sportID, refereeID);
                Console.WriteLine("\n\nIf refereeId is 0, ({0}), choose a referee from below list:", refereeName);
                foreach (var x in refe)
                {
                    Console.WriteLine(x.Name);
                }
            }
            else
            {
                try // lägger till en spelare till en match
                {
                    var addContestantToMatch = new MatchRepository();
                    addContestantToMatch.Add(new Match {
                        ContestantId = contestantID, ContestId = contestID, Arena = arena, DateTime = dateTime, RefereeId = refereeID
                    });
                    addContestantToMatch.Save();
                }
                catch
                {
                    Console.WriteLine("{0} {1} is already participating in {2}.", contestantFirst, contestantLast, contest);
                }
            }
        }
Example #15
0
        //Tar bort ett id och dess barn. Förutom i två tabeller, där jag gjorde fel i migreringen och inte lyckades rätta till det.
        // Se kommentarer på rad 81 i OlympicContext.
        internal static void DeleteBasicData(string olympicModel, string contestantFirstName, string contestantLastName, string country, string sport, string contestName, string refereeName)
        {
            var mRep = new MatchRepository();


            if (olympicModel == "Country")
            {
                try                         // Denna nödlösning för jag misslyckades att ändra Restict till Cascade i min sista migration.
                {
                    var cRep = new CountryRepository();
                    var co   = cRep.FindBy(c => c.CountryName == country);
                    cRep.DeleteRange(co);
                    cRep.Save();
                    return;
                }
                catch
                {
                    var match = mRep.FindBy(m => m.Contestant.Country.CountryName.Equals(country));
                    foreach (var x in match)
                    {
                        Console.WriteLine("Match with keyvaluepairs: " + x.ContestId + " - " + x.ContestantId + " has to be deleted first.");
                    }
                    return;
                }
            }
            if (olympicModel == "Sport")
            {
                var cRep = new SportRepository();
                var co   = cRep.FindBy(c => c.SportName == sport);
                cRep.DeleteRange(co);
                cRep.Save();
                return;
            }
            if (olympicModel == "Referee")
            {
                var cRep = new RefereeRepository();
                var co   = cRep.FindBy(c => c.Name == refereeName);
                cRep.DeleteRange(co);
                cRep.Save();
                return;
            }
            if (olympicModel == "Contest")
            {
                var cRep = new ContestRepository();
                var co   = cRep.FindBy(c => c.ContestName == contestName);
                cRep.DeleteRange(co);
                cRep.Save();
                return;
            }
            if (olympicModel == "Contestant")
            {
                try                          // Denna nödlösning för jag misslyckades att ändra Restict till Cascade i min sista migration. (Tror jag i alla fall)
                {
                    var cRep = new ContestantRepository();
                    var co   = cRep.FindBy(c => c.FirstName == contestantFirstName && c.LastName == contestantLastName);
                    cRep.DeleteRange(co);
                    cRep.Save();
                    return;
                }
                catch
                {
                    var match = mRep.FindBy(m => m.Contestant.FirstName.Equals(contestantFirstName) && m.Contestant.LastName.Equals(contestantLastName));
                    foreach (var x in match)
                    {
                        Console.WriteLine("Match with keyvaluepairs: " + x.ContestId + " - " + x.ContestantId + " has to be deleted first.");
                    }
                    return;
                }
            }
            else
            {
                System.Console.WriteLine("{0} does not exist in database.", olympicModel);
            }
        }