コード例 #1
0
        public void CountryRepositoryAddNewItemSaveItem()
        {
            //Arrange
            var unitOfWork = new MainBCUnitOfWork();
            ICountryRepository countryRepository = new CountryRepository(unitOfWork);

            var country = new Country()
            {
                Id = IdentityGenerator.NewSequentialGuid(),
                CountryName = "France",
                CountryISOCode = "fr-FR"
            };

            //Act

            countryRepository.Add(country);
            countryRepository.UnitOfWork.Commit();

            //Assert

            var result = countryRepository.Get(country.Id);

            Assert.IsNotNull(result);
            Assert.IsTrue(result.Id == country.Id);
        }
コード例 #2
0
        public void AddTest()
        {
            Pais item = new Pais()
            {
                Nome = "Pais01", Sigla = "01"
            };
            CountryRepository target = new CountryRepository();

            target.Add(item);

            try
            {
                // use session to try to load the product
                using (ISession session = NHibernateHelper.OpenSession())
                {
                    var fromDb = session.Get <Pais>(item.Id);

                    Assert.IsNotNull(fromDb);
                    Assert.AreNotSame(item, fromDb);
                    Assert.AreEqual(item.Nome, fromDb.Nome);
                    Assert.AreEqual(item.Sigla, fromDb.Sigla);
                }
            }
            finally
            {
                target.Remove(item);
            }
        }
コード例 #3
0
        public void Add_AddsItemToDbSet()
        {
            var newCountry = new Country()
            {
                CountryId = 4,
                IsoCode   = "DD",
                Name      = "TestName"
            };

            var mockSet = new Mock <DbSet <Country> >().SetupData(new List <Country>());

            mockSet.Setup(m => m.Add(It.IsAny <Country>())).Returns(newCountry);

            var mockContext = new Mock <CountryContext>();

            mockContext.Setup(c => c.Set <Country>()).Returns(mockSet.Object);

            var service = new CountryRepository(mockContext.Object);

            // Act
            var item = service.Add(newCountry);

            mockSet.Verify(m => m.Add(newCountry), Times.Once);
            Assert.IsNotNull(item);
            Assert.AreEqual(item.IsoCode, newCountry.IsoCode);
            Assert.AreEqual(item.Name, newCountry.Name);
        }
コード例 #4
0
        public void GetAllTest()
        {
            Pais item = new Pais()
            {
                Nome = "Pais06", Sigla = "06"
            };
            CountryRepository target = new CountryRepository();

            target.Add(item);

            try
            {
                var fromDb = target.GetAll();;
                Assert.IsNotNull(fromDb);

                bool found = false;
                foreach (var p in fromDb)
                {
                    found = p.Id.Equals(item.Id);
                    if (found)
                    {
                        break;
                    }
                }

                Assert.IsTrue(found);
            }
            finally
            {
                target.Remove(item);
            }
        }
コード例 #5
0
        public void UpdateTest()
        {
            Pais item = new Pais()
            {
                Nome = "Pais03", Sigla = "03"
            };
            CountryRepository target = new CountryRepository();

            target.Add(item);

            try
            {
                item.Nome = "Pais04";
                target    = new CountryRepository();
                target.Update(item);

                // use session to try to load the product
                using (ISession session = NHibernateHelper.OpenSession())
                {
                    var fromDb = session.Get <Pais>(item.Id);
                    Assert.AreEqual(item.Nome, fromDb.Nome);
                }
            }
            finally
            {
                target.Remove(item);
            }
        }
コード例 #6
0
 public IActionResult Create(Countries model)
 {
     if (HttpContext.Session.GetString("ID") == null)
     {
         return(RedirectToAction("Login", "Admin"));
     }
     else
     {
         //check validation
         if (ModelState.IsValid)
         {
             //check duplicate ID of Country
             bool check = countryRep.checkID(model.CountryID);
             if (check)
             {
                 countryRep.Add(model);
                 return(RedirectToAction("Index"));
             }
             else
             {
                 ModelState.AddModelError(string.Empty, "This ID already exists.");
                 return(View());
             }
         }
         return(View(model));
     }
 }
