コード例 #1
0
        //[Disable("ProcessRaces")]
        public static async Task ProcessRaces(TextWriter log)
        {
            try
            {
                List <Course> courses = await _raceRepository.GetRacesAsync(0, 0);

                List <RaceEntity> entities = new List <RaceEntity>();
                foreach (Course course in courses)
                {
                    var hisCompetitors = await _raceRepository.GetConcurrentsByRaceAsync(course.CourseId);

                    var paris = await _competitorRepository.GetBetsByRaceAsync(course.CourseId);

                    foreach (Concurrent competitor in hisCompetitors)
                    {
                        RaceEntity entity = course.ToRaceEntity();
                        entity.PartitionKey = course.CourseId.ToString();

                        entity.Concurrent = competitor.Nom;
                        entity.RowKey     = competitor.ConcurrentId.ToString();
                        entity.SC         = paris.FirstOrDefault(p => p.ConcurrentId == competitor.ConcurrentId).SC;

                        entities.Add(entity);
                    }
                }

                _storage.SetRaces(entities);

                await log.WriteLineAsync("Mise à jour du lot réussie");
            }
            catch (Exception ex)
            {
                await log.WriteLineAsync(ex.Message);
            }
        }
コード例 #2
0
ファイル: Extensions.cs プロジェクト: ajaunasse/WebSport
        public static Race ToBo(this RaceEntity bo, bool withJoin = false)
        {
            if (bo == null)
            {
                return(null);
            }

            Race race = new Race
            {
                Id          = bo.Id,
                Title       = bo.Title,
                Description = bo.Description,
                DateStart   = bo.DateStart,
                DateEnd     = bo.DateEnd,
                Town        = bo.Town,
                Points      = bo.Points.ToList().ToBos(),

                Organisers = withJoin && bo.Contributors != null?bo.Contributors.Where(x => x.IsOrganiser).Select(x => x.ToOrganiserBo()).ToList() : null,
                                 Competitors = withJoin && bo.Contributors != null?bo.Contributors.Where(x => x.IsCompetitor).Select(x => x.ToCompetitorBo()).ToList() : null
            };

            if (bo.Distance == null)
            {
                race.Distance = 0;
            }
            else
            {
                race.Distance = bo.Distance;
            }
            return(race);
        }
コード例 #3
0
ファイル: DbRace.cs プロジェクト: websportENIgrp5/webSport
        public int AddRace(Race race)
        {
            if (race == null)
            {
                return(0);
            }

            int retour = 0;

            // Utilisation d'Entity Framework => On ne nécessite plus de transactions
            using (var context = new WebSportEntities())
            {
                var newRace = new RaceEntity()
                {
                    Title             = race.Title,
                    Description       = race.Description,
                    DateStart         = race.DateStart,
                    Town              = race.Town,
                    Distance          = race.Distance,
                    IdDifficulte      = race.IdDifficulte,
                    IdCategorieCourse = race.IdCategoryRace
                };

                context.RaceEntities.Add(newRace);
                context.SaveChanges();
                retour = newRace.Id;
            }

            return(retour);
        }
コード例 #4
0
 public bool checkpoint(RaceEntity car, int checkpointID)
 {
     Debug.Log("Checkpoint: " + checkpointID);
     if (racers.ContainsKey(car))
     {
         Debug.Log("Contains");
         if ((racers[car][1] + 1) % numCheckpoints == checkpointID)
         {
             Debug.Log("if state");
             racers[car][1] = checkpointID;
             bool lapCompleted = (racers[car][1] % numCheckpoints == 0) ? true : false;
             racers[car][0] += (lapCompleted) ? 1 : 0;
             if (lapCompleted && !raceFinished && isFinished(car))
             {
                 raceFinished    = true;
                 winnerText.text = car.racer_name + " Wins!";
                 winnerText.gameObject.SetActive(true);
                 StartCoroutine(EndRace());
             }
             return(lapCompleted);
         }
         return(false);
     }
     return(false);
 }
