public void Add(BusinessObjects.GroupRelation entity)
        {
            //Add GroupRelation
            using (_GroupRelationRepository = new GenericRepository<DAL.DataEntities.GroupRelation>())
            {
                _GroupRelationRepository.Add((DAL.DataEntities.GroupRelation)entity.InnerEntity);
                _GroupRelationRepository.SaveChanges();
            }

            //Add GroupRelations_To_Features
            using (_GroupRelationsToFeaturesRepository = new GenericRepository<DAL.DataEntities.GroupRelation_To_Feature>())
            {

                foreach (int childFeatureID in entity.ChildFeatureIDs)
                {
                    DAL.DataEntities.GroupRelation_To_Feature grToFeature = new DAL.DataEntities.GroupRelation_To_Feature();
                    grToFeature.GroupRelationID = entity.ID;
                    grToFeature.ParentFeatureID = entity.ParentFeatureID;
                    grToFeature.ChildFeatureID = childFeatureID;

                    _GroupRelationsToFeaturesRepository.Add(grToFeature);
                }

                _GroupRelationsToFeaturesRepository.SaveChanges();
            }
        }
        public void Add(BusinessObjects.FeatureSelection entity)
        {
            using (_FeatureSelectionRepository = new GenericRepository<DAL.DataEntities.FeatureSelection>())
            {
                //Add the FeatureSelection
                _FeatureSelectionRepository.Add((DAL.DataEntities.FeatureSelection)entity.InnerEntity);
                _FeatureSelectionRepository.SaveChanges();

                //Add AttributeValues
                using (_AttributeValuesRepository = new GenericRepository<DAL.DataEntities.AttributeValue>())
                {
                    for (int i = entity.AttributeValues.Count - 1; i >= 0; i--)
                    {
                        BLL.BusinessObjects.AttributeValue BLLAttributeValue = entity.AttributeValues[i];
                        BLLAttributeValue.FeatureSelectionID = entity.ID;

                        //Add
                        if (BLLAttributeValue.ToBeDeleted == false && BLLAttributeValue.ID == 0)
                        {
                            _AttributeValuesRepository.Add((DAL.DataEntities.AttributeValue)BLLAttributeValue.InnerEntity);
                        }
                    }
                    _AttributeValuesRepository.SaveChanges();
                }
            }
        }
