public static IQueryable <Departement> GetDepartements(this GeoDbContext dbContext, int?departementID = null)
        {
            var requete = dbContext.Departements.AsQueryable();

            if (departementID.HasValue)
            {
                requete = requete.Where(r => r.ID == departementID);
            }

            return(requete);
        }
        public static IQueryable <Village> GetVillages(this GeoDbContext dbContext, int?villageID = null)
        {
            var requete = dbContext.Villages.AsQueryable();

            if (villageID.HasValue)
            {
                requete = requete.Where(r => r.ID == villageID);
            }

            return(requete);
        }
        public static IQueryable <SousPrefecture> GetSousPrefectures(this GeoDbContext dbContext, int?sousPrefectureID = null)
        {
            var requete = dbContext.SousPrefectures.AsQueryable();

            if (sousPrefectureID.HasValue)
            {
                requete = requete.Where(r => r.ID == sousPrefectureID);
            }

            return(requete);
        }
        public static IQueryable <Region> GetRegions(this GeoDbContext dbContext, int?regionID = null)
        {
            var requete = dbContext.Regions.AsQueryable();

            if (regionID.HasValue)
            {
                requete = requete.Where(r => r.ID == regionID);
            }

            return(requete);
        }
示例#5
0
        public static void Update <TEntity>(this GeoDbContext dbContext, TEntity entity, IUserInfo userInfo) where TEntity : class, IEntite
        {
            if (string.IsNullOrWhiteSpace(entity.DernierModificateur))
            {
                entity.DernierModificateur = userInfo.NomUtilisateur;
            }
            if (!entity.DateDerniereModification.HasValue)
            {
                entity.DateDerniereModification = DateTime.Now;
            }

            dbContext.Set <TEntity>().Update(entity);
        }
示例#6
0
        public static IEnumerable <LogChange> GetChanges(this GeoDbContext dbContext, IUserInfo userInfo)
        {
            foreach (var entry in dbContext.ChangeTracker.Entries())
            {
                if (entry.State != EntityState.Modified)
                {
                    continue;
                }

                var entityType = entry.Entity.GetType();

                foreach (var property in entityType.GetTypeInfo().DeclaredProperties)
                {
                    var originalValue = entry.Property(property.Name).OriginalValue;
                    var currentValue  = entry.Property(property.Name).CurrentValue;

                    if (string.Concat(originalValue) == string.Concat(currentValue))
                    {
                        continue;
                    }

                    // todo: improve the way to retrieve primary key value from entity instance

                    var key = entry.Entity.GetType().GetProperties().First().GetValue(entry.Entity, null).ToString();

                    yield return(new LogChange
                    {
                        NomDeClasse = entityType.Name,
                        NomDePropriete = property.Name,
                        Cle = key,
                        ValeurInitiale = originalValue == null ? string.Empty : originalValue.ToString(),
                        ValeurCourante = currentValue == null ? string.Empty : currentValue.ToString(),
                        NomUtilisateur = userInfo.NomUtilisateur,
                        DateChangement = DateTime.Now
                    });
                }
            }
        }
 public static Village GetVillageByLibelleEtDepartement(this GeoDbContext dbContext, string libelleVillage, string libelleDepartement)
 => dbContext.Villages.FirstOrDefault(item => item.Libelle.ToUpper() == libelleVillage.ToUpper() &&
                                      item.SousPrefecture.Departement.Libelle.ToUpper() == libelleDepartement.ToUpper());
 public static Village GetVillageByLibelle(this GeoDbContext dbContext, string libelle)
 => dbContext.Villages.FirstOrDefault(item => item.Libelle.ToUpper() == libelle.ToUpper());
 public static async Task <Village> GetVillagesync(this GeoDbContext dbContext, Village village)
 => await dbContext.Villages.FirstOrDefaultAsync(item => item.ID == village.ID);
 public static SousPrefecture GetSousPrefectureByLibelle(this GeoDbContext dbContext, string libelle)
 => dbContext.SousPrefectures.FirstOrDefault(item => item.Libelle.ToUpper() == libelle.ToUpper());
 public static async Task <SousPrefecture> GetSousPrefectureAsync(this GeoDbContext dbContext, SousPrefecture sousPrefecture)
 => await dbContext.SousPrefectures.FirstOrDefaultAsync(item => item.ID == sousPrefecture.ID);
 public static Departement GetDepartementByLibelle(this GeoDbContext dbContext, string libelle)
 => dbContext.Departements.FirstOrDefault(item => item.Libelle.ToUpper() == libelle.ToUpper());
 public static async Task <Departement> GetDepartementAsync(this GeoDbContext dbContext, Departement departement)
 => await dbContext.Departements.FirstOrDefaultAsync(item => item.ID == departement.ID);
 public static Region GetRegionByLibelle(this GeoDbContext dbContext, string libelle)
 => dbContext.Regions.FirstOrDefault(item => item.Libelle.ToUpper() == libelle.ToUpper());
 public static async Task <Region> GetRegionAsync(this GeoDbContext dbContext, Region region)
 => await dbContext.Regions.FirstOrDefaultAsync(item => item.ID == region.ID);