Example #1
0
 private async void downloadDone(Task <List <Models.Calendrier> > result)
 {
     await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
     {
         List <Models.Calendrier> matchs = result.Result;
         using (BddContext bddContext = new BddContext())
         {
             foreach (Models.Calendrier match in matchs)
             {
                 if (bddContext.Calendriers.Any(item => match.Equipe1 == item.Equipe1 &&
                                                match.Equipe2 == item.Equipe2 &&
                                                match.Categorie == item.Categorie))
                 {
                     Models.Calendrier matchBdd = bddContext.Calendriers.First(item => match.Equipe1 == item.Equipe1 &&
                                                                               match.Equipe2 == item.Equipe2 &&
                                                                               match.Categorie == item.Categorie);
                     matchBdd.Date   = match.Date;
                     matchBdd.Score1 = match.Score1;
                     matchBdd.Score2 = match.Score2;
                     bddContext.Entry(matchBdd).State = Microsoft.Data.Entity.EntityState.Modified;
                 }
                 else
                 {
                     bddContext.Calendriers.Add(match);
                 }
                 matchsObservable.Add(match);
             }
             bddContext.SaveChanges();
         }
     });
 }
        public async Task <Guid> Create(Models.Calendrier cale)
        {
            try
            {
                var context = CreateContext();
                var created = new Data.Calendrier
                {
                    Id           = cale.Id,
                    UniversId    = cale.UniversId,
                    NbMois       = cale.NbMois,
                    NbJoursAnnée = cale.NbJoursAnnée,
                };
                var enr = await context
                          ._Calendrier
                          .AddAsync(created);

                await context.SaveChangesAsync();

                return(enr.Entity.Id);
            }
            catch (DbUpdateException e)
            {
                Console.WriteLine(e.Message);
                return(cale.Id);
            }
        }
        public async Task Delete(Models.Calendrier cale)
        {
            try
            {
                var context  = CreateContext();
                var toDelete = await context._Calendrier.FindAsync(cale.Id);

                if (toDelete != null)
                {
                    context._Calendrier.Remove(toDelete);
                    await context.SaveChangesAsync();
                }
            }
            catch (DbUpdateException e)
            {
                Console.WriteLine(e.Message);
            }
        }
        public async Task Update(Models.Calendrier cale)
        {
            try
            {
                var context  = CreateContext();
                var toUpdate = await context._Calendrier.FindAsync(cale.Id);

                if (toUpdate != null)
                {
                    toUpdate.Id           = cale.Id;
                    toUpdate.UniversId    = cale.UniversId;
                    toUpdate.NbMois       = cale.NbMois;
                    toUpdate.NbJoursAnnée = cale.NbJoursAnnée;

                    await context.SaveChangesAsync();
                }
            }
            catch (DbUpdateException e)
            {
                Console.WriteLine(e.Message);
            }
        }