Example #3
0
        private void DropFileInCategory(object sender, DragEventArgs e)
        {
            ImageService imgService = new ImageService();
            string[] fileList = e.Data.GetData(DataFormats.FileDrop) as string[];
            string fileextension = Path.GetExtension(fileList[0]);
            if (fileextension != ".pdf")
            {
                MessageBox.Show("Not allowed Drag'n'Drop for this file type");
            }
            else
            {
                string filename = Path.GetFileNameWithoutExtension(fileList[0]);
                string pathtofile = Path.GetFullPath(fileList[0]);
               
                string pathtobookimage = imgService.GenerateImage(pathtofile);
                FileInfo fileToAdd = new FileInfo(pathtofile);
                int size = (int)fileToAdd.Length;

                var book = new Book()
                {
                    Name = filename,
                    FileType = fileextension,
                    Path = pathtofile,
                    PathToBookImg = pathtobookimage,
                    Author = "Unknown Author",
                    Size = size
                };
                Debug.WriteLine(book.Name);
                _categoriesRepository = IoCManager.Kernel.Get<IRepository<Category>>();
                var concreteCategory = _categoriesRepository.GetByQery(q => q.Name == "Foreign Literature");
                concreteCategory.FirstOrDefault().Books.Add(book);
                _categoriesRepository.SaveChanges();
                MessageBox.Show("Book was added");
            }
        }
 public void Add(BusinessObjects.CustomRule entity)
 {
     using (_CustomRuleRepository = new GenericRepository<DAL.DataEntities.CustomRule>())
     {
         _CustomRuleRepository.Add((DAL.DataEntities.CustomRule)entity.InnerEntity);
         _CustomRuleRepository.SaveChanges();
     }
 }
 public void Add(BusinessObjects.Model entity)
 {
     using (_ModelRepository = new GenericRepository<DAL.DataEntities.Model>())
     {
         _ModelRepository.Add((DAL.DataEntities.Model)entity.InnerEntity);
         _ModelRepository.SaveChanges();
     }
 }
 public void Add(BusinessObjects.Constraint entity)
 {
     using (_ConstraintRepository = new GenericRepository<DAL.DataEntities.Constraint>())
     {
         _ConstraintRepository.Add((DAL.DataEntities.Constraint)entity.InnerEntity);
         _ConstraintRepository.SaveChanges();
     }
 }
 public void Add(BLL.BusinessObjects.UITemplate entity)
 {
     using (_UITemplateRepository = new GenericRepository<DAL.DataEntities.UITemplate>())
     {
         _UITemplateRepository.Add((DAL.DataEntities.UITemplate)entity.InnerEntity);
         _UITemplateRepository.SaveChanges();
     }
 }
 public void Add(BusinessObjects.Relation entity)
 {
     using (_RelationRepository = new GenericRepository<DAL.DataEntities.Relation>())
     {
         _RelationRepository.Add((DAL.DataEntities.Relation)entity.InnerEntity);
         _RelationRepository.SaveChanges();
     }
 }
 public void Add(BusinessObjects.Feature entity)
 {
     using (_FeatureRepository = new GenericRepository<DAL.DataEntities.Feature>())
     {
         //Add the Feature
         _FeatureRepository.Add((DAL.DataEntities.Feature)entity.InnerEntity);
         _FeatureRepository.SaveChanges();
     }
 }
 public void Add(BusinessObjects.Attribute entity)
 {
     using (_AttributeRepository = new GenericRepository<DAL.DataEntities.Attribute>())
     {
         //Add the Attribute
         _AttributeRepository.Add((DAL.DataEntities.Attribute)entity.InnerEntity);
         _AttributeRepository.SaveChanges();
     }
 }
 public void Delete(int id)
 {
     DAL.DataEntities.Configuration DALConfiguration;
     using (_ConfigurationRepository = new GenericRepository<DAL.DataEntities.Configuration>())
     {
         DALConfiguration = _ConfigurationRepository.SingleOrDefault(m => m.ID == id);
         _ConfigurationRepository.Delete(DALConfiguration);
         _ConfigurationRepository.SaveChanges();
     }
 }
Example #12
0
 public void Delete(int id)
 {
     DAL.DataEntities.Model model;
     using (_ModelRepository = new GenericRepository<DAL.DataEntities.Model>())
     {
         model = _ModelRepository.SingleOrDefault(m => m.ID == id);
         _ModelRepository.Delete(model);
         _ModelRepository.SaveChanges();
     }
 }
 public void Delete(int id)
 {
     DAL.DataEntities.UITemplate template;
     using (_UITemplateRepository = new GenericRepository<DAL.DataEntities.UITemplate>())
     {
         template = _UITemplateRepository.SingleOrDefault(m => m.ID == id);
         _UITemplateRepository.Delete(template);
         _UITemplateRepository.SaveChanges();
     }
 }
Example #14
0
 private static void EnsureMember(IRepository<Member> memberRepository)
 {
     if (!memberRepository.GetAll().Any(m => m.Name == "Sherlock Holmes"))
     {
         memberRepository.Add(new Member
         {
             Name = "Sherlock Holmes"
         });
         memberRepository.SaveChanges();
     }
 }
Example #15
0
 private static void EnsureProduct(Rebate rebate, IRepository<Product> productRepository)
 {
     if (!productRepository.GetAll().Any(p => p.ProductNumber == 11190))
     {
         productRepository.Add(new Product
         {
             ProductNumber = 11190,
             Name = "Procrit",
             Rebate = rebate
         });
         productRepository.SaveChanges();
     }
 }
