public static void AddPostToDataBase(string namePost, decimal distanceSensors, int IdKoords, string nameBasin, string nameGround, string nameLocality, string description) { using (var dbContext = new FastWaterContext()) { GeographicalKoordinate koordinate = GeographyKordinatesService.GetGeographicalKoordinatesEf().FirstOrDefault(y => y.Id_GeographicalKoordinates == IdKoords); Basin basin = dbContext.Basins.FirstOrDefault(y => y.NameBasin.Equals(nameBasin)); Ground ground = dbContext.Grounds.FirstOrDefault(y => y.TypeGround.Equals(nameGround)); Locality locality = dbContext.Localities.FirstOrDefault(y => y.NameLocality.Equals(nameLocality)); int idKoords = dbContext.GeographicalKoordinates.FirstOrDefault(x => x.Id_GeographicalKoordinates == IdKoords).Id_GeographicalKoordinates; int idbasin = dbContext.Basins.FirstOrDefault(y => y.NameBasin.Equals(nameBasin)).Id_Basin; int idGround = dbContext.Grounds.FirstOrDefault(y => y.TypeGround.Equals(nameGround)).Id_Ground; int idlocal = dbContext.Localities.FirstOrDefault(y => y.NameLocality.Equals(nameLocality)).Id_Locality; Post post = new Post() { NamePost = namePost, DistanceBeetwenSensors = distanceSensors, // GeographicalKoordinate = koordinate, Id_GeographicalKoordinates = idKoords, // Basin = basin, Id_Basin = idbasin, // Ground = ground, Id_Ground = idGround, // Locality = locality, Id_Locality = idlocal, description = description }; dbContext.Posts.Add(post); dbContext.SaveChanges(); } }
public static void UpdateGeographyKoord(int idUpdate, int srid, int radiusAction, decimal heighSeaLevel, string description, string typeKoordinates, params double[] latitude_longitude) { var context = new FastWaterContext(); //Объект класса для получения доступа к сущностям DbGeography geographyKoords = null; switch (typeKoordinates) { case "POINT": geographyKoords = CreatePoint(latitude_longitude[0], latitude_longitude[1]); break; case "LINESTRING": geographyKoords = CreateLineString(latitude_longitude[0], latitude_longitude[1], latitude_longitude[2], latitude_longitude[3]); break; case "POLYGON": geographyKoords = CreatePoligon(latitude_longitude); break; // case MessageBox.Show("Не верный тип координат"); } IQueryable <GeographicalKoordinate> query = context.GeographicalKoordinates; var updateObject = query.FirstOrDefault(x => x.Id_GeographicalKoordinates == idUpdate); updateObject.Koordinate = geographyKoords; updateObject.SRID = srid; updateObject.RadiusAction = radiusAction; updateObject.HeighSeaLevel = heighSeaLevel; updateObject.description = description; updateObject.TypeKoordinates = typeKoordinates; context.Entry(updateObject).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); }
public static void RemovePostEf(int idRemove) { var context = new FastWaterContext(); IQueryable <Post> query = context.Posts; var removeObject = query.Where(x => x.Id_Post == idRemove).FirstOrDefault(); if (removeObject != null) { context.Posts.Remove(removeObject); context.SaveChanges(); } }
public static void RemoveGeographicalKoordinatesEf(int idRemove) { var context = new FastWaterContext(); IQueryable <GeographicalKoordinate> query = context.GeographicalKoordinates; var removeObject = query.Where(x => x.Id_GeographicalKoordinates == idRemove).FirstOrDefault(); if (removeObject != null) { context.GeographicalKoordinates.Remove(removeObject); context.SaveChanges(); } }
public static void UpdatePost(int idUpdate, string namePost, decimal distanceSensors, int IdKoords, string nameBasin, string nameGround, string nameLocality, string description) { var context = new FastWaterContext(); //Объект класса для получения доступа к сущностям GeographicalKoordinate koordinate = GeographyKordinatesService.GetGeographicalKoordinatesEf().FirstOrDefault(y => y.Id_GeographicalKoordinates == IdKoords); Basin basin = context.Basins.FirstOrDefault(y => y.NameBasin.Equals(nameBasin)); Ground ground = context.Grounds.FirstOrDefault(y => y.TypeGround.Equals(nameGround)); Locality locality = context.Localities.FirstOrDefault(y => y.NameLocality.Equals(nameLocality)); IQueryable <Post> query = context.Posts; var updateObject = query.FirstOrDefault(x => x.Id_Post == idUpdate); updateObject.NamePost = namePost; updateObject.DistanceBeetwenSensors = distanceSensors; updateObject.GeographicalKoordinate = koordinate; updateObject.Basin = basin; updateObject.Ground = ground; updateObject.Locality = locality; updateObject.description = description; context.Entry(updateObject).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); }
public static void AddWeightParameterSnow(int id_WeightParameterSnow, int id_Post, int countInputs, int countLayer, int numberLayer, int countNeuron, decimal?longitudeDayStart, decimal?longitudeDayFinish, decimal?weightLongitudeDay, decimal?weightSnow, decimal?weightRain, decimal?weightSnowRain, decimal?weightAirHumidity, decimal?weightLevelSnow, decimal?weightChangeLevelSnowBefore, decimal?weightHardnessSnow, decimal?weightTemperatureDay, decimal?weightTemperatureNight, decimal?weightSolarActivity, decimal?weightLevelFreezingGround) { var context = new FastWaterContext(); Post post = context.Posts.FirstOrDefault(y => y.Id_Post == id_Post); WeightParameterSnow weightParameterSnow = new WeightParameterSnow { Id_WeightParameterSnow = id_WeightParameterSnow, Id_Post = id_Post, Post = post, CountInputs = countInputs, CountLayer = countLayer, NumberLayer = numberLayer, CountNeuron = countNeuron, LongitudeDayStart = longitudeDayStart, LongitudeDayFinish = longitudeDayFinish, WeightLongitudeDay = weightLongitudeDay, WeightSnow = weightSnow, WeightRain = weightRain, WeightSnowRain = weightSnowRain, WeightAirHumidity = weightAirHumidity, WeightLevelSnow = weightLevelSnow, WeightChangeLevelSnowBefore = weightChangeLevelSnowBefore, WeightHardnessSnow = weightHardnessSnow, WeightTemperatureDay = weightTemperatureDay, WeightTemperatureNight = weightTemperatureNight, WeightSolarActivity = weightSolarActivity, WeightLevelFreezingGround = weightLevelFreezingGround, }; context.WeightParameterSnows.Add(weightParameterSnow); context.SaveChanges(); }
public static void AddGeographyKoordToDataBase(int srid, int radiusAction, decimal heighSeaLevel, string description, string typeKoordinates, params double[] latitude_longitude) { var context = new FastWaterContext(); //var location = new GeographicalKoordinate() //{ // // Create a point using native DbGeography Factory method // Koordinate = DbGeography.PointFromText( // string.Format("POINT({0} {1})", -121.527200, 45.712113) // , 4326), //}; //context.GeographicalKoordinates.Add(location); DbGeography geographyKoords = null; switch (typeKoordinates) { case "POINT": geographyKoords = CreatePoint(latitude_longitude[0], latitude_longitude[1]); break; case "LINESTRING": geographyKoords = CreateLineString(latitude_longitude[0], latitude_longitude[1], latitude_longitude[2], latitude_longitude[3]); break; case "POLYGON": geographyKoords = CreatePoligon(latitude_longitude); break; // case MessageBox.Show("Не верный тип координат"); } GeographicalKoordinate geographicalKoordinate = new GeographicalKoordinate() { Koordinate = geographyKoords, SRID = srid, RadiusAction = radiusAction, HeighSeaLevel = heighSeaLevel, description = description, TypeKoordinates = typeKoordinates }; context.GeographicalKoordinates.Add(geographicalKoordinate); context.SaveChanges(); }