コード例 #1
0
        public ActionResult ChooseAthletes(List <AnalyseVM> a)
        {
            AthleteDA a1 = DataAccessServiceController.AthleteService.GetAthleteByName(a.First().AthleteName);
            AthleteDA a2 = DataAccessServiceController.AthleteService.GetAthleteByName(a.Last().AthleteName);

            return(RedirectToAction("Compare", new { aID1 = a1.AthleteID, aID2 = a2.AthleteID, eventName = a.First().EventName, timeframe = a.First().TimeFrame }));
        }
コード例 #2
0
        public ActionResult DeletePost(int athleteID)
        {
            try
            {
                List <AthleteDA> athleteList = new List <AthleteDA>();

                AthleteDA athleteToDelete = DataAccessServiceController.AthleteService.GetAthleteByID(athleteID);
                athleteToDelete.IsDeleted = true;

                athleteList.Add(athleteToDelete);

                bool success = DataAccessServiceController.AthleteService.SaveAthletes(athleteList);

                if (success == true)
                {
                    return(RedirectToAction("Success", "Application", new { area = "" }));
                }
                else
                {
                    return(RedirectToAction("Fail", "Application", new { area = "" }));
                }
            }
            catch (Exception e)
            {
                throw (new Exception("Error occured in AthleteController.DeletePost(athleteID) - " + e.Message));
            }
        }
        public void TestAthleteDAtoVM()
        {
            AthleteDA source = new AthleteDA {
                AthleteID = 1, AthleteName = "Niall Martin", DateOfBirth = new DateTime(2006, 06, 10), GroupID = 1, GroupName = "Under 10s", AgeGroup = new GroupDA(), IsDeleted = false, Results = new List <ResultDA>()
            };
            AthleteVM dest = new AthleteVM();

            Assert.IsNull(dest.AthleteName);
            Mapper.Map(source, dest);
            Assert.AreEqual("Niall Martin", dest.AthleteName);
        }
コード例 #4
0
        public bool SaveAthletes(List <AthleteDA> athletes)
        {
            bool success = false;

            try
            {
                foreach (AthleteDA athlete in athletes)
                {
                    AthleteDA existAthlete = new AthleteDA();

                    //check if athlete is valid existing athlete
                    if (athlete.AthleteID > 0)
                    {
                        //get age group object associated with athlete
                        if (athlete.AgeGroup == null)
                        {
                            athlete.AgeGroup = _db.Groups.SingleOrDefault(g => g.GroupID == athlete.GroupID);
                        }
                        //get existing athlete from database
                        existAthlete = _db.Athletes.SingleOrDefault(a => a.AthleteID == athlete.AthleteID);
                        //update existing athlete
                        _db.Entry(existAthlete).CurrentValues.SetValues(athlete);
                        //flag athlete as changed
                        _db.Entry(existAthlete).State = System.Data.Entity.EntityState.Modified;
                    }

                    else if (athlete.AthleteID == 0)
                    {
                        //get age group object associated with athlete
                        if (athlete.AgeGroup == null)
                        {
                            athlete.AgeGroup = _db.Groups.SingleOrDefault(g => g.GroupID == athlete.GroupID);
                        }

                        _db.Athletes.Add(athlete);
                    }
                }
                //single call to database to save all changes
                _db.SaveChanges();
                success = true;
            }

            catch (Exception e)
            {
                throw (new Exception("Error occured in AthleteService.SaveAthletes(athletes) - " + e.Message));
            }

            return(success);
        }
コード例 #5
0
        public AthleteDA GetAthleteByID(int athleteID)
        {
            List <AthleteDA> athleteSource = new List <AthleteDA>();
            AthleteDA        athlete       = new AthleteDA();

            try
            {
                athleteSource = _db.Athletes.Where(a => a.AthleteID == athleteID).ToList();
                athlete       = athleteSource.First();
            }
            catch (Exception e)
            {
                throw (new Exception("Error occured in AthleteService.GetAthleteByID()"));
            }

            return(athlete);
        }
コード例 #6
0
        //GET: Delete
        public ViewResult Delete(int athleteID)
        {
            AthleteVM athlete       = new AthleteVM();
            AthleteDA athleteSource = new AthleteDA();

            try
            {
                athleteSource = DataAccessServiceController.AthleteService.GetAthleteByID(athleteID);

                Mapper.Map(athleteSource, athlete);

                return(View("Delete", athlete));
            }
            catch (Exception e)
            {
                throw (new Exception("Error occured in AthleteController.Delete(athleteID)"));
            }
        }