コード例 #7
0
        public ActionResult Create([Bind(Include = "Id,Description,InsertedDateTime,ModifiedDateTime")] Country country)
        {
            if (ModelState.IsValid)
            {
                repo.Add(country);
                repo.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(country));
        }
コード例 #8
0
ファイル: CountryService.cs プロジェクト: hugovin/SRS
        public static CountryResponse AddCountry(CountryRequest request)
        {
            var response = new CountryResponse();
            var countryRepository = new CountryRepository();
            try
            {
                var newCountry = new country
                                  {
                                      country_name = request.CountryName,
                                      created_date = DateTime.Now,
                                      modified_date = DateTime.Now,
                                      modified_by = request.ModifiedBy
                                  };
                countryRepository.Add(newCountry);
                countryRepository.SaveChanges();
            }
            catch (InvalidOperationException exc)
            {
                log.Error(exc);
                response.Message = exc.Message;
                response.Acknowledge = AcknowledgeType.FAILURE;
            }
            catch (ArgumentNullException exc)
            {
                log.Error(exc);
                response.Message = exc.Message;
                response.Acknowledge = AcknowledgeType.FAILURE;
            }
            catch (NullReferenceException exc)
            {
                log.Error(exc);
                response.Message = exc.Message;
                response.Acknowledge = AcknowledgeType.FAILURE;
            }
            catch (OptimisticConcurrencyException exc)
            {
                log.Error(exc);
                response.Message = exc.Message;
                response.Acknowledge = AcknowledgeType.FAILURE;
            }
            catch (UpdateException exc)
            {
                log.Error(exc);
                response.Message = exc.Message;
                response.Acknowledge = AcknowledgeType.FAILURE;
            }
            finally
            {
                countryRepository.Dispose();
            }

            return response;
        }
コード例 #9
0
        public void CountryRepositoryAddNewItemSaveItem()
        {
            //Arrange
            var countryRepository = new CountryRepository(fixture.unitOfWork, fixture.countryLogger);

            var country = new Country("France", "fr-FR");

            country.GenerateNewIdentity();

            //Act
            countryRepository.Add(country);
            fixture.unitOfWork.Commit();
        }
コード例 #10
0
        public void CountryRepositoryAddNewItemSaveItem()
        {
            //Arrange
            var unitOfWork = new MainBCUnitOfWork();
            var countryRepository = new CountryRepository(unitOfWork);

            var country = new Country("France", "fr-FR");
            country.GenerateNewIdentity();

            //Act
            countryRepository.Add(country);
            unitOfWork.Commit();
        }
コード例 #11
0
        public async Task AddCountry_AddsToDb()
        {
            // Act
            var lResult = await countryRepository.Add(new Entities.CountryEntity {
                Name = "test"
            });

            // Assert
            Assert.IsTrue(lResult.Id > 0);
            var lCreatedEntity = await countryRepository.GetById(lResult.Id);

            Assert.IsNotNull(lCreatedEntity);
            Assert.AreEqual("test", lCreatedEntity.Name);
            Assert.IsTrue(lCreatedEntity.Id > 0);
        }
コード例 #12
0
        public void ConstructorSetsCorrectEfenkaContext() //done by checking if getbyid works
        {
            EfenkaContextTestFactory.Create();

            _sut = new CountryRepository(EfenkaContextTestFactory.EfenkaContext);

            var country = new Country();

            _sut.Add(country);

            var countryFromDatabase = _sut.GetById(country.Id);

            Assert.That(countryFromDatabase, Is.EqualTo(country));
        }
コード例 #13
0
        public void CountryRepositoryAddNewItemSaveItem()
        {
            //Arrange
            var unitOfWork        = new MainBcUnitOfWork();
            var countryRepository = new CountryRepository(unitOfWork);

            var country = new Country("France", "fr-FR");

            country.GenerateNewIdentity();

            //Act
            countryRepository.Add(country);
            unitOfWork.Commit();
        }