Example #16
0
 private static Rebate EnsureRebate(IRepository<Rebate> rebateRepository)
 {
     Rebate rebate = rebateRepository.GetAll().FirstOrDefault(r => r.Name == "Procrit Rebate");
     if (rebate == null)
     {
         rebate = rebateRepository.Add(new Rebate
         {
             Name = "Procrit Rebate"
         });
         rebateRepository.SaveChanges();
     }
     return rebate;
 }
Example #17
0
        public void MyTestInitialize()
        {
            var context = GetProfileContext();
            ContextSession.Current = context;
            //CallContext.SetData(ServiceContextManager<ServiceContext>.SESSIONCOTEXTKEY, context);

            _repository = RepositoryContext.GetRepository();
            //清理垃圾数据
            var rubbish = _repository.GetAll<Category>();
            if (rubbish == null || rubbish.Count() <= 0) return;
            foreach (var item in rubbish)
                this._repository.Remove(item);

            _repository.SaveChanges();
        }
Example #18
0
 public static ApplicationSetting AddTo(this ApplicationSetting item, IRepository repository)
 {
     repository.Add(item);
     repository.SaveChanges();
     return item;
 }
Example #19
0
        public void MyTestInitialize()
        {
            ObjectContext edmContext = new DemoEntities();
            _repository = EDMRepositoryContext.GetCurrentContext(edmContext).GetRepository<SysParam>();
            //清理垃圾数据
            var rubbish = _repository.GetFilteredElements(x => x.sysparamName.StartsWith("ParamName"));
            if (rubbish == null || rubbish.Count() <= 0) return;
            foreach (var item in rubbish)
                this._repository.Remove(item);

            _repository.SaveChanges();
        }
Example #20
0
        public void UpdateName(int modelID, string newName)
        {
            using (_ModelRepository = new GenericRepository<DAL.DataEntities.Model>())
            {
                DAL.DataEntities.Model model = _ModelRepository.SingleOrDefault(m => m.ID == modelID);
                model.LastModifiedDate = DateTime.Now;
                model.Name = newName;

                //_ModelRepository.Attach(model);
                _ModelRepository.SaveChanges();
            }
        }
