Ejemplo n.º 1
0
        public async Task SetBetAsync(int idCourse, int concurrentId)
        {
            // pari sur lequel on parie
            var pari = await SqlAzureRetry.ExecuteAsync(async() => await Context.Paris
                                                        .Where(p => p.CourseId == idCourse && p.ConcurrentId == concurrentId)
                                                        .FirstOrDefaultAsync());

            if (pari == null)
            {
                return;
            }
            pari.NbParis++; // enregistre le pari

            // les paris de la course
            var paris = await SqlAzureRetry.ExecuteAsync(async() => await Context.Paris.Where(c => c.CourseId == idCourse).ToListAsync());

            // somme de tous les paris de la course
            int total = paris.Sum(c => c.NbParis);

            // recalcul de la cote pour chaque pari de la course
            paris.ForEach(p =>
            {
                p.SC = (double)total / p.NbParis;
                p.SC = Math.Round(10 * p.SC) / 10;
            });
        }
Ejemplo n.º 2
0
        public async Task <Course> GetCourseByIdAsync(int id)
        {
            var course = await SqlAzureRetry.ExecuteAsync(async() => await Context.Courses
                                                          .FirstOrDefaultAsync(c => c.CourseId == id));

            return(course);
        }
Ejemplo n.º 3
0
        public List <Pari> GetBetsByCompetitor(int id)
        {
            var paris = SqlAzureRetry.ExecuteAction(() => Context.Paris
                                                    .Include("Course")
                                                    .Where(p => p.ConcurrentId == id).ToList());

            return(paris);
        }
Ejemplo n.º 4
0
        public Concurrent GetCompetitorById(int id)
        {
            var concurrent = SqlAzureRetry.ExecuteAction(() => Context.Concurrents
                                                         .Include("Entraineur")
                                                         .FirstOrDefault(c => c.ConcurrentId == id));

            return(concurrent);
        }
Ejemplo n.º 5
0
        public async Task <Concurrent> GetCompetitorByIdAsync(int id)
        {
            var concurrent = await SqlAzureRetry.ExecuteAsync(async() => await Context.Concurrents
                                                              .Include("Entraineur")
                                                              .FirstOrDefaultAsync(c => c.ConcurrentId == id));

            return(concurrent);
        }
Ejemplo n.º 6
0
        public async Task <List <Pari> > GetBetsByCompetitorAsync(int id)
        {
            var paris = await SqlAzureRetry.ExecuteAsync(async() => await Context.Paris
                                                         .Include("Course")
                                                         .Where(p => p.ConcurrentId == id).ToListAsync());

            return(paris);
        }
Ejemplo n.º 7
0
        public async Task <List <Pari> > GetBetsByRace(int idCourse)
        {
            var paris = await SqlAzureRetry.ExecuteAsync(async() => await Context.Paris
                                                         .Include("Course")
                                                         .Where(p => p.CourseId == idCourse).ToListAsync());

            return(paris);
        }
Ejemplo n.º 8
0
 public async Task SaveAsync()
 {
     await SqlAzureRetry.ExecuteAsync(async() =>
     {
         await Context.SaveChangesAsync();
     }
                                      );
 }
Ejemplo n.º 9
0
        public List <Pari> GetBetsByRace(int idCourse)
        {
            var paris = SqlAzureRetry.ExecuteAction(() => Context.Paris
                                                    .Include("Course")
                                                    .Where(p => p.CourseId == idCourse).ToList());

            return(paris);
        }
Ejemplo n.º 10
0
        public List <Concurrent> GetCompetitors()
        {
            var concurrents = SqlAzureRetry.ExecuteAction(() => Context.Concurrents
                                                          .Include("Entraineur")
                                                          .OrderBy(c => c.Nom)
                                                          .ToList());

            return(concurrents);
        }
Ejemplo n.º 11
0
        public void Like(int idCourse)
        {
            Course course = SqlAzureRetry.ExecuteAction(() =>
            {
                return(Context.Courses.FirstOrDefault(c => c.CourseId == idCourse));
            });

            course.Likes++;
        }
Ejemplo n.º 12
0
        public async Task <List <Concurrent> > GetCompetitorsAsync()
        {
            var concurrents = await SqlAzureRetry.ExecuteAsync(async() => await Context.Concurrents
                                                               .Include("Entraineur")
                                                               .OrderBy(c => c.Nom)
                                                               .ToListAsync());

            return(concurrents);
        }