コード例 #14
0
        public async Task <bool> Add(CountryRequest countryReq)
        {
            Guid   Id  = Guid.NewGuid();
            string url = await ImageService.UploadImage(Id, countryReq.PhotoUrl);

            Country country = new Country()
            {
                Id       = Id,
                Name     = countryReq.Name,
                States   = countryReq.States,
                Friends  = countryReq.Friends,
                PhotoUrl = url
            };

            return(await CountryRepository.Add(country));
        }
コード例 #15
0
        public void Test_Add()
        {
            var position    = _fixture.Create <int>();
            var russianName = _fixture.Create <string>();
            var englishName = _fixture.Create <string>();

            var id = _country.Add(englishName, russianName, position);

            var russian = _country.All(TwoLetterISOLanguageName.Russian).First(x => x.Id == id);

            var english = _country.All(TwoLetterISOLanguageName.English).First(x => x.Id == id);

            russian.ShouldBeEquivalentTo(english, options => options.Excluding(x => x.Name));
            russian.Name.ShouldBeEquivalentTo(russianName);
            english.Name.ShouldBeEquivalentTo(englishName);
        }
コード例 #16
0
      public void AddSingleModelCountryTest()
      {
          var context  = new ApplicationDbContext();
          var expected = context.Country.Count() + 1;
          var target   = new CountryRepository(context);
          var country  = new Country()
          {
              Title = Guid.NewGuid().ToString()
          };

          target.Add(country);
          target.Complete();
          var actual = context.Country.Count();

          Assert.AreEqual(expected, actual);
      }
コード例 #17
0
        public void CountryRepositoryRemoveItemDeleteIt()
        {
            //Arrange
            var countryRepository = new CountryRepository(fixture.unitOfWork, fixture.countryLogger);

            var country = new Country("England", "en-EN");

            country.GenerateNewIdentity();

            countryRepository.Add(country);
            countryRepository.UnitOfWork.Commit();

            //Act
            countryRepository.Remove(country);
            fixture.unitOfWork.Commit();
        }
コード例 #18
0
        public void Country_Repository_Create()
        {
            try
            {
                //Arrange
                Country c = new Country()
                {
                    Name = "UK"
                };

                //Act
                var result = objRepo.Add(c);
                databaseContext.SaveChanges();
            }
            catch (Exception ex) { }
        }
コード例 #19
0
        public JsonResult Create(Country country, string userid)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    ICN.Add(country, Session["userid"].ToString());
                }
            }
            catch
            {
                return(Json("error"));
            }

            return(Json("success"));
        }
コード例 #20
0
ファイル: ContextInitializer.cs プロジェクト: Yurets2000/TRPZ
        private void AddCountry(List <Country> countries, int citiesCount)
        {
            int     no      = countries.Count + 1;
            Country country = new Country
            {
                Name   = "Country #" + no,
                Cities = new List <City>()
            };

            for (int i = 0; i < citiesCount; i++)
            {
                AddCity(country, 3);
            }
            countries.Add(country);
            _countryRepository.Add(country);
        }
コード例 #21
0
        public void CountryRepositoryRemoveItemDeleteIt()
        {
            //Arrange
            var unitOfWork        = new MainBcUnitOfWork();
            var countryRepository = new CountryRepository(unitOfWork);

            var country = new Country("England", "en-EN");

            country.GenerateNewIdentity();

            countryRepository.Add(country);
            countryRepository.UnitOfWork.Commit();

            //Act
            countryRepository.Remove(country);
            unitOfWork.Commit();
        }
コード例 #22
0
        public void Country_Repository_Create()
        {
            //Arrange
            Country c = new Country {
                Name = "UK"
            };

            //Act
            var result = objRepo.Add(c);

            databaseContext.SaveChanges();

            var lst = objRepo.GetAll().ToList();

            //Assert

            Assert.AreEqual(4, lst.Count);
            Assert.AreEqual("UK", lst.Last().Name);
        }