コード例 #7
0
        public ActionResult Create(ResultVM createdResult)
        {
            try
            {
                ResultDA        resultDA   = new ResultDA();
                List <ResultDA> resultList = new List <ResultDA>();


                List <EventDA>   events   = DataAccessServiceController.EventService.GetEvents();
                EventDA          e        = events.Find(x => x.EventName == createdResult.EventName);
                List <AthleteDA> athletes = DataAccessServiceController.AthleteService.GetAthletes(-1);
                AthleteDA        a        = athletes.Find(x => x.AthleteName == createdResult.AthleteName);

                //send event and athlete ids to created result viewmodel depending on names chosen
                createdResult.EventID   = e.EventID;
                createdResult.AthleteID = a.AthleteID;

                Mapper.Map(createdResult, resultDA);

                resultList.Add(resultDA);
                bool success = DataAccessServiceController.ResultService.SaveResults(resultList);

                if (success == true)
                {
                    return(RedirectToAction("Success", "Application", new { area = "" }));
                }
                else
                {
                    return(RedirectToAction("Fail", "Application", new { area = "" }));
                }
            }
            catch (Exception e)
            {
                throw (new Exception("Error occured in ResultsController.Create(result)"));
            }
        }
コード例 #8
0
        public ViewResult CompareChart(int aID1, int aID2, string eventName, string timeframe)
        {
            try
            {
                List <AnalyseVM> compareList = new List <AnalyseVM>();

                AthleteDA       athlete1 = DataAccessServiceController.AthleteService.GetAthleteByID(aID1);
                EventDA         evnt     = DataAccessServiceController.EventService.GetEventByName(eventName);
                List <ResultDA> results1 = DataAccessServiceController.ResultService.GetResultsForAnalysis(aID1, eventName, timeframe);
                results1 = results1.OrderBy(r => r.DateOfResult).ToList();
                AnalyseVM analysis1 = new AnalyseVM();


                AthleteDA       athlete2 = DataAccessServiceController.AthleteService.GetAthleteByID(aID2);
                EventDA         evnt2    = DataAccessServiceController.EventService.GetEventByName(eventName);
                List <ResultDA> results2 = DataAccessServiceController.ResultService.GetResultsForAnalysis(aID2, eventName, timeframe);
                results2 = results2.OrderBy(r => r.DateOfResult).ToList();
                AnalyseVM analysis2 = new AnalyseVM();

                if (results1.Count > 0 && results2.Count > 0)
                {
                    analysis1.AthleteID       = aID1;
                    analysis1.AthleteName     = athlete1.AthleteName;
                    analysis1.EventName       = evnt.EventName;
                    analysis1.EventType       = evnt.EventType;
                    analysis1.TimeFrame       = timeframe;
                    analysis1.TotalNumResults = results1.Count();


                    List <DateTime> dates1        = new List <DateTime>();
                    List <double>   resultValues1 = new List <double>();
                    //List<string> resultDates = new List<string>();

                    foreach (ResultDA r in results1)
                    {
                        resultValues1.Add(r.Result);
                        dates1.Add(r.DateOfResult);
                    }

                    //AnalyseVM store results as arrays for use in graph
                    analysis1.Results     = resultValues1.ToArray();
                    analysis1.ResultDates = dates1.ToArray();

                    if (analysis1.EventType == "Time")
                    {
                        analysis1.BestResult   = analysis1.Results.Min();
                        analysis1.WorstResult  = analysis1.Results.Max();
                        analysis1.TargetResult = analysis1.BestResult * 0.95;
                    }
                    else if (analysis1.EventType == "Distance")
                    {
                        analysis1.BestResult   = analysis1.Results.Max();
                        analysis1.WorstResult  = analysis1.Results.Min();
                        analysis1.TargetResult = analysis1.BestResult * 1.05;
                    }

                    analysis1.AverageResult = analysis1.Results.Average();

                    analysis2.AthleteID       = aID2;
                    analysis2.AthleteName     = athlete2.AthleteName;
                    analysis2.EventName       = evnt2.EventName;
                    analysis2.EventType       = evnt2.EventType;
                    analysis2.TimeFrame       = timeframe;
                    analysis2.TotalNumResults = results2.Count();


                    List <DateTime> dates2        = new List <DateTime>();
                    List <double>   resultValues2 = new List <double>();

                    foreach (ResultDA r in results2)
                    {
                        resultValues2.Add(r.Result);
                        dates2.Add(r.DateOfResult);
                    }

                    //AnalyseVM store results as arrays for use in graph
                    analysis2.Results     = resultValues2.ToArray();
                    analysis2.ResultDates = dates2.ToArray();

                    if (analysis2.EventType == "Time")
                    {
                        analysis2.BestResult   = analysis2.Results.Min();
                        analysis2.WorstResult  = analysis2.Results.Max();
                        analysis2.TargetResult = analysis2.BestResult * 0.95;
                    }
                    else if (analysis1.EventType == "Distance")
                    {
                        analysis2.BestResult   = analysis2.Results.Max();
                        analysis2.WorstResult  = analysis2.Results.Min();
                        analysis2.TargetResult = analysis2.BestResult * 1.05;
                    }

                    analysis2.AverageResult = analysis2.Results.Average();
                    compareList.Add(analysis1);
                    compareList.Add(analysis2);

                    return(View("CompareChart", compareList));
                }
                else
                {
                    return(View("NoResults"));
                }
            }
            catch (Exception e)
            {
                throw (new Exception("Error occured in AthleteController.Compare(aID1, aID2, eventName, timeframe)"));
            }
        }