Ejemplo n.º 13
0
        public List <Concurrent> GetConcurrentsByRace(int idCourse)
        {
            var courses = SqlAzureRetry.ExecuteAction(() => Context.Courses
                                                      .Where(c => c.CourseId == idCourse)
                                                      .SelectMany(c => c.Concurrents)
                                                      .OrderBy(c => c.Nom)
                                                      .ToList());

            return(courses);
        }
Ejemplo n.º 14
0
        public async Task <List <Concurrent> > GetConcurrentsByRaceAsync(int idCourse)
        {
            var courses = await SqlAzureRetry.ExecuteAsync(async() => await Context.Courses
                                                           .Where(c => c.CourseId == idCourse)
                                                           .SelectMany(c => c.Concurrents)
                                                           .OrderBy(c => c.Nom)
                                                           .ToListAsync());

            return(courses);
        }
Ejemplo n.º 15
0
        public List <Course> GetRacesByCompetitor(int id)
        {
            var paris = SqlAzureRetry.ExecuteAction(() => Context.Paris
                                                    .Include("Course")
                                                    .Where(p => p.ConcurrentId == id).ToList());

            var courses = paris.OrderBy(p => p.Course.Date).Select(p => p.Course).ToList();

            return(courses);
        }
Ejemplo n.º 16
0
        public async Task <List <Course> > GetRacesByCompetitorAsync(int id)
        {
            List <Pari> paris = await SqlAzureRetry.ExecuteAsync(async() => await Context.Paris
                                                                 .Include("Course")
                                                                 .Where(p => p.ConcurrentId == id).ToListAsync());

            var courses = paris.OrderBy(p => p.Course.Date).Select(p => p.Course).ToList();

            return(courses);
        }
Ejemplo n.º 17
0
        public async Task <List <Course> > GetRacesAsync(int recordsPerPage, int currentPage)
        {
            var           req   = CreateRequest(recordsPerPage, currentPage);
            List <Course> races = await SqlAzureRetry.ExecuteAsync(async() => await req.ToListAsync());

            if (races.Count == 0 && currentPage > 0)
            {
                currentPage--;
                req   = CreateRequest(recordsPerPage, currentPage);
                races = await req.ToListAsync();
            }

            return(races);
        }
Ejemplo n.º 18
0
        public List <Course> GetRaces(int recordsPerPage, int currentPage)
        {
            var           req   = CreateRequest(recordsPerPage, currentPage);
            List <Course> races = SqlAzureRetry.ExecuteAction(() => req.ToList());

            if (races.Count == 0 && currentPage > 0)
            {
                currentPage--;
                req   = CreateRequest(recordsPerPage, currentPage);
                races = req.ToList();
            }

            return(races);
        }
Ejemplo n.º 19
0
        public async Task <Ticket> AddTicketAsync(int courseId, int visiteurId, int nbPlaces)
        {
            // enregistre la demande d'achat
            Ticket ticket = new Ticket();

            ticket.AcheteurId = visiteurId;
            ticket.CourseId   = courseId;
            ticket.NbPlaces   = nbPlaces;
            ticket.DateAchat  = DateTime.Now;

            Context.Tickets.Add(ticket);

            // confirme la demande
            Course course = await SqlAzureRetry.ExecuteAsync(async() => await Context.Courses.FirstAsync(c => c.CourseId == courseId));

            if (course == null || course.NbTickets < nbPlaces)
            {
                return(null);
            }

            course.NbTickets -= nbPlaces;

            return(ticket);
        }
Ejemplo n.º 20
0
 public void Save()
 {
     SqlAzureRetry.ExecuteAction(() =>
                                 Context.SaveChanges());
 }
Ejemplo n.º 21
0
        public async Task LikeAsync(int idCourse)
        {
            Course course = await SqlAzureRetry.ExecuteAsync(async() => await Context.Courses.FirstOrDefaultAsync(c => c.CourseId == idCourse));

            course.Likes++;
        }
Ejemplo n.º 22
0
 public async Task <List <Visiteur> > GetVisiteursAsync()
 {
     return(await SqlAzureRetry.ExecuteAsync(async() => await Context.Visiteurs.OrderBy(v => v.Nom).ToListAsync()));
 }
Ejemplo n.º 23
0
 public List <Visiteur> GetVisiteurs()
 {
     return(SqlAzureRetry.ExecuteAction(() => Context.Visiteurs.OrderBy(v => v.Nom).ToList()));
 }
Ejemplo n.º 24
0
        public Course GetRaceById(int id)
        {
            Course course = SqlAzureRetry.ExecuteAction(() => Context.Courses.FirstOrDefault(c => c.CourseId == id));

            return(course);
        }