Example #21
0
        internal static void SeedData(IRepository repository)
        {
            Console.WriteLine("Seeding data...");

            // Seed Persons
            var persons = new List<Person>
                              {
                                  new Person {FirstName = "Arthur", LastName = "Smith", Gender = "M"},
                                  new Person {FirstName = "Bert", LastName = "Jones", Gender = "M"},
                                  new Person {FirstName = "Charlie", LastName = "Robertson", Gender = "M"}
                              };

            persons.ForEach(p => repository.Insert(p));

            // Seed Regions
            var regions = new List<Region>
                              {
                                  new Region {Name = "Banff National Park - South", Description = "Banff National Park"},
                                  new Region {Name = "Jasper National Park"},
                                  new Region {Name = "Kootenay National Park"},
                                  new Region {Name = "Banff National Park - North"},
                                  new Region {Name = "Kananaskis Country"}
                              };
            regions.ForEach(r => repository.Insert(r));

            // Seed Locations
            var locations = new List<Location>
                                {
                                    new Location
                                        {
                                            Name = "Bow Valley Parkway",
                                            Description = "Road from Banff to Lake Louise",
                                            Directions = "Turn left off main highway 2km north of Banff",
                                            Region = regions[0]
                                        },
                                    new Location {Name = "Banff Townsite area", Region = regions[0]},
                                    new Location
                                        {
                                            Name = "Bow Lake area",
                                            Description = "20 minutes north of Lake Louise on IceField Parkway",
                                            Region = regions[3]
                                        },
                                    new Location {Name = "Smith Dorrien Highway", Region = regions[4]}
                                };
            locations.ForEach(l => repository.Insert(l));

            // Seed Difficulty Levels
            var difficulties = new List<Difficulty>
                                   {
                                       new Difficulty {DifficultyType = "Easy"},
                                       new Difficulty {DifficultyType = "Moderate"},
                                       new Difficulty {DifficultyType = "Challenging"},
                                       new Difficulty {DifficultyType = "Difficult"}
                                   };
            difficulties.ForEach(d => repository.Insert(d));

            // Seed TrailType Levels
            var trailTypes = new List<TrailType>
                                 {
                                     new TrailType {TrailTypeName = "Land"},
                                     new TrailType {TrailTypeName = "Air"},
                                     new TrailType {TrailTypeName = "Water"}
                                 };
            trailTypes.ForEach(t => repository.Insert(t));

            // Seed TransportType Levels
            var transportTypes = new List<TransportType>
                                     {
                                         new TransportType {TransportTypeName = "Hike"},
                                         new TransportType {TransportTypeName = "Cycle"},
                                         new TransportType {TransportTypeName = "Canoe"},
                                         new TransportType {TransportTypeName = "Ski"},
                                         new TransportType {TransportTypeName = "Snowshoe"},
                                         new TransportType {TransportTypeName = "Aeroplane"}
                                     };
            transportTypes.ForEach(t => repository.Insert(t));

            // Seed Trails
            var trails = new List<Trail>
                             {
                                 new Trail
                                     {
                                         Name = "Johnstone Canyon",
                                         Description = "Johnstone Canyon",
                                         Distance = 4.8M,
                                         ElevationGain = 200,
                                         EstimatedTime = 2,
                                         Location = locations[0],
                                         TrailType = trailTypes[0],
                                         Difficulty = difficulties[0],
                                         ReturnOnEffort = 9.2M,
                                         OverallGrade = 7.2M,
                                         Notes =
                                             "Good Waterfalls scenery. Good in all seasons. Take crampons in winter/spring",
                                         Longitude = -102,
                                         Latitude = 50
                                     },
                                 new Trail
                                     {
                                         Name = "Burstall Pass",
                                         Description = "Burstall Pass",
                                         Distance = 8.53M,
                                         ElevationGain = 390,
                                         EstimatedTime = 4,
                                         Location = locations[1],
                                         TrailType = trailTypes[0],
                                         Difficulty = difficulties[0],
                                         ReturnOnEffort = 8.1M,
                                         OverallGrade = 8.1M,
                                         Notes = "Excellent view from the pass"
                                     },
                                 new Trail
                                     {
                                         Name = "Helen Lake",
                                         Description = "Helen Lake",
                                         Distance = 8M,
                                         ElevationGain = 480,
                                         EstimatedTime = 4.5M,
                                         Location = locations[2],
                                         TrailType = trailTypes[0],
                                         Difficulty = difficulties[3],
                                         ReturnOnEffort = 7.8M,
                                         OverallGrade = 7.8M,
                                         Notes = "Views across to the Dolomite range."
                                     },
                                 new Trail
                                     {
                                         Name = "Chester Lake",
                                         Description = "Chester Lake",
                                         Distance = 8.11M,
                                         ElevationGain = 520,
                                         EstimatedTime = 4.5M,
                                         Location = locations[2],
                                         TrailType = trailTypes[0],
                                         Difficulty = difficulties[1],
                                         ReturnOnEffort = 6.9M,
                                         OverallGrade = 6.9M,
                                         Notes = "Don't stop at Chester Lake - go on to Three Lake Valley"
                                     }
                             };

            trails.ForEach(t => repository.Insert(t));

            // Seed Trips
            var trips = new List<Trip>
                            {
                                new Trip
                                    {
                                        Date = new DateTime(2001, 9, 1),
                                        TransportType = transportTypes[0],
                                        Trail = trails[0],
                                        Weather = "Cloudy",
                                        TimeTaken = 3.3M,
                                        Notes = "Very slippery - cramps needed.",
                                        Persons = new List<Person>
                                        {
                                            persons[0], persons[1],persons[2]
                                        }
                                    },
                                new Trip
                                    {
                                        Date = new DateTime(2004, 7, 31),
                                        TransportType = transportTypes[1],
                                        Trail = trails[0],
                                        Weather = "Sunny",
                                        TimeTaken = 2.3M,
                                        Notes = "First time on this trail."

                                    }
                            };
            trips.ForEach(t => repository.Insert(t));

            repository.SaveChanges();
        }
 public void Delete(int id)
 {
     DAL.DataEntities.Attribute attribute;
     using (_AttributeRepository = new GenericRepository<DAL.DataEntities.Attribute>())
     {
         attribute = _AttributeRepository.SingleOrDefault(m => m.ID == id);
         _AttributeRepository.Delete(attribute);
         _AttributeRepository.SaveChanges();
     }
 }
