Example #1
0
        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);
        }
Example #2
0
        public Personne UpdatePersonne(Personne personne)
        {
            try
            {
                PersonEntity     entity  = BoToEntity(personne);
                WebSportEntities context = new WebSportEntities();
                entity           = context.PersonEntities.Single(p => p.Id == personne.Id);
                entity.Firstname = personne.Prenom;
                entity.Lastname  = personne.Nom;
                entity.Mail      = personne.Email;
                entity.Phone     = personne.Phone;
                if (personne.DateNaissance == DateTime.MinValue)
                {
                    entity.BirthDate = null;
                }
                else
                {
                    entity.BirthDate = personne.DateNaissance;
                }
                entity.Password = personne.Password;

                context.SaveChanges();

                return(EntityToBO(entity));
            }
            catch (Exception ex)
            {
                string t = ex.ToString();
                return(null);
            }
        }
Example #3
0
        public List <Resultat> GetResultatsByIdRace(int idrace)
        {
            _context = new WebSportEntities();
            List <ResultatEntity> liste = _context.ResultatEntities.Where(x => x.CourseId == idrace).OrderBy(x => x.Classement).ToList();

            return(liste.Select(x => x.ToBo()).ToList());
        }
Example #4
0
        public List <int> GetResultats()
        {
            _context = new WebSportEntities();
            List <int> idRaces = _context.ResultatEntities.Select(x => x.CourseId).Distinct().ToList();

            return(idRaces);
        }
Example #5
0
        public List <Race> SuscribeRace(Personne user, int idrace)
        {
            WebSportEntities  context = new WebSportEntities();
            ContributorEntity join    = new ContributorEntity();

            join.RaceId   = idrace;
            join.PersonId = user.Id;
            if (user.Role == 1)
            {
                join.IsOrganiser = true;
            }
            else
            {
                join.IsCompetitor = true;
            }

            context.ContributorEntities.Add(join);
            context.SaveChanges();

            List <int>        idRaces = context.ContributorEntities.Where(c => c.PersonId == user.Id).Select(c => c.RaceId).ToList();
            List <RaceEntity> races   = new List <RaceEntity>();

            foreach (int race in idRaces)
            {
                races.Add(context.RaceEntities.Single(r => r.Id == race));
            }

            return(races.ToBos());
        }
Example #6
0
        public bool UpdateRace(Race race)
        {
            // Utilisation d'Entity Framework
            using (var context = new WebSportEntities())
            {
                var initialRace = context.RaceEntities.SingleOrDefault(x => x.Id == race.Id);
                if (initialRace != null)
                {
                    initialRace.Title             = race.Title;
                    initialRace.Description       = race.Description;
                    initialRace.DateStart         = race.DateStart;
                    initialRace.Town              = race.Town;
                    initialRace.Distance          = race.Distance;
                    initialRace.IdDifficulte      = race.IdDifficulte;
                    initialRace.IdCategorieCourse = race.IdCategoryRace;
                }
                else
                {
                    return(false);
                }

                context.SaveChanges();
                return(true);
            }
        }
Example #7
0
        // CREATE

        // UPDATE

        // DELETE
        public Personne GetPersonneByID(int id)
        {
            WebSportEntities context = new WebSportEntities();

            PersonEntity entity = context.PersonEntities.Single(x => x.Id == id);

            return(entity.ToBo());
        }
Example #8
0
        public List <Race> GetRace()
        {
            List <Race> list = new List <Race>();

            // Utilisation d'Entity Framework
            using (var context = new WebSportEntities())
            {
                return(context.RaceEntities.ToList().Select(x => x.ToBo()).ToList());
            }
        }
Example #9
0
        public List <Race> getRacebyUser(int idUser)
        {
            WebSportEntities context    = new WebSportEntities();
            List <Race>      races      = GetAllItems();
            List <int>       idRaceUser =
                context.ContributorEntities.Where(c => c.PersonId == idUser).Select(c => c.RaceId).ToList();

            foreach (int id in idRaceUser)
            {
                Race r = races.Find(c => c.Id == id);
                races.Remove(r);
            }

            return(races);
        }
Example #10
0
        public Point AddPoint(Point point)
        {
            try
            {
                PointEntity      entity  = EntityToBo(point);
                WebSportEntities context = new WebSportEntities();
                context.PointEntities.Add(entity);
                context.SaveChanges();

                return(point);
            }
            catch (Exception e)
            {
                return(null);
            }
        }
Example #11
0
        public List <Race> GetRace()
        {
            List <Race> list = new List <Race>();

            // Utilisation d'Entity Framework
            using (var context = new WebSportEntities())
            {
                return(context.RaceEntities.ToList().Select(x => x.ToBo()).ToList());
            }

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

            //DbDataReader reader = command.ExecuteReader();
            //return this.BuildRaceList(reader);
        }