コード例 #5
0
    int CompareRaceEntities(RaceEntity a, RaceEntity b)
    {
        CarController acc = a.GetComponent <CarController>();
        CarController bcc = b.GetComponent <CarController>();

        if (acc.getCurrentNodeCount() == bcc.getCurrentNodeCount())
        {
            float distance = Vector3.Distance(acc.gameObject.transform.position, bcc.gameObject.transform.position);
            if (distance > 0)
            {
                return(1);
            }
            else
            {
                return(-1);
            }
        }
        else if (acc.getCurrentNodeCount() > bcc.getCurrentNodeCount())
        {
            return(-1);
        }
        else
        {
            return(1);
        }
    }
コード例 #6
0
        public static Race ToBoId(this RaceEntity bo, bool withJoin = false)
        {
            if (bo == null)
            {
                return(null);
            }

            return(new Race
            {
                Id = bo.Id,
                Title = bo.Title,
                Description = bo.Description,
                DateStart = bo.DateStart,
                Town = bo.Town,
                Distance = bo.Distance,
                HeureStart = bo.HeureStart,
                HeureEnd = bo.HeureEnd,
                Reglement = bo.Reglement,
                IdDifficulte = bo.IdDifficulte,
                IdCategoryRace = bo.IdCategorieCourse,

                Difficulte = bo.Difficulte != null?bo.Difficulte.ToBo() : null,
                                 CategoryRace = bo.CategorieCourse != null?bo.CategorieCourse.ToBo() : null,
                                                    Inscriptions = bo.Inscription != null?bo.Inscription.Where(x => x.IdCourse == bo.Id).Select(x => x.ToInscriptionBo()).ToList() : null,
            });
        }
コード例 #7
0
 public void registerCar(RaceEntity car)
 {
     if (!racers.ContainsKey(car))
     {
         racers[car] = new List <int> {
             0, 0
         };
         raceEntityPositions.Add(car);
     }
 }
コード例 #8
0
 public int getLap(RaceEntity car)
 {
     if (racers.ContainsKey(car))
     {
         return(racers[car][0]);
     }
     else
     {
         return(-1);
     }
 }
コード例 #9
0
 public float getCheckpointPercentage(RaceEntity car)
 {
     if (racers.ContainsKey(car))
     {
         return((racers[car][1] * 100) / numCheckpoints);
     }
     else
     {
         return(-1);
     }
 }
コード例 #10
0
    // Use this for initialization
    void Start()
    {
        currentNodeIndex = 0;
        nodeCount        = 0;
        currentSpeed     = 0f;
        initializePath(path);

        GetComponent <Rigidbody>().centerOfMass = centreOfMass;
        pickup     = GetComponent <ActivatePickup>();
        raceEntity = GetComponent <RaceEntity>();
    }
