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); }
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); } }
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()); }
public List <int> GetResultats() { _context = new WebSportEntities(); List <int> idRaces = _context.ResultatEntities.Select(x => x.CourseId).Distinct().ToList(); return(idRaces); }
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()); }
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); } }
// CREATE // UPDATE // DELETE public Personne GetPersonneByID(int id) { WebSportEntities context = new WebSportEntities(); PersonEntity entity = context.PersonEntities.Single(x => x.Id == id); return(entity.ToBo()); }
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()); } }
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); }
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); } }
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); }
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()); }
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()); }
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); } }
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); } }
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); } }
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); } }
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; }
public MgtResultat() { _context = new WebSportEntities(); }
public InscriptionRepo(WebSportEntities context) : base(context) { }
public PersonRepository(WebSportEntities context) : base(context) { }
public UserTableRepository(WebSportEntities context) : base(context) { }
public ParticipantRepository(WebSportEntities context) : base(context) { }
public RaceRepository(WebSportEntities context) : base(context) { }
public UnitOfWork(WebSportEntities context) { this.context = context; }
public MailRepository(WebSportEntities context) : base(context) { }
public MembershipRepository(WebSportEntities context) : base(context) { }
public PointRepository(WebSportEntities context) : base(context) { }
public ResultatRepository(WebSportEntities context) : base(context) { }