コード例 #9
0
        public ViewResult AnalysisChart(int aID, string eventName, string timeframe)
        {
            try
            {
                AthleteDA       athlete = DataAccessServiceController.AthleteService.GetAthleteByID(aID);
                EventDA         evnt    = DataAccessServiceController.EventService.GetEventByName(eventName);
                List <ResultDA> results = DataAccessServiceController.ResultService.GetResultsForAnalysis(aID, eventName, timeframe);
                results = results.OrderBy(r => r.DateOfResult).ToList();
                AnalyseVM analysis = new AnalyseVM();

                if (results.Count > 0)
                {
                    analysis.AthleteID       = aID;
                    analysis.AthleteName     = athlete.AthleteName;
                    analysis.EventName       = evnt.EventName;
                    analysis.EventType       = evnt.EventType;
                    analysis.TimeFrame       = timeframe;
                    analysis.TotalNumResults = results.Count();


                    List <DateTime> dates        = new List <DateTime>();
                    List <double>   resultValues = new List <double>();
                    //List<string> resultDates = new List<string>();

                    foreach (ResultDA r in results)
                    {
                        resultValues.Add(r.Result);
                        dates.Add(r.DateOfResult);
                    }

                    //AnalyseVM store results as arrays for use in graph
                    analysis.Results     = resultValues.ToArray();
                    analysis.ResultDates = dates.ToArray();

                    if (analysis.EventType == "Time")
                    {
                        analysis.BestResult   = analysis.Results.Min();
                        analysis.WorstResult  = analysis.Results.Max();
                        analysis.TargetResult = analysis.BestResult * 0.95;
                    }
                    else if (analysis.EventType == "Distance")
                    {
                        analysis.BestResult   = analysis.Results.Max();
                        analysis.WorstResult  = analysis.Results.Min();
                        analysis.TargetResult = analysis.BestResult * 1.05;
                    }

                    analysis.AverageResult = analysis.Results.Average();

                    return(View("AnalysisChart", analysis));
                }
                else
                {
                    return(View("NoResults"));
                }
            }
            catch (Exception e)
            {
                throw (new Exception("Error occured in AthleteController.AnalyseChart(aID1, aID2, eventName, timeframe)"));
            }
        }
コード例 #10
0
        public ActionResult Create(AthleteVM athlete)
        {
            try
            {
                AthleteDA        athleteDA   = new AthleteDA();
                List <AthleteDA> athleteList = new List <AthleteDA>();

                //set athlete's group depending on athlete's date of birth
                //condition is set by seeing if athlete is less than a certain amount of days old (eg. 4018 days is 11 years ie. 365.25 * 11)
                if ((DateTime.Now - athlete.DateOfBirth).Days < 4018)
                {
                    athlete.GroupID   = 1;
                    athlete.GroupName = "Under 10s";
                }
                else if ((DateTime.Now - athlete.DateOfBirth).Days >= 4018 && (DateTime.Now - athlete.DateOfBirth).Days < 4748)
                {
                    athlete.GroupID   = 2;
                    athlete.GroupName = "Under 12s";
                }
                else if ((DateTime.Now - athlete.DateOfBirth).Days >= 4748 && (DateTime.Now - athlete.DateOfBirth).Days < 5479)
                {
                    athlete.GroupID   = 3;
                    athlete.GroupName = "Under 14s";
                }
                else if ((DateTime.Now - athlete.DateOfBirth).Days >= 5479 && (DateTime.Now - athlete.DateOfBirth).Days < 6209)
                {
                    athlete.GroupID   = 4;
                    athlete.GroupName = "Under 16s";
                }
                else if ((DateTime.Now - athlete.DateOfBirth).Days >= 6209 && (DateTime.Now - athlete.DateOfBirth).Days < 6940)
                {
                    athlete.GroupID   = 5;
                    athlete.GroupName = "Under 18s";
                }
                else if ((DateTime.Now - athlete.DateOfBirth).Days >= 6940 && (DateTime.Now - athlete.DateOfBirth).Days < 8036)
                {
                    athlete.GroupID   = 6;
                    athlete.GroupName = "Under 21s";
                }
                else if ((DateTime.Now - athlete.DateOfBirth).Days >= 8036)
                {
                    athlete.GroupID   = 7;
                    athlete.GroupName = "Senior";
                }

                Mapper.Map(athlete, athleteDA);

                athleteList.Add(athleteDA);
                bool success = DataAccessServiceController.AthleteService.SaveAthletes(athleteList);

                if (success == true)
                {
                    return(RedirectToAction("Success", "Application", new { area = "" }));
                }
                else
                {
                    return(RedirectToAction("Fail", "Application", new { area = "" }));
                }
            }
            catch (Exception e)
            {
                throw (new Exception("Error occured in AthleteController.Create(athlete)"));
            }
        }