Example #12
0
        public List <Race> Unsubscribe(int idUser, int idRace)
        {
            WebSportEntities  context = new WebSportEntities();
            ContributorEntity join    = context.ContributorEntities.Single(j => j.PersonId == idUser && j.RaceId == idRace);

            context.ContributorEntities.Remove(join);
            context.SaveChanges();
            List <int>        idRaces = context.ContributorEntities.Where(c => c.PersonId == idUser).Select(c => c.RaceId).ToList();
            List <RaceEntity> races   = new List <RaceEntity>();

            foreach (int race in idRaces)
            {
                races.Add(context.RaceEntities.Single(r => r.Id == race));
            }

            return(races.ToBos());
        }
Example #13
0
        public List <Race> MyRaces(int idUser)
        {
            WebSportEntities context = new WebSportEntities();
            List <int>       idRaces = context.ContributorEntities.Where(c => c.PersonId == idUser).Select(c => c.RaceId).ToList();

            if (idRaces == null)
            {
                return(null);
            }
            List <RaceEntity> races = new List <RaceEntity>();

            foreach (int race in idRaces)
            {
                races.Add(context.RaceEntities.Single(r => r.Id == race));
            }

            return(races.ToBos());
        }
Example #14
0
        public Personne ValidateConnection(Personne pers)
        {
            WebSportEntities context = new WebSportEntities();

            var test = context.PersonEntities.Where(p => p.Mail == pers.Email);

            PersonEntity entity = context.PersonEntities.Single(p => p.Mail == pers.Email);

            if (entity.Password == pers.Password)
            {
                pers = EntityToBO(entity);
                return(pers);
            }
            else
            {
                return(null);
            }
        }
Example #15
0
        public bool RemoveRace(int raceId)
        {
            // Utilisation d'Entity Framework
            using (var context = new WebSportEntities())
            {
                var raceToDelete = context.RaceEntities.SingleOrDefault(x => x.Id == raceId);
                if (raceToDelete != null)
                {
                    context.RaceEntities.Remove(raceToDelete);
                }
                else
                {
                    return(false);
                }

                context.SaveChanges();
                return(true);
            }
        }
Example #16
0
        public Personne Addpersonne(Personne personne)
        {
            try
            {
                PersonEntity     entity  = BoToEntity(personne);
                WebSportEntities context = new WebSportEntities();
                webpages_Roles   role    = context.webpages_Roles.FirstOrDefault(r => r.RoleId == personne.Role);
                entity.webpages_Roles.Add(role);
                role.Personnes.Add(entity);
                context.PersonEntities.Add(entity);
                context.SaveChanges();

                return(EntityToBO(entity));
            }
            catch (Exception ex)
            {
                string t = ex.ToString();
                return(null);
            }
        }
Example #17
0
        public bool Save(List <Resultat> models)
        {
            try
            {
                _context = new WebSportEntities();

                foreach (Resultat resultat in models)
                {
                    _context.ResultatEntities.Add(resultat.ToEntity());
                }

                _context.SaveChanges();

                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Example #18
0
        public PersonEntity BoToEntity(Personne personne)
        {
            WebSportEntities context = new WebSportEntities();

            PersonEntity bo = new PersonEntity();

            bo.Mail      = personne.Email;
            bo.Lastname  = personne.Nom;
            bo.Firstname = personne.Prenom;
            if (personne.DateNaissance == DateTime.MinValue)
            {
                bo.BirthDate = null;
            }
            else
            {
                bo.BirthDate = personne.DateNaissance;
            }

            bo.Password = personne.Password;
            bo.Phone    = personne.Phone;

            return(bo);
        }
 /// <summary>
 /// Constructor by default
 /// </summary>
 /// <param name="context">The context</param>
 public GenericRepository(WebSportEntities context)
 {
     this.context = context;
 }
Example #20
0
 public MgtResultat()
 {
     _context = new WebSportEntities();
 }
Example #21
0
 public InscriptionRepo(WebSportEntities context) : base(context)
 {
 }
Example #22
0
 public PersonRepository(WebSportEntities context) : base(context)
 {
 }
Example #23
0
 public UserTableRepository(WebSportEntities context)
     : base(context)
 {
 }
 public ParticipantRepository(WebSportEntities context)
     : base(context)
 {
 }
Example #25
0
 public RaceRepository(WebSportEntities context)
     : base(context)
 {
 }
Example #26
0
 public UnitOfWork(WebSportEntities context)
 {
     this.context = context;
 }
 public MailRepository(WebSportEntities context)
     : base(context)
 {
 }
 public MembershipRepository(WebSportEntities context)
     : base(context)
 {
 }
Example #29
0
 public PointRepository(WebSportEntities context)
     : base(context)
 {
 }
Example #30
0
 public ResultatRepository(WebSportEntities context)
     : base(context)
 {
 }