コード例 #11
0
 public bool isFinished(RaceEntity car)
 {
     if (racers.ContainsKey(car))
     {
         if (racers[car][0] >= numLaps)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     return(false);
 }
コード例 #12
0
ファイル: ScrapeDailyRaces.cs プロジェクト: gmpatel/Scheduler
        public IList <VenueEntity> GetRaces()
        {
            var exceptions = new List <Exception>();
            var venues     = new List <VenueEntity>();

            Console.WriteLine("");

            var chromeService = ChromeDriverService.CreateDefaultService();

            chromeService.HideCommandPromptWindow = true;

            var chromeOptions = new ChromeOptions();

            chromeOptions.AddArguments("-incognito");
            chromeOptions.AddArguments("--disable-popup-blocking");

            using (var driver = new ChromeDriver(chromeService, chromeOptions))
            {
                try
                {
                    driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(0);
                    driver.Navigate().GoToUrl("https://www.skyracing.com.au/tab/form/index.php#");
                    GeneralHelpers.Wait(3000);

                    var headElement = driver.GetElement(By.XPath("//*[@id='headname']"));

                    if (headElement != null)
                    {
                        var meetingRows = driver.GetElements(By.XPath("//*[@id='wrapper']/table[1]/tbody/tr"));

                        if (meetingRows != null && meetingRows.Any())
                        {
                            foreach (var meeting in meetingRows)
                            {
                                var m = GetMeetingData(meeting);

                                if (m != null)
                                {
                                    venues.Add(m);
                                }
                            }
                        }

                        if (venues.Any())
                        {
                            for (int i = 0; i < venues.Count; i++)
                            {
                                driver.Navigate().GoToUrl(venues[i].Meetings.First().FormUrl);
                                GeneralHelpers.Wait(3000);

                                var raceNavigations = driver.GetElements(By.XPath("//*[@id='navlist']/li"));

                                if (raceNavigations.Any())
                                {
                                    var raceCounter = 0;

                                    for (var x = 0; x < raceNavigations.Count; x++)
                                    {
                                        raceNavigations = driver.GetElements(By.XPath("//*[@id='navlist']/li"));

                                        var href = raceNavigations.ElementAt(x).FindElement(By.TagName("a")).GetAttribute("href");

                                        if (!string.IsNullOrEmpty(href))
                                        {
                                            raceCounter++;

                                            raceNavigations.ElementAt(x).FindElement(By.TagName("a")).Click();
                                            GeneralHelpers.Wait(3000);

                                            var race = new RaceEntity
                                            {
                                                Number          = raceCounter,
                                                Name            = driver.GetElement(By.XPath("//*[@id='topleft']/table[1]/tbody/tr/td[1]"))?.Text.Replace("\r\n", "").Replace("\n", "").Trim(),
                                                Time            = driver.GetElement(By.XPath("//*[@id='topleft']/table[1]/tbody/tr/td[2]"))?.Text.Replace("Advertised Start Time:", "").Replace("\r\n", "").Replace("\n", "").Trim(),
                                                Weather         = driver.GetElement(By.XPath("//*[@id='topleft']/table[1]/tbody/tr/td[3]"))?.Text.Replace("Weather:", "").Replace("\r\n", "").Replace("\n", "").Trim(),
                                                Track           = driver.GetElement(By.XPath("//*[@id='topleft']/table[1]/tbody/tr/td[4]"))?.Text.Replace("Track:", "").Replace("\r\n", "").Replace("\n", "").Trim(),
                                                Distance        = driver.GetElement(By.XPath("//*[@id='topleft']/table[2]/tbody/tr/td[1]"))?.Text.Replace("Distance:", "").Replace("\r\n", "").Replace("\n", "").Trim(),
                                                Class           = driver.GetElement(By.XPath("//*[@id='topleft']/table[2]/tbody/tr/td[2]"))?.Text.Replace("Class:", "").Replace("\r\n", "").Replace("\n", "").Trim(),
                                                Prizemoney      = driver.GetElement(By.XPath("//*[@id='topleft']/table[2]/tbody/tr/td[3]"))?.Text.Replace("Prizemoney:", "").Replace("\r\n", "").Replace("\n", "").Trim(),
                                                Runners         = new List <RunnerEntity>(),
                                                DateTimeCreated = dateTime
                                            };

                                            var table   = driver.GetElement(By.XPath("//*[@id='report']/tbody"));
                                            var runners = table.FindElements(By.XPath("//*[@class='alt' or @class='row' or @class='altscratched' or @class='rowscratched']"));

                                            if (runners.Any())
                                            {
                                                foreach (var runner in runners)
                                                {
                                                    var scratched = runner.GetAttribute("class").Contains("scratched");
                                                    var cells     = runner.FindElements(By.TagName("td"));

                                                    if (cells.Any())
                                                    {
                                                        var counter = 0;
                                                        var r       = new RunnerEntity {
                                                            Scratched = scratched, DateTimeCreated = dateTime
                                                        };

                                                        foreach (var cell in cells)
                                                        {
                                                            counter++;

                                                            if (counter == 1)
                                                            {
                                                                r.Number = int.Parse(cell.Text.Split(new char [] { '\n' }).Last().Replace("a", "").Replace("b", "").Replace("c", "").Replace("d", "").Replace("e", "").Replace("f", "").Replace("g", "").Replace("h", "").Trim());
                                                            }
                                                            else if (counter == 2)
                                                            {
                                                                r.LastFiveRuns = cell.Text.Replace("\r\n", "").Replace("\n", "").Trim();
                                                            }
                                                            else if (counter == 3)
                                                            {
                                                                r.Name = cell.Text.Replace("\r\n", "").Replace("\n", "").Trim();
                                                            }
                                                            else if (counter == 4)
                                                            {
                                                                r.Barrel = int.Parse(cell.Text.Replace("\r\n", "").Replace("\n", "").Trim());
                                                            }
                                                            else if (counter == 5)
                                                            {
                                                                r.Tcdw = cell.Text.Replace("\r\n", "").Replace("\n", "").Trim();
                                                            }
                                                            else if (counter == 6)
                                                            {
                                                                r.Trainer = cell.Text.Replace("\r\n", "").Replace("\n", "").Trim();
                                                            }
                                                            else if (counter == 7)
                                                            {
                                                                r.Jockey = cell.Text.Replace("\r\n", "").Replace("\n", "").Trim();
                                                            }
                                                            else if (counter == 8)
                                                            {
                                                                r.Weight = decimal.Parse(cell.Text.Replace("\r\n", "").Replace("\n", "").Trim());
                                                            }
                                                            else if (counter == 9)
                                                            {
                                                                r.Rating = int.Parse(cell.Text.Replace("\r\n", "").Replace("\n", "").Trim());
                                                            }
                                                        }

                                                        race.Runners.Add(r);
                                                    }
                                                }
                                            }

                                            var formRows = driver.GetElements(By.XPath("//*[@id='details']/tbody/tr"));

                                            if (formRows.Any())
                                            {
                                                var rowCounter = 0;

                                                foreach (var formRow in formRows)
                                                {
                                                    var cells = formRow.GetElements(By.TagName("td"));

                                                    if (cells.Any())
                                                    {
                                                        var cellCounter = 0;
                                                        rowCounter++;

                                                        foreach (var cell in cells)
                                                        {
                                                            cellCounter++;

                                                            var text = cell.Text.Replace("\r\n", "").Replace("\n", "").Trim();

                                                            if (!string.IsNullOrEmpty(text))
                                                            {
                                                                var number = int.Parse(text.Split(new char[] { ' ' })[0].Trim());
                                                                var run    = race.Runners.FirstOrDefault(xr => xr.Number == number);

                                                                if (rowCounter <= 4)
                                                                {
                                                                    if (run != null)
                                                                    {
                                                                        if (cellCounter == 1)
                                                                        {
                                                                            run.FormSkyRating         = true;
                                                                            run.FormSkyRatingPosition = rowCounter;
                                                                        }
                                                                        else if (cellCounter == 2)
                                                                        {
                                                                            run.FormBest12Months         = true;
                                                                            run.FormBest12MonthsPosition = rowCounter;
                                                                        }
                                                                        else if (cellCounter == 3)
                                                                        {
                                                                            run.FormRecent         = true;
                                                                            run.FormRecentPosition = rowCounter;
                                                                        }
                                                                        else if (cellCounter == 4)
                                                                        {
                                                                            run.FormDistance         = true;
                                                                            run.FormDistancePosition = rowCounter;
                                                                        }
                                                                    }
                                                                }
                                                                else if (rowCounter > 4)
                                                                {
                                                                    if (run != null)
                                                                    {
                                                                        if (cellCounter == 1)
                                                                        {
                                                                            run.FormClass         = true;
                                                                            run.FormClassPosition = rowCounter - 4;
                                                                        }
                                                                        else if (cellCounter == 2)
                                                                        {
                                                                            run.FormTimeRating         = true;
                                                                            run.FormTimeRatingPosition = rowCounter - 4;
                                                                        }
                                                                        else if (cellCounter == 3)
                                                                        {
                                                                            run.FormInWet         = true;
                                                                            run.FormInWetPosition = rowCounter - 4;
                                                                        }
                                                                        else if (cellCounter == 4)
                                                                        {
                                                                            run.FormBestOverall         = true;
                                                                            run.FormBestOverallPosition = rowCounter - 4;
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }

                                            venues[i].Meetings.First().Races.Add(race);
                                        }
                                    }
                                }

                                if (venues[i].Meetings?.First()?.Races?.Count > 0)
                                {
                                    driver.Navigate().GoToUrl(venues[i].Meetings.First().TipsUrl);
                                    GeneralHelpers.Wait(3000);

                                    var tipsRows = driver.GetElements(By.XPath("//*[@id='report']/tbody/tr"));

                                    if (tipsRows != null && tipsRows.Any())
                                    {
                                        var raceCounter = 0;

                                        foreach (var tip in tipsRows)
                                        {
                                            var cells = tip.FindElements(By.TagName("td"));

                                            if (cells.Any())
                                            {
                                                var cellCounter = 0;
                                                raceCounter++;

                                                foreach (var cell in cells)
                                                {
                                                    cellCounter++;
                                                    var text = cell.Text.Replace("\r\n", "").Replace("\n", "").Trim();

                                                    if (!string.IsNullOrEmpty(text) && cellCounter >= 3 && cellCounter <= 6)
                                                    {
                                                        var race   = venues[i].Meetings.First().Races.FirstOrDefault(xr => xr.Number == raceCounter);
                                                        var number = 0;

                                                        if (race != null && int.TryParse(text.Split(new char[] { ' ' })[0].Replace(".", "").Trim(), out number))
                                                        {
                                                            var run = race.Runners.FirstOrDefault(xr => xr.Number == number);
                                                            if (run != null)
                                                            {
                                                                run.TipSky         = true;
                                                                run.TipSkyPosition = cellCounter - 2;
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }

                                File.WriteAllText(string.Format("{0}.json", fileName), JsonConvert.SerializeObject(venues, Formatting.Indented));
                            }
                        }
                    }
                }
                catch (Exception exception)
                {
                    exceptions.Add(new Exception(string.Format("Failed to scrape Index {0} (id: {1}, exchangeId: {2} (exchange: {3})) from the url {4}", "", "", "", "", ""), exception));
                }
                finally
                {
                    try
                    {
                        driver.Close();
                    }
                    catch (Exception)
                    {
                        // Do ...
                    }

                    try
                    {
                        driver.Dispose();
                    }
                    catch (Exception)
                    {
                        // Do ...
                    }
                }
            }

            if (exceptions.Any())
            {
                throw new ExceptionBunch("There were bunch of exceptions during the scrapping process.", exceptions); {}
            }

            return(venues);
        }
コード例 #13
0
ファイル: ScrapeDailyRaces.cs プロジェクト: gmpatel/Scheduler
        private static RaceEntity GetRacesAndTips(IWebElement tip)
        {
            var cells = tip.FindElements(By.TagName("td"));

            if (cells != null && cells.Any())
            {
                var counter = 0;
                var number  = 0;
                var name    = string.Empty;

                var race = default(RaceEntity);

                foreach (var cell in cells)
                {
                    var text = cell.Text.Trim();

                    if (counter == 0)
                    {
                        if (!string.IsNullOrEmpty(text))
                        {
                            number = int.Parse(text);
                        }
                    }
                    else if (counter == 1)
                    {
                        if (!string.IsNullOrEmpty(text))
                        {
                            name = text;
                        }

                        if (number > 0 && !string.IsNullOrEmpty(name))
                        {
                            race = new RaceEntity
                            {
                                Number  = number,
                                Name    = name,
                                Runners = new List <RunnerEntity>()
                            };
                        }
                    }

                    if (counter >= 2 && counter <= 5 && race != null)
                    {
                        if (!string.IsNullOrEmpty(text))
                        {
                            var parts = text.Split(new char[] { '.' });

                            if (parts.Length == 2)
                            {
                                var tipNumber = int.Parse(parts[0].Trim());
                                var tipName   = parts[1].Trim();

                                race.Runners.Add(new RunnerEntity
                                {
                                    Number = tipNumber,
                                    Name   = tipName,
                                    TipSky = true
                                });
                            }
                        }
                    }

                    counter++;
                }

                return(race);
            }

            return(null);
        }
コード例 #14
0
        public bool UpdateData(IList <VenueEntity> venues)
        {
            if (venues.Any())
            {
                foreach (var venue in venues)
                {
                    VenueEntity v;

                    if (UnitOfWork.VenueRepository.FindBy(x => x.Name.Equals(venue.Name) || x.Name2.Equals(venue.Name) || x.Name3.Equals(venue.Name)).Any())
                    {
                        v = UnitOfWork.VenueRepository.FindBy(x => x.Name.Equals(venue.Name) || x.Name2.Equals(venue.Name) || x.Name3.Equals(venue.Name)).First();

                        v.DateTimeLastModified = (venue.DateTimeCreated.Equals(default(DateTime)) ? dateTime : venue.DateTimeCreated);

                        UnitOfWork.VenueRepository.Update(v);
                        UnitOfWork.Save();
                    }
                    else
                    {
                        v = new VenueEntity
                        {
                            Name            = venue.Name.ToUpper(),
                            Province        = venue.Province,
                            DateTimeCreated = (venue.DateTimeCreated.Equals(default(DateTime)) ? dateTime : venue.DateTimeCreated)
                        };

                        UnitOfWork.VenueRepository.Add(v);
                        UnitOfWork.Save();
                    }

                    if (venue.Meetings.Any())
                    {
                        foreach (var meeting in venue.Meetings)
                        {
                            MeetingEntity m;

                            if (UnitOfWork.MeetingRepository.FindBy(x => x.Date.Equals(meeting.Date) && x.VenueId.Equals(v.Id)).Any())
                            {
                                m = UnitOfWork.MeetingRepository.FindBy(x => x.Date.Equals(meeting.Date) && x.VenueId.Equals(v.Id)).First();

                                m.Date    = meeting.Date;
                                m.FormUrl = meeting.FormUrl;
                                m.TipsUrl = meeting.TipsUrl;
                                m.VenueId = v.Id;
                                m.DateTimeLastModified = (meeting.DateTimeCreated.Equals(default(DateTime)) ? dateTime : meeting.DateTimeCreated);

                                UnitOfWork.MeetingRepository.Update(m);
                                UnitOfWork.Save();
                            }
                            else
                            {
                                m = new MeetingEntity
                                {
                                    Date            = meeting.Date,
                                    FormUrl         = meeting.FormUrl,
                                    TipsUrl         = meeting.TipsUrl,
                                    VenueId         = v.Id,
                                    DateTimeCreated = (meeting.DateTimeCreated.Equals(default(DateTime)) ? dateTime : meeting.DateTimeCreated)
                                };

                                UnitOfWork.MeetingRepository.Add(m);
                                UnitOfWork.Save();
                            }

                            if (meeting.Races.Any())
                            {
                                foreach (var race in meeting.Races)
                                {
                                    RaceEntity r;

                                    if (UnitOfWork.RaceRepository.FindBy(x => x.MeetingId.Equals(m.Id) && x.Number.Equals(race.Number)).Any())
                                    {
                                        r = UnitOfWork.RaceRepository.FindBy(x => x.MeetingId.Equals(m.Id) && x.Number.Equals(race.Number)).First();

                                        r.Name                 = race.Name.ToUpper();
                                        r.Time                 = race.Time;
                                        r.Weather              = race.Weather;
                                        r.Track                = race.Track;
                                        r.Distance             = race.Distance;
                                        r.Class                = race.Class;
                                        r.Prizemoney           = race.Prizemoney;
                                        r.DateTimeLastModified = (race.DateTimeCreated.Equals(default(DateTime)) ? dateTime : race.DateTimeCreated);

                                        UnitOfWork.RaceRepository.Update(r);
                                        UnitOfWork.Save();
                                    }
                                    else
                                    {
                                        r = new RaceEntity
                                        {
                                            MeetingId       = m.Id,
                                            Number          = race.Number,
                                            Name            = race.Name.ToUpper(),
                                            Time            = race.Time,
                                            Weather         = race.Weather,
                                            Track           = race.Track,
                                            Distance        = race.Distance,
                                            Class           = race.Class,
                                            Prizemoney      = race.Prizemoney,
                                            DateTimeCreated = (race.DateTimeCreated.Equals(default(DateTime)) ? dateTime : race.DateTimeCreated),
                                        };

                                        UnitOfWork.RaceRepository.Add(r);
                                        UnitOfWork.Save();
                                    }

                                    if (race.Runners.Any())
                                    {
                                        foreach (var runner in race.Runners)
                                        {
                                            RunnerEntity n;

                                            if (UnitOfWork.RunnerRepository.FindBy(x => x.RaceId.Equals(r.Id) && x.Number.Equals(runner.Number)).Any())
                                            {
                                                n = UnitOfWork.RunnerRepository.FindBy(x => x.RaceId.Equals(r.Id) && x.Number.Equals(runner.Number)).First();

                                                n.Name                     = runner.Name.ToUpper();
                                                n.Rating                   = runner.Rating;
                                                n.LastFiveRuns             = runner.LastFiveRuns;
                                                n.Scratched                = runner.Scratched;
                                                n.Barrel                   = runner.Barrel;
                                                n.Tcdw                     = runner.Tcdw;
                                                n.Trainer                  = runner.Trainer;
                                                n.Jockey                   = runner.Jockey;
                                                n.Weight                   = runner.Weight;
                                                n.ResultPosition           = runner.ResultPosition;
                                                n.FormSkyRating            = runner.FormSkyRating;
                                                n.FormSkyRatingPosition    = runner.FormSkyRatingPosition;
                                                n.FormBest12Months         = runner.FormBest12Months;
                                                n.FormBest12MonthsPosition = runner.FormBest12MonthsPosition;
                                                n.FormRecent               = runner.FormRecent;
                                                n.FormRecentPosition       = runner.FormRecentPosition;
                                                n.FormDistance             = runner.FormDistance;
                                                n.FormDistancePosition     = runner.FormDistancePosition;
                                                n.FormClass                = runner.FormClass;
                                                n.FormClassPosition        = runner.FormClassPosition;
                                                n.FormTimeRating           = runner.FormTimeRating;
                                                n.FormTimeRatingPosition   = runner.FormTimeRatingPosition;
                                                n.FormInWet                = runner.FormInWet;
                                                n.FormInWetPosition        = runner.FormInWetPosition;
                                                n.FormBestOverall          = runner.FormBestOverall;
                                                n.FormBestOverallPosition  = runner.FormBestOverallPosition;
                                                n.TipSky                   = runner.TipSky;
                                                n.TipSkyPosition           = runner.TipSkyPosition;
                                                n.DateTimeLastModified     = (runner.DateTimeCreated.Equals(default(DateTime)) ? dateTime : runner.DateTimeCreated);

                                                UnitOfWork.RunnerRepository.Update(n);
                                                UnitOfWork.Save();
                                            }
                                            else
                                            {
                                                n = new RunnerEntity
                                                {
                                                    RaceId                   = r.Id,
                                                    Number                   = runner.Number,
                                                    Name                     = runner.Name.ToUpper(),
                                                    Rating                   = runner.Rating,
                                                    LastFiveRuns             = runner.LastFiveRuns,
                                                    Scratched                = runner.Scratched,
                                                    Barrel                   = runner.Barrel,
                                                    Tcdw                     = runner.Tcdw,
                                                    Trainer                  = runner.Trainer,
                                                    Jockey                   = runner.Jockey,
                                                    Weight                   = runner.Weight,
                                                    ResultPosition           = runner.ResultPosition,
                                                    FormSkyRating            = runner.FormSkyRating,
                                                    FormSkyRatingPosition    = runner.FormSkyRatingPosition,
                                                    FormBest12Months         = runner.FormBest12Months,
                                                    FormBest12MonthsPosition = runner.FormBest12MonthsPosition,
                                                    FormRecent               = runner.FormRecent,
                                                    FormRecentPosition       = runner.FormRecentPosition,
                                                    FormDistance             = runner.FormDistance,
                                                    FormDistancePosition     = runner.FormDistancePosition,
                                                    FormClass                = runner.FormClass,
                                                    FormClassPosition        = runner.FormClassPosition,
                                                    FormTimeRating           = runner.FormTimeRating,
                                                    FormTimeRatingPosition   = runner.FormTimeRatingPosition,
                                                    FormInWet                = runner.FormInWet,
                                                    FormInWetPosition        = runner.FormInWetPosition,
                                                    FormBestOverall          = runner.FormBestOverall,
                                                    FormBestOverallPosition  = runner.FormBestOverallPosition,
                                                    TipSky                   = runner.TipSky,
                                                    TipSkyPosition           = runner.TipSkyPosition,
                                                    DateTimeCreated          = (runner.DateTimeCreated.Equals(default(DateTime)) ? dateTime : runner.DateTimeCreated)
                                                };

                                                UnitOfWork.RunnerRepository.Add(n);
                                                UnitOfWork.Save();
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(true);
        }
コード例 #15
0
ファイル: DbRace.cs プロジェクト: ajaunasse/WebSport
        public int AddRace(Race race)
        {
            if (race == null)
            {
                return(0);
            }

            int retour = 0;

            // Utilisation d'Entity Framework => On ne nécessite plus de transactions
            using (var context = new WebSportEntities())
            {
                var newRace = new RaceEntity()
                {
                    Title       = race.Title,
                    Description = race.Description,
                    DateStart   = race.DateStart,
                    DateEnd     = race.DateEnd,
                    Town        = race.Town,
                };

                context.RaceEntities.Add(newRace);
                context.SaveChanges();
                retour = newRace.Id;
            }

            // Utilisation de transactions avec Entity Framework
            //using (var contextBis = new WebSportEntities())
            //{
            //    using (var transac = contextBis.Database.Connection.BeginTransaction())
            //    {
            //        try
            //        {
            //             DO QUERY

            //            contextBis.SaveChanges();
            //            transac.Commit();
            //        }
            //        catch (Exception)
            //        {
            //            transac.Rollback();
            //        }
            //    }
            //}

            // Si on utilise ADO.NET en direct, on utiliserait le code ci-dessous
            //try
            //{
            //    var instance = new DbTools();

            //    // Préparation d'une transaction
            //    var transac = instance.CreerTransaction();

            //    // Exécution de la requête d'ajout + on l'inclut dans la transaction
            //    var commandAdd = instance.CreerRequete(RQT_ADD_RACE);
            //    instance.CreerParametre(commandAdd, "@title", race.Title);
            //    instance.CreerParametre(commandAdd, "@description", race.Description);
            //    instance.CreerParametre(commandAdd, "@datestart", race.DateStart);
            //    instance.CreerParametre(commandAdd, "@dateend", race.DateEnd);
            //    instance.CreerParametre(commandAdd, "@ville", race.Town);
            //    commandAdd.Transaction = transac;
            //    commandAdd.ExecuteNonQuery();

            //    // Exécution de la requête de recupération du dernier id ajouté + on l'inclut dans la transaction
            //    var commandSelect = instance.CreerRequete(RQT_GET_LAST_ADDED);
            //    commandSelect.Transaction = transac;

            //    retour = Convert.ToInt32(commandSelect.ExecuteScalar());
            //    if (retour > 0)
            //    {
            //        transac.Commit();
            //    }
            //    else
            //    {
            //        transac.Rollback();
            //    }
            //}
            //catch (Exception)
            //{
            //    retour = 0;
            //}

            return(retour);
        }