Example #23
0
 public void Update(BusinessObjects.Model entity)
 {
     using (_ModelRepository = new GenericRepository<DAL.DataEntities.Model>())
     {
         entity.LastModifiedDate = DateTime.Now;
         //
         _ModelRepository.Attach((DAL.DataEntities.Model)entity.InnerEntity);
         _ModelRepository.SaveChanges();
     }
 }
        private static void SeedNews(IRepository<News> repository)
        {
            var newsList = ListOfNews;

            foreach (var news in newsList)
            {
                repository.Add(news);
            }

            repository.SaveChanges();
        }
        private static void ClearDatabase(IRepository<News> repository)
        {
            foreach (var news in repository.All())
            {
                repository.Delete(news.Id);
            }

            repository.SaveChanges();
        }
 public void Update(BusinessObjects.Configuration entity)
 {
     using (_ConfigurationRepository = new GenericRepository<DAL.DataEntities.Configuration>())
     {
         entity.LastModifiedDate = DateTime.Now;
         //
         _ConfigurationRepository.Attach((DAL.DataEntities.Configuration)entity.InnerEntity);
         _ConfigurationRepository.SaveChanges();
     }
 }
        public void UpdateName(int configurationID, string newName)
        {
            using (_ConfigurationRepository = new GenericRepository<DAL.DataEntities.Configuration>())
            {
                DAL.DataEntities.Configuration model = _ConfigurationRepository.SingleOrDefault(m => m.ID == configurationID);
                model.LastModifiedDate = DateTime.Now;
                model.Name = newName;

                _ConfigurationRepository.SaveChanges();
            }
        }
 public void Delete(int id)
 {
     DAL.DataEntities.CustomRule customRule;
     using (_CustomRuleRepository = new GenericRepository<DAL.DataEntities.CustomRule>())
     {
         customRule = _CustomRuleRepository.SingleOrDefault(m => m.ID == id);
         _CustomRuleRepository.Delete(customRule);
         _CustomRuleRepository.SaveChanges();
     }
 }
        public void Delete(int id)
        {
            DAL.DataEntities.Feature feature;
            using (_FeatureRepository = new GenericRepository<DAL.DataEntities.Feature>())
            {
                feature = _FeatureRepository.SingleOrDefault(m => m.ID == id);

                //Cascade delete on all related FeatureSelections
                using (_FeatureSelectionRepository = new GenericRepository<DAL.DataEntities.FeatureSelection>())
                {
                    IEnumerable<DAL.DataEntities.FeatureSelection> featureSelections = _FeatureSelectionRepository.Find(k => k.FeatureID == feature.ID);
                    foreach (DAL.DataEntities.FeatureSelection featureSelection in featureSelections)
                    {
                        _FeatureSelectionRepository.Delete(featureSelection);
                    }

                    _FeatureSelectionRepository.SaveChanges();
                }

                //
                _FeatureRepository.Delete(feature);
                _FeatureRepository.SaveChanges();
            }
        }
 public void Delete(int id)
 {
     DAL.DataEntities.Relation relation;
     using (_RelationRepository = new GenericRepository<DAL.DataEntities.Relation>())
     {
         relation = _RelationRepository.SingleOrDefault(m => m.ID == id);
         _RelationRepository.Delete(relation);
         _RelationRepository.SaveChanges();
     }
 }