コード例 #23
0
        public void RemoveTest()
        {
            Pais item = new Pais()
            {
                Nome = "Pais02", Sigla = "02"
            };
            CountryRepository target = new CountryRepository();

            target.Add(item);

            target = new CountryRepository();
            target.Remove(item);

            using (ISession session = NHibernateHelper.OpenSession())
            {
                var fromDb = session.Get <Pais>(item.Id);
                Assert.IsNull(fromDb);
            }
        }
コード例 #24
0
        public void Country_Repository_Add()
        {
            var oldList = repo.GetAll().ToList();
            var country = new Country()
            {
                Name = "France",
            };
            var result = repo.Add(country);

            context.SaveChanges();

            Assert.IsNotNull(result);
            Assert.AreEqual("France", result.Name);

            var newList = repo.GetAll().ToList();

            Assert.IsNotNull(newList);
            Assert.AreEqual(oldList.Count + 1, newList.Count);
        }
コード例 #25
0
        public void GetByNameTest()
        {
            Pais item = new Pais()
            {
                Nome = "Pais04", Sigla = "04"
            };
            CountryRepository target = new CountryRepository();

            target.Add(item);

            try
            {
                var fromDb = target.GetByName(item.Nome);
                Assert.IsNotNull(fromDb);
                Assert.AreNotSame(item, fromDb);
                Assert.AreEqual(item.Nome, fromDb.Nome);
            }
            finally
            {
                target.Remove(item);
            }
        }
コード例 #26
0
        public void Country_Repository_Create()
        {
            Console.WriteLine("Ejecutando NEW");
            //Arrange
            Country c = new Country()
            {
                Name = "UK"
            };

            //Act
            objRepo.Add(c);
            databaseContext.SaveChanges();

            var lst = objRepo.GetAll().ToList();

            //Assert

            Assert.AreEqual(4, lst.Count);
            Assert.AreEqual("UK", lst.Last().Name);

            objRepo.Delete(c);
            databaseContext.SaveChanges();
        }
コード例 #27
0
 public void AddCountry(country country)
 {
     _countryRepository.Add(country);
 }
コード例 #28
0
        public void CountryRepositoryRemoveItemDeleteIt()
        {
            //Arrange
            var unitOfWork = new MainBCUnitOfWork();
            var countryRepository = new CountryRepository(unitOfWork);

            var country = new Country("England", "en-EN");
            country.GenerateNewIdentity();
            
            countryRepository.Add(country);
            countryRepository.UnitOfWork.Commit();

            //Act
            countryRepository.Remove(country);
            unitOfWork.Commit();
        }
コード例 #29
0
 public bool Add(Country country)
 {
     return(_countryRepository.Add(country));
 }
コード例 #30
0
        public void AddData()
        {
            Console.Clear();
            Console.WriteLine("Введите название страны - ");
            var countryName = CheckNullString(Console.ReadLine());

            Console.WriteLine($"Введите название города находящегося в стране {countryName} - ");
            var cityName = CheckNullString(Console.ReadLine());

            Console.WriteLine($"Введите название улицы находящейся в городе {cityName} - ");
            var streetName = CheckNullString(Console.ReadLine());

            var street = new Street {
                Name = streetName
            };
            var city = new City {
                Name = cityName, Street = street, StreetId = street.Id,
            };
            var country = new Country {
                Name = countryName, City = city, CityId = city.Id
            };

            Console.Clear();
            using (var repository = new StreetRepository())
            {
                try
                {
                    repository.Add(street);
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception.Message);
                    Console.WriteLine("Нажмите Enter чтобы продолжить!");
                    Console.ReadKey();
                    return;
                }
            }

            using (var repository = new CityRepository())
            {
                try
                {
                    repository.Add(city);
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception.Message);
                    Console.WriteLine("Нажмите Enter чтобы продолжить!");
                    Console.ReadKey();
                    return;
                }
            }

            using (var repository = new CountryRepository())
            {
                try
                {
                    repository.Add(country);
                }
                catch (Exception exception)
                {
                    Console.Clear();
                    Console.WriteLine(exception.Message);
                    Console.WriteLine("Нажмите Enter чтобы продолжить!");
                    Console.ReadKey();
                    return;
                }
            }

            Console.Clear();
            Console.WriteLine("Данные добавлены!");
            Console.WriteLine("Нажмите Enter чтобы продолжить!");
            Console.ReadKey();
        }
