示例#1
0
 public PlantVariety CreatePlantVariety(PlantVariety plantVariety)
 {
     using (var database = new Core.Entity.SeedsEntities())
     {
         var entity = plantVariety.ToEntity(database);
         entity.ID = database.PlantVariety.Execute(MergeOption.NoTracking).Any() ? database.PlantVariety.Execute(MergeOption.NoTracking).Max(pv => pv.ID) + 1 : 0;
         database.AddToPlantVariety(entity);
         database.SaveChanges();
         var newEntity = database.PlantVariety.Execute(MergeOption.NoTracking).Single(v => v.ID == entity.ID);
         var result = new PlantVariety(newEntity);
         var plant = Cache.Instance.Plants[newEntity.PlantID];
         result.Plant = plant;
         plant.Varieties[result.ID] = result;
         return result;
     }
 }
示例#2
0
 public PlantVariety EditPlantVariety(PlantVariety plantVariety)
 {
     using (var database = new Core.Entity.SeedsEntities())
     {
         var entity = database.PlantVariety.Single(e => e.ID == plantVariety.ID);
         plantVariety.ApplyChanges(database, entity);
         database.SaveChanges();
         var result = new PlantVariety(entity);
         Cache.Instance.Plants[result.Plant.ID].Varieties[result.ID] = result;
         return result;
     }
 }