コード例 #31
0
        public void CountryRepositoryRemoveItemDeleteIt()
        {
            //Arrange
            var unitOfWork = new MainBCUnitOfWork();
            ICountryRepository countryRepository = new CountryRepository(unitOfWork);

            Country country = new Country()
            {
                CountryName = "England",
                CountryISOCode = "en-EN"
            };

            country.Id = IdentityGenerator.NewSequentialGuid();

            countryRepository.Add(country);
            countryRepository.UnitOfWork.Commit();

            //Act

            countryRepository.Remove(country);
            countryRepository.UnitOfWork.Commit();

            var result = countryRepository.Get(country.Id);

            //Assert
            Assert.IsNull(result);
        }
コード例 #32
0
        public async Task <CreateCountryCommandResponse> Handle(CreateCountryCommand request, CancellationToken cancellationToken)
        {
            CreateCountryCommandResponse response = new CreateCountryCommandResponse()
            {
                IsSuccessful = false
            };

            if (request.ImagesData.JPGData == "" || request.ImagesData.JPGName == "" || request.ImagesData.SVGData == "" || request.ImagesData.SVGData == "")
            {
                throw new ArgumentNullException(nameof(request));
            }
            ImageData imageData = new ImageData()
            {
                JPGData = request.ImagesData.JPGData,
                JPGName = request.ImagesData.JPGName,
                SVGData = request.ImagesData.SVGData,
                SVGName = request.ImagesData.SVGName
            };
            List <string> urls = await _Eventblobcontext.PublishThroughBlobStorageAsync(imageData);

            Images _imagesPNG = new Images()
            {
                Name        = request.ImagesData.JPGName,
                ImageType   = (int)ImageType.FlagPNG,
                FilePath    = urls[0],
                FileType    = "png",
                CreatedBy   = "",
                CreatedDate = DateTime.UtcNow,
                UpdatedBy   = "",
                UpdatedDate = DateTime.UtcNow
            };
            Images _imagesSVG = new Images()
            {
                Name        = request.ImagesData.SVGName,
                ImageType   = (int)ImageType.FlagSVG,
                FilePath    = urls[1],
                FileType    = "svg",
                CreatedBy   = "",
                CreatedDate = DateTime.UtcNow,
                UpdatedBy   = "",
                UpdatedDate = DateTime.UtcNow
            };

            _CountryRepository.AddImage(_imagesPNG);
            _CountryRepository.AddImage(_imagesSVG);
            await _CountryRepository.UnitOfWork
            .SaveEntitiesAsync();

            Countries _Country = new Countries();

            using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                int pngImageId = _imagesPNG.ImageId > 0 ? _imagesPNG.ImageId : throw new NullReferenceException(nameof(request));
                int svgImageId = _imagesSVG.ImageId > 0 ? _imagesSVG.ImageId : throw new NullReferenceException(nameof(request));
                //  List<Languages> _languages = _CountryRepository.GetAllLanguages();

                _Country.PngimageId  = pngImageId;
                _Country.SvgimageId  = svgImageId;
                _Country.IsPublished = false;
                _Country.CreatedBy   = "";
                _Country.CreatedDate = DateTime.Now;
                _Country.UpdatedBy   = "";
                _Country.UpdatedDate = DateTime.Now;
                foreach (var langName in request.LanguageNames)
                {
                    var CountryContent = new CountryContents();
                    CountryContent.DisplayName      = langName.CountryName.Trim();
                    CountryContent.DisplayNameShort = langName.ShortName.Trim();
                    CountryContent.LanguageId       = langName.LanguageID;
                    _Country.CountryContents.Add(CountryContent);
                }
                _CountryRepository.Add(_Country);
                await _CountryRepository.UnitOfWork
                .SaveEntitiesAsync();

                await _cacheService.ClearCacheAsync("countriesCacheKey");

                await _cacheService.ClearCacheAsync("imagesCacheKey");

                response.IsSuccessful = true;
                scope.Complete();
            }

            using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                var pngImageEvent = new ImageCommandEvent()
                {
                    EventType     = ServiceBusEventType.Create,
                    Discriminator = Constants.ImagesDiscriminator,
                    ImageId       = _imagesPNG.ImageId,
                    ImageType     = _imagesPNG.ImageType,
                    Name          = _imagesPNG.Name,
                    CountryId     = _imagesPNG.CountryId,
                    Keyword       = _imagesPNG.Keyword ?? string.Empty,
                    Source        = _imagesPNG.Source ?? string.Empty,
                    Description   = _imagesPNG.Description ?? string.Empty,
                    Copyright     = _imagesPNG.Copyright ?? string.Empty,
                    FilePath      = _imagesPNG.FilePath,
                    FileType      = _imagesPNG.FileType,
                    CreatedBy     = _imagesPNG.CreatedBy,
                    CreatedDate   = _imagesPNG.CreatedDate,
                    UpdatedBy     = _imagesPNG.UpdatedBy,
                    UpdatedDate   = _imagesPNG.UpdatedDate,
                    EmpGuid       = _imagesPNG.EmpGuid ?? string.Empty,
                    IsEdited      = false,
                    PartitionKey  = ""
                };
                await _Eventcontext.PublishThroughEventBusAsync(pngImageEvent);

                var svgImageEvent = new ImageCommandEvent()
                {
                    EventType     = ServiceBusEventType.Create,
                    Discriminator = Constants.ImagesDiscriminator,
                    ImageId       = _imagesSVG.ImageId,
                    ImageType     = _imagesSVG.ImageType,
                    Name          = _imagesSVG.Name,
                    CountryId     = _imagesSVG.CountryId,
                    Keyword       = _imagesSVG.Keyword ?? string.Empty,
                    Source        = _imagesSVG.Source ?? string.Empty,
                    Description   = _imagesSVG.Description ?? string.Empty,
                    Copyright     = _imagesSVG.Copyright ?? string.Empty,
                    FilePath      = _imagesSVG.FilePath,
                    FileType      = _imagesSVG.FileType,
                    CreatedBy     = _imagesSVG.CreatedBy,
                    CreatedDate   = _imagesSVG.CreatedDate,
                    UpdatedBy     = _imagesSVG.UpdatedBy,
                    UpdatedDate   = _imagesSVG.UpdatedDate,
                    EmpGuid       = _imagesSVG.EmpGuid ?? string.Empty,
                    IsEdited      = false,
                    PartitionKey  = ""
                };
                await _Eventcontext.PublishThroughEventBusAsync(svgImageEvent);

                foreach (var content in _Country.CountryContents)
                {
                    var eventSourcing = new CountryCommandEvent()
                    {
                        EventType        = ServiceBusEventType.Create,
                        CountryId        = _Country.CountryId,
                        SVGImageId       = _Country.SvgimageId,
                        PNGImageId       = _Country.PngimageId,
                        IsPublished      = _Country.IsPublished,
                        CreatedBy        = _Country.CreatedBy,
                        CreatedDate      = _Country.CreatedDate,
                        UpdatedBy        = _Country.UpdatedBy,
                        UpdatedDate      = _Country.UpdatedDate,
                        CountryContentId = content.CountryContentId,
                        DisplayName      = content.DisplayName,
                        DisplayNameShort = content.DisplayNameShort,
                        LanguageId       = content.LanguageId,
                        Discriminator    = Constants.CountriesDiscriminator,
                        PartitionKey     = ""
                    };
                    await _Eventcontext.PublishThroughEventBusAsync(eventSourcing);
                }
                scope.Complete();
            }
            return(response);
        }
コード例 #33
0
        // Lägger till Basic data samt till one to many tabeller.
        // För övrigt gäller samma kommentarer som till metoden under.
        internal static void AddBasicData(string olympicModel, string contestantFirstName, string contestantLastName, int age,
                                          string gender, string country, string sport, string contestName, string refereeName) //KLAR
        {
            int sportID      = 0;
            int countryID    = 0;
            int contestID    = 0;
            int refereeID    = 0;
            int contestantID = 0;

            var conRep = new ContestantRepository();
            var conId  = conRep.FindBy(m => m.FirstName.Equals(contestantFirstName) && m.LastName.Equals(contestantLastName));

            foreach (var c in conId)
            {
                contestantID = c.Id;
            }
            var cRep = new CountryRepository();
            var cId  = cRep.FindBy(m => m.CountryName.StartsWith(country));

            foreach (var c in cId)
            {
                countryID = c.Id;
            }

            var sRep = new SportRepository();
            var sId  = sRep.FindBy(m => m.SportName.Equals(sport));

            foreach (var c in sId)
            {
                sportID = c.Id;
            }
            var coRep = new ContestRepository();
            var coId  = coRep.FindBy(m => m.ContestName.Equals(contestName));

            foreach (var c in coId)
            {
                contestID = c.Id;
            }
            var reRep = new RefereeRepository();
            var reId  = reRep.FindBy(m => m.Name.Equals(refereeName));

            foreach (var c in reId)
            {
                refereeID = c.Id;
            }
            try
            {
                if (olympicModel == "Country" && countryID == 0)
                {
                    var addCountry = new CountryRepository();
                    addCountry.Add(new Country {
                        CountryName = country
                    });
                    addCountry.Save();
                }
            }
            catch
            {
                Console.WriteLine("{0} already exists in db.", olympicModel);
            }
            try
            {
                if (olympicModel == "Sport" && sportID == 0)
                {
                    var addSport = new SportRepository();
                    addSport.Add(new Sport {
                        SportName = sport
                    });
                    addSport.Save();
                }
            }
            catch
            {
                Console.WriteLine("{0} already exists in db.", olympicModel);
            }
            try
            {
                if (olympicModel == "Contest" && contestID == 0 && sportID != 0)
                {
                    var addContest = new ContestRepository();
                    addContest.Add(new Contest {
                        ContestName = contestName, SportId = sportID
                    });
                    addContest.Save();
                }
                else if (olympicModel == "Contest" && contestID != 0)
                {
                    Console.WriteLine("{0} already exists in db.", olympicModel);
                }
            }
            catch
            {
                Console.WriteLine("{0} is not added yet. You have to register OlympicModel: {1}, first.", olympicModel, sport);
            }
            try
            {
                if (olympicModel == "Contestant" && contestantID == 0 && sportID != 0 && countryID != 0)
                {
                    var addContestant = new ContestantRepository();
                    addContestant.Add(new Contestant {
                        FirstName = contestantFirstName, LastName = contestantLastName, Age = age, CountryId = countryID, Gender = gender, SportId = sportID
                    });
                    addContestant.Save();
                }
                else if (olympicModel == "Contestant" && contestantID != 0)
                {
                    Console.WriteLine("{0} already exists in db.", olympicModel);
                }
            }
            catch
            {
                Console.WriteLine("This sport or country is not added yet. Select OlympicModel: Sport/Country, first.");
            }
            try
            {
                if (olympicModel == "Referee" && refereeID == 0 && countryID != 0)
                {
                    var addReferee = new RefereeRepository();
                    addReferee.Add(new Referee {
                        Name = refereeName, CountryId = countryID
                    });
                    addReferee.Save();
                    Console.WriteLine("Data is now added!");
                }
            }
            catch
            {
                Console.WriteLine("This country is not added yet. Select OlympicModel: Country, first.");
                Console.ReadKey();
            }
            if (olympicModel == "Match")
            {
                Console.WriteLine("This method doesen't work for many to many. Select AddManyToMany(), instead.");
            }
        }
コード例 #34
0
 public void Add(Country country)
 {
     CountryRepository.Add(country);
 }