Exemplo n.º 1
0
        public PostalAddressListViewModel GetPostalAddressList(Guid customerid)
        {
            if (customerid != Guid.Empty)
            {
                using (var context = new ApplicationDbContext())
                {
                    var postalAddresses = context.PostalAddresses.AsNoTracking()
                                          .Where(x => x.CustomerID == customerid)
                                          .OrderBy(x => x.PostalAddressID);

                    if (postalAddresses != null)
                    {
                        var postalAddressListVm = new PostalAddressListViewModel();
                        foreach (var address in postalAddresses)
                        {
                            var postalAddressVm = new PostalAddressViewModel()
                            {
                                CustomerID      = address.CustomerID.ToString("D"),
                                PostalAddressID = address.PostalAddressID,
                                StreetAddress1  = address.StreetAddress1,
                                StreetAddress2  = address.StreetAddress2,
                                City            = address.City
                            };
                            var regionsRepo = new RegionsRepository();
                            postalAddressVm.RegionNameEnglish = regionsRepo.GetRegionNameEnglish(address.RegionCode);
                            var countryRepo = new CountriesRepository();
                            postalAddressVm.CountryNameEnglish = countryRepo.GetCountryNameEnglish(address.Iso3);
                            postalAddressListVm.PostalAddresses.Add(postalAddressVm);
                        }
                        return(postalAddressListVm);
                    }
                }
            }
            return(null);
        }
Exemplo n.º 2
0
        public void BindDDLs(PlaceView placeView, ObjectContext db)
        {
            //countries ddl
            ICountriesRepository countriesRepository = new CountriesRepository(db);

            placeView.Countries = new SelectList(countriesRepository.GetValid().OrderBy("Name ASC").ToList(), "CountryPK", "Name");

            //counties ddl
            if (placeView.CountryFK != null)
            {
                ICountiesRepository countiesRepository = new CountiesRepository(db);
                placeView.Counties = new SelectList(countiesRepository.GetCountiesByCountry(Convert.ToInt32(placeView.CountryFK)).OrderBy("Name ASC"), "CountyPK", "Name");
            }
            else
            {
                placeView.Counties = new SelectList(new List <County>(), "CountyPK", "Name");
            }

            //postal offices ddl
            if (placeView.CountyFK != null)
            {
                IPostalOfficesRepository postalOfficesRepository = new PostalOfficesRepository(db);
                var postalOffices = postalOfficesRepository.GetValidByCounty(Convert.ToInt32(placeView.CountyFK)).OrderBy(c => c.Name);

                placeView.PostalOffices = new SelectList(postalOffices.Select(c => new { value = c.PostalOfficePK, text = c.Name + " (" + SqlFunctions.StringConvert((double)c.Number).Trim() + ")" }), "value", "text");
            }
            else
            {
                placeView.PostalOffices = new SelectList(new List <PostalOffice>(), "PostalOfficePK", "Name");
            }
        }
Exemplo n.º 3
0
        public PostalAddressViewModel GetPostalAddress(Guid customerid, int postaladdressid)
        {
            if (customerid != Guid.Empty)
            {
                using (var context = new ApplicationDbContext())
                {
                    var postalAddress = context.PostalAddresses.AsNoTracking()
                                        .Where(x => x.CustomerID == customerid && x.PostalAddressID == postaladdressid)
                                        .SingleOrDefault();

                    if (postalAddress != null)
                    {
                        var postalAddressVm = new PostalAddressViewModel()
                        {
                            CustomerID     = postalAddress.CustomerID.ToString("D"),
                            StreetAddress1 = postalAddress.StreetAddress1?.Trim(),
                            StreetAddress2 = postalAddress.StreetAddress2?.Trim(),
                            City           = postalAddress.City?.Trim()
                        };
                        var countriesRepo = new CountriesRepository();
                        postalAddressVm.CountryNameEnglish = countriesRepo.GetCountryNameEnglish(postalAddress.Iso3);
                        var regionsRepo = new RegionsRepository();
                        postalAddressVm.RegionNameEnglish = regionsRepo.GetRegionNameEnglish(postalAddress.RegionCode);

                        return(postalAddressVm);
                    }
                }
            }
            return(null);
        }
Exemplo n.º 4
0
        public CustomerEditViewModel GetCustomer(Guid customerid)
        {
            if (customerid != Guid.Empty)
            {
                using (var context = new ApplicationDbContext())
                {
                    var customer = context.Customers.AsNoTracking()
                                   .Where(x => x.CustomerID == customerid)
                                   .SingleOrDefault();
                    if (customer != null)
                    {
                        var customerEditVm = new CustomerEditViewModel()
                        {
                            CustomerID          = customer.CustomerID.ToString("D"),
                            CustomerName        = customer.CustomerName.Trim(),
                            SelectedCountryIso3 = customer.CountryIso3,
                            SelectedRegionCode  = customer.RegionCode
                        };
                        var countriesRepo = new CountriesRepository();
                        customerEditVm.Countries = countriesRepo.GetCountries();
                        var regionsRepo = new RegionsRepository();
                        customerEditVm.Regions = regionsRepo.GetRegions(customer.CountryIso3);

                        return(customerEditVm);
                    }
                }
            }
            return(null);
        }
Exemplo n.º 5
0
        public PostalAddressEditViewModel SavePostalAddress(PostalAddressEditViewModel model)
        {
            if (model != null && Guid.TryParse(model.CustomerID, out Guid customerid))
            {
                using (var context = new ApplicationDbContext())
                {
                    var postalAddress = new PostalAddress()
                    {
                        CustomerID     = customerid,
                        StreetAddress1 = model.StreetAddress1?.Trim(),
                        StreetAddress2 = model.StreetAddress2?.Trim(),
                        City           = model.City?.Trim(),
                        PostalCode     = model.PostalCode,
                        RegionCode     = model.SelectedRegionCode,
                        Iso3           = model.SelectedCountryIso3
                    };
                    postalAddress.Region  = context.Regions.Find(postalAddress.RegionCode);
                    postalAddress.Country = context.Countries.Find(postalAddress.Iso3);

                    context.PostalAddresses.Add(postalAddress);
                    context.SaveChanges();

                    var countriesRepo = new CountriesRepository();
                    model.Countries = countriesRepo.GetCountries();
                    var regionsRepo = new RegionsRepository();
                    model.Regions = regionsRepo.GetRegions(model.SelectedCountryIso3);
                    return(model);
                }
            }
            return(null);
        }
Exemplo n.º 6
0
        public void CRUD()
        {
            ICountriesRepository repository = new CountriesRepository("Assets/countries.xml");

            Assert.NotNull(repository);
            RetrieveByKey(repository);
        }
Exemplo n.º 7
0
        //Returnerar lista med länder
        public List <Country> getInfoOnSelectedCountry()
        {
            var c     = new CountriesRepository();
            var count = c.GetAllCountries();

            return(count);
        }
Exemplo n.º 8
0
        public static void TestFixtureSetup(TestContext context)
        {
            con = new NpgsqlConnection(cs);
            con.Open();

            regionsRepository       = new RegionsRepository(con);
            countriesRepository     = new CountriesRepository(con);
            manufacturersRepository = new ManufacturersRepository(con);
            manufacturerValidation  = new ManufacturerValidation(con);
            carsRepository          = new CarsRepository(con);

            regionsRepository.Save(Region1);
            regionsRepository.Save(Region2);
            regionsRepository.Save(Region3);
            regionsRepository.Flush();

            countriesRepository.Save(Country1);
            countriesRepository.Save(Country2);
            countriesRepository.Save(Country3);
            countriesRepository.Flush();

            manufacturersRepository.Save(Manufacturer1);
            manufacturersRepository.Save(Manufacturer2);
            manufacturersRepository.Save(Manufacturer3);
            manufacturersRepository.Flush();

            carsRepository.SaveAndFlush(Car2);
        }
Exemplo n.º 9
0
        public List <Country> GetCountries()
        {
            var rept = new CountriesRepository();
            var hej  = rept.GetAllCountries();

            return(hej);
        }
Exemplo n.º 10
0
 [TestInitialize] public override void TestInitialize()
 {
     base.TestInitialize();
     repository         = new CountriesRepository(db);
     controller         = "countries";
     detailsViewCaption = "Country";
 }
        public static void TestFixtureSetup(TestContext context)
        {
            con = new NpgsqlConnection(cs);
            con.Open();

            regionsRepository       = new RegionsRepository(con);
            countriesRepository     = new CountriesRepository(con);
            manufacturersRepository = new ManufacturersRepository(con);
            manufacturersService    = new ManufacturersService(con);

            regionsRepository.Save(Region1);
            regionsRepository.Save(Region2);
            regionsRepository.Save(Region3);
            regionsRepository.Flush();

            countriesRepository.Save(Country1);
            countriesRepository.Save(Country2);
            countriesRepository.Save(Country3);
            countriesRepository.Save(Country4);
            countriesRepository.Save(Country5);
            countriesRepository.Flush();

            manufacturersRepository.Save(Manufacturer1);
            manufacturersRepository.Save(Manufacturer2);
            manufacturersRepository.Save(Manufacturer3);
            manufacturersRepository.Save(Manufacturer4);
            manufacturersRepository.Save(Manufacturer5);
            manufacturersRepository.Save(Manufacturer6);
            manufacturersRepository.Save(Manufacturer7);
            manufacturersRepository.Save(Manufacturer8);
            manufacturersRepository.Save(Manufacturer9);
            manufacturersRepository.Flush();
        }
Exemplo n.º 12
0
        public ActionResult AddressTypePartial(AddressTypeViewModel model)
        {
            if (ModelState.IsValid && !String.IsNullOrWhiteSpace(model.CustomerID))
            {
                switch (model.SelectedAddressType)
                {
                case "Email":
                    var emailAddressModel = new EmailAddressViewModel()
                    {
                        CustomerID = model.CustomerID
                    };
                    return(PartialView("CreateEmailAddressPartial", emailAddressModel));

                case "Postal":
                    var postalAddressModel = new PostalAddressEditViewModel()
                    {
                        CustomerID = model.CustomerID
                    };
                    var countriesRepo = new CountriesRepository();
                    postalAddressModel.Countries = countriesRepo.GetCountries();
                    var regionsRepo = new RegionsRepository();
                    postalAddressModel.Regions = regionsRepo.GetRegions();
                    return(PartialView("CreatePostalAddressPartial", postalAddressModel));

                default:
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                }
            }
            return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
        }
Exemplo n.º 13
0
        public static void ReceiveRequest()
        {
            SevenWondersContext db = new SevenWondersContext();
            CountriesRepository countriesRepository = new CountriesRepository(db);

            var factory = new ConnectionFactory()
            {
                HostName = "localhost"
            };

            factory.Protocol = Protocols.DefaultProtocol;
            factory.Port     = AmqpTcpEndpoint.UseDefaultPort;

            using (var connection = factory.CreateConnection())
                using (var channel = connection.CreateModel())
                {
                    channel.QueueDeclare(queue: "rpc_queue", durable: false,
                                         exclusive: false, autoDelete: false, arguments: null);
                    channel.BasicQos(0, 1, false);
                    var consumer = new EventingBasicConsumer(channel);
                    channel.BasicConsume(queue: "rpc_queue",
                                         autoAck: false, consumer: consumer);
                    Console.WriteLine(" [x] Awaiting RPC requests");

                    consumer.Received += (model, ea) =>
                    {
                        string response = null;

                        var body       = ea.Body;
                        var props      = ea.BasicProperties;
                        var replyProps = channel.CreateBasicProperties();
                        replyProps.CorrelationId = props.CorrelationId;

                        try
                        {
                            var countries = countriesRepository.GetCountries();
                            var json      = JsonConvert.SerializeObject(countries);
                            response = json;
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(" [.] " + e.Message);
                            response = "";
                        }
                        finally
                        {
                            var responseBytes = Encoding.UTF8.GetBytes(response);
                            channel.BasicPublish(exchange: "", routingKey: props.ReplyTo,
                                                 basicProperties: replyProps, body: responseBytes);
                            channel.BasicAck(deliveryTag: ea.DeliveryTag,
                                             multiple: false);
                        }
                    };

                    Console.WriteLine(" Press [enter] to exit.");
                    Console.ReadLine();
                }
        }
Exemplo n.º 14
0
 public void GetAllCountries()
 {
     using (var db = new ExampleContext(Connection))
     {
         ICountriesRepository repository = new CountriesRepository(db);
         var countries = repository.GetAll();
         Assert.That(countries.Count(), Is.EqualTo(3));
     }
 }
Exemplo n.º 15
0
        public static void TestFixtureSetup(TestContext context)
        {
            con = new NpgsqlConnection(cs);
            con.Open();

            regionsRepository       = new RegionsRepository(con);
            countriesRepository     = new CountriesRepository(con);
            manufacturersRepository = new ManufacturersRepository(con);
            carsRepository          = new CarsRepository(con);
            carValidation           = new CarValidation(con);
            ownerCarsRepository     = new OwnerCarsRepository(con);
            ownersRepository        = new OwnersRepository(con);

            regionsRepository.Save(Region1);
            regionsRepository.Save(Region2);
            regionsRepository.Save(Region3);
            regionsRepository.Flush();

            countriesRepository.Save(Country1);
            countriesRepository.Save(Country2);
            countriesRepository.Save(Country3);
            countriesRepository.Save(Country4);
            countriesRepository.Save(Country5);
            countriesRepository.Flush();

            manufacturersRepository.Save(Manufacturer1);
            manufacturersRepository.Save(Manufacturer2);
            manufacturersRepository.Save(Manufacturer3);
            manufacturersRepository.Save(Manufacturer4);
            manufacturersRepository.Save(Manufacturer5);
            manufacturersRepository.Save(Manufacturer6);
            manufacturersRepository.Save(Manufacturer7);
            manufacturersRepository.Save(Manufacturer8);
            manufacturersRepository.Save(Manufacturer9);
            manufacturersRepository.Flush();

            carsRepository.Save(Car1);
            carsRepository.Save(Car2);
            carsRepository.Save(Car3);
            carsRepository.Save(Car4);
            carsRepository.Save(Car5);
            carsRepository.Save(Car6);
            carsRepository.Save(Car7);
            carsRepository.Save(Car8);
            carsRepository.Save(Car9);
            carsRepository.Save(Car10);
            carsRepository.Save(Car11);
            carsRepository.Save(Car12);
            carsRepository.Save(Car13);
            carsRepository.Save(Car14);
            carsRepository.Save(Car15);
            carsRepository.Flush();

            ownersRepository.SaveAndFlush(Owner2);

            ownerCarsRepository.SaveAndFlush(OwnerCar2);
        }
        public RegistrationViewModel(ApplicationManager appManager)
        {
            _appManager          = appManager;
            _countriesRepository = new CountriesRepository();

            SelectedCountry = Countries.First();
            SelectedSex     = Sexes.First();
            SelectedAge     = Ages.First();
        }
Exemplo n.º 17
0
 public UnitOfWork(TransaviaDbContext ctx, IEventDispatcher eventDispatcher)
 {
     _ctx             = ctx;
     _eventDispatcher = eventDispatcher;
     AirportTypes     = new AirportTypesRepository(ctx, eventDispatcher);
     AirportStatuses  = new AirportStatusesRepository(ctx, eventDispatcher);
     AirportSizes     = new AirportSizesRepository(ctx, eventDispatcher);
     Countries        = new CountriesRepository(ctx, eventDispatcher);
     Continents       = new ContinentsRepository(ctx, eventDispatcher);
     Airports         = new AirportsRepository(ctx, eventDispatcher);
 }
Exemplo n.º 18
0
        public MainWindow()
        {
            InitializeComponent();
            PopulateCurrencyData();
            PopulateListViewUsers();
            PupulateListViewCountries();
            localHandeler.SaveCountriesfromDBtoXML();


            TbTotalKm.IsReadOnly = true;
            tbUserID.IsEnabled = false;
            tbUsername.IsEnabled = false;
            tbBoss.IsEnabled = false;
            notesLoading = notesHandler.LoadNotes("Notes.xml");
            tbNotes.Text = notesLoading.Note;
            var rep = new CountriesRepository();

            main = this;

            var hej = rep.GetAllCountries();


            foreach(var x in hej)
            {
                CbCountries.Items.Add(x.Name);       
            }

            try
            {
                _reportDraftLoading = reportHandler.LoadDraft("DraftReport.xml");
                TbTotalKm.Text = _reportDraftLoading.NumberOfKilometersDrivenInTotal.ToString();
                TbCarTripLengthKm.Text = _reportDraftLoading.KilometersDriven.ToString();
                tbDoneOnTrip.Text = _reportDraftLoading.Description;
                dpStartDate.Text = _reportDraftLoading.StartDate;
                dpEndDate.Text = _reportDraftLoading.EndDate;
                foreach (var kvitto in _reportDraftLoading.imagePathsList)
                {
                    listBoxReceipts.Items.Add(kvitto);
                }
                foreach (var dayinfo in _reportDraftLoading.daysSpentInCountry)
                {
                    listBoxDays.Items.Add(dayinfo);
                }
                
                
            }
            catch
            {
                MessageBox.Show("Det finns inget sparat utkast att ladda");
            }


        }
Exemplo n.º 19
0
        public CustomerEditViewModel CreateCustomer()
        {
            var cRepo    = new CountriesRepository();
            var rRepo    = new RegionsRepository();
            var customer = new CustomerEditViewModel()
            {
                CustomerID = Guid.NewGuid().ToString(),
                Countries  = cRepo.GetCountries(),
                Regions    = rRepo.GetRegions()
            };

            return(customer);
        }
Exemplo n.º 20
0
        // GET: api/Countries
        public IEnumerable<Country> Get()
        {
            var countries = new List<Country>();

            var db = new CountriesRepository();
            for (int i = 1; i <= MaxCountryId; i++)
            {
                countries.Add(GetCountry(db, i));
            }
            return countries;

            // return new string[] { "value1", "value2" };
        }
        public static void TestFixtureSetup(TestContext context)
        {
            con = new NpgsqlConnection(cs);
            con.Open();

            regionsRepository   = new RegionsRepository(con);
            countriesRepository = new CountriesRepository(con);

            regionsRepository.Save(Region1);
            regionsRepository.Save(Region2);
            regionsRepository.Save(Region3);
            regionsRepository.Flush();
        }
Exemplo n.º 22
0
        public void Should_return_supported_countries()
        {
            var listOfSupportCountries = new List<Country>() {
                new Country { Name = "Canada" }, new Country { Name = "Mexico"}, new Country { Name = "United States" }
            };

            var listOfCountries = new CountriesRepository().GetAll();

            foreach(var cntry in listOfSupportCountries)
            {
                var exists = listOfCountries.Exists( c => c.Name == cntry.Name);
                Assert.IsTrue(exists);
            }
        }
 public TerritoryRegionCountryServices()
 {
     if (territoriesRepository == null)
     {
         territoriesRepository = new TerritoriesRepository();
     }
     if (regionsRepository == null)
     {
         regionsRepository = new RegionsRepository();
     }
     if (countriesRepository == null)
     {
         countriesRepository = new CountriesRepository();
     }
 }
Exemplo n.º 24
0
        private static void CountriesWork()
        {
            while (true)
            {
                Console.WriteLine("Выберите действие\n1 - Посмотреть страны\n2 - Добавить страну\n3 - Редактировать страну\n4 - Удалить страну");
                int answer = int.Parse(Console.ReadLine());

                switch (answer)
                {
                case 1:
                    using (var repository = new CountriesRepository())
                    {
                        var countries = repository.Select();
                        foreach (var country in countries)
                        {
                            Console.WriteLine($"{country.Name} - {country.Population} человек");
                        }
                    } break;

                case 2:
                    using (var repository = new CountriesRepository())
                    {
                        var newCountry = new Country();
                        while (newCountry.Name == null || newCountry.Name == string.Empty)
                        {
                            Console.Write("Введите название: ");
                            newCountry.Name = Console.ReadLine();
                        }
                        while (newCountry.Population < 0)
                        {
                            Console.Write("Введите численность населения: ");
                            newCountry.Population = int.Parse(Console.ReadLine());
                        }
                        newCountry.CreationDate = DateTime.Now;
                        repository.Insert(newCountry);
                    }
                    break;

                case 3: break;

                case 4: break;

                default:
                    Console.WriteLine("Нет такого варианта");
                    break;
                }
            }
        }
Exemplo n.º 25
0
        public ActionResult Index()
        {
            ICountiesRepository      countiesRepository      = new CountiesRepository(db);
            ICountriesRepository     countriesRepository     = new CountriesRepository(db);
            IPostalOfficesRepository postalOfficesRepository = new PostalOfficesRepository(db);
            IPlacesRepository        placesRepository        = new PlacesRepository(db);

            int    page       = !String.IsNullOrWhiteSpace(Request.QueryString["page"]) ? Convert.ToInt32(Request.QueryString["page"]) : 1;
            int    pageSize   = !String.IsNullOrWhiteSpace(Request.QueryString["pageSize"]) ? Convert.ToInt32(Request.QueryString["pageSize"]) : Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["ResultsPerPage"]);
            string sortOrder  = !String.IsNullOrWhiteSpace(Request.QueryString["sortOrder"]) ? Request.QueryString["sortOrder"] : "DESC";
            string sortColumn = !String.IsNullOrWhiteSpace(Request.QueryString["sortColumn"]) ? Request.QueryString["sortColumn"] : "PlacePK";
            string ordering   = sortColumn + " " + sortOrder;

            ordering = ordering.Trim();

            IQueryable <PlaceView> places = PlaceView.GetPlaceView(placesRepository.GetValid(), postalOfficesRepository.GetValid(), countiesRepository.GetValid(), countriesRepository.GetValid())
                                            .OrderBy(ordering);

            if (!String.IsNullOrWhiteSpace(Request.QueryString["searchString"]))
            {
                string searchString = Request.QueryString["searchString"].ToString();
                places = places.Where(c => c.Name.Contains(searchString));
            }

            places = places.Page(page, pageSize);

            if (!String.IsNullOrWhiteSpace(Request.QueryString["searchString"]))
            {
                string searchString = Request.QueryString["searchString"].ToString();
                ViewData["numberOfRecords"] = placesRepository.GetValid().Where(c => c.Name.Contains(searchString)).Count();
            }
            else
            {
                ViewData["numberOfRecords"] = placesRepository.GetValid().Count();
            }

            int numberOfPages = ((int)ViewData["numberOfRecords"] + pageSize - 1) / pageSize;

            if (page > numberOfPages)
            {
                string url = LinkHelper.getQueryStringArray(new string[] { "page" });
                return(Redirect("Place?" + url + "page=" + numberOfPages));
            }
            else
            {
                return(View("Index", places.ToList()));
            }
        }
Exemplo n.º 26
0
        public void uppdateCountry(string currname, string newname, string newcurr, int newsub)
        {
            var countryrep = new CountriesRepository();
            var list       = countryrep.GetAllCountries();
            var cid        = 1;

            foreach (var c in list)
            {
                if (c.Name == currname)
                {
                    cid = c.CID;
                }
            }


            CountriesRepository.UpdateCountry(cid, newname, newcurr, newsub);
        }
Exemplo n.º 27
0
        public ActionResult Delete(int?countryPK)
        {
            ICountriesRepository countriesRepository = new CountriesRepository(db);

            if (countryPK != null)
            {
                Country country = countriesRepository.GetCountryByPK((int)countryPK);

                country.Deleted = true;

                countriesRepository.SaveChanges();

                TempData["message"] = LayoutHelper.GetMessage("DELETE", country.CountryPK);
            }

            return(Redirect(Request.UrlReferrer.AbsoluteUri));
        }
Exemplo n.º 28
0
        public void BindDDLs(LegalEntityBranchView legalEntityBranchView, ObjectContext db)
        {
            //countries ddl
            ICountriesRepository countriesRepository = new CountriesRepository(db);

            legalEntityBranchView.Countries = new SelectList(countriesRepository.GetValid().OrderBy("Name ASC").ToList(), "CountryPK", "Name");

            //counties ddl
            ICountiesRepository countiesRepository = new CountiesRepository(db);

            legalEntityBranchView.Counties = new SelectList(countiesRepository.GetCountiesByCountry((int)legalEntityBranchView.CountryFK).OrderBy("Name ASC").ToList(), "CountyPK", "Name");

            //citiesCommunities dll
            if (legalEntityBranchView.CountyFK != null)
            {
                ICitiesCommunitiesRepository citiesCommunitiesRepository = new CitiesCommunitiesRepository(db);
                legalEntityBranchView.CitiesCommunities = new SelectList(citiesCommunitiesRepository.GetCitiesCommunitiesByCounty(Convert.ToInt32(legalEntityBranchView.CountyFK)).OrderBy("Name ASC"), "CityCommunityPK", "Name", legalEntityBranchView.CityCommunityFK);
            }
            else
            {
                legalEntityBranchView.CitiesCommunities = new SelectList(new List <CityCommunity>(), "CityCommunityPK", "Name");
            }

            //postal offices dll
            if (legalEntityBranchView.CountyFK != null)
            {
                IPostalOfficesRepository postalOfficesRepository = new PostalOfficesRepository(db);
                legalEntityBranchView.PostalOffices = new SelectList(postalOfficesRepository.GetValidByCounty(Convert.ToInt32(legalEntityBranchView.CountyFK)).OrderBy("Name ASC"), "PostalOfficePK", "Name", legalEntityBranchView.PostalOfficeFK);
            }
            else
            {
                legalEntityBranchView.PostalOffices = new SelectList(new List <PostalOffice>(), "PostalOfficePK", "Name");
            }

            //places dll
            if (legalEntityBranchView.PostalOfficeFK != null)
            {
                IPlacesRepository placesRepository = new PlacesRepository(db);
                legalEntityBranchView.Places = new SelectList(placesRepository.GetPlacesByPostalOffice(Convert.ToInt32(legalEntityBranchView.PostalOfficeFK)).OrderBy("Name ASC"), "PlacePK", "Name", legalEntityBranchView.PlaceFK);
            }
            else
            {
                legalEntityBranchView.Places = new SelectList(new List <Place>(), "PlacePK", "Name");
            }
        }
Exemplo n.º 29
0
        public void BindDDLs(CityCommunityView cityCommunityView, ObjectContext db)
        {
            //countries ddl
            ICountriesRepository countriesRepository = new CountriesRepository(db);

            cityCommunityView.Countries = new SelectList(countriesRepository.GetValid().OrderBy("Name ASC").ToList(), "CountryPK", "Name");

            //counties ddl
            if (cityCommunityView.CountryFK != null)
            {
                ICountiesRepository countiesRepository = new CountiesRepository(db);
                cityCommunityView.Counties = new SelectList(countiesRepository.GetCountiesByCountry(Convert.ToInt32((int)cityCommunityView.CountryFK)).OrderBy("Name ASC"), "CountyPK", "Name");
            }
            else
            {
                cityCommunityView.Counties = new SelectList(new List <County>(), "CountyPK", "Name");
            }
        }
Exemplo n.º 30
0
        public ActionResult Edit(int?countryPK)
        {
            if (countryPK != null)
            {
                ICountriesRepository countriesRepository = new CountriesRepository(db);

                Country country = countriesRepository.GetCountryByPK((int)countryPK);

                CountryView countryView = new CountryView();
                countryView.ConvertFrom(country, countryView);

                return(View(countryView));
            }
            else
            {
                return(RedirectToAction("Index", "Country"));
            }
        }
Exemplo n.º 31
0
 public UnitOfWork(DataContext context)
 {
     _context      = context;
     Users         = new UsersRepository(_context);
     Photos        = new PhotosRepository(_context);
     Groups        = new GroupsRepository(_context);
     Memberships   = new MembershipsRepository(_context);
     Auths         = new AuthRepository(_context);
     Comments      = new CommentsRepository(_context);
     Achievements  = new AchievementsRepository(_context);
     Cities        = new CitiesRepository(_context);
     Countries     = new CountriesRepository(_context);
     Locations     = new LocationsRepository(_context);
     Matchdays     = new MatchdaysRepository(_context);
     MatchStatuses = new MatchStatusesRepository(_context);
     Friends       = new FriendsRepository(_context);
     Messages      = new MessagesRepository(_context);
     Chats         = new ChatsRepository(_context);
 }
Exemplo n.º 32
0
        private Country GetCountry(CountriesRepository db, int id)
        {
            var country = db.Countries.Where(x => x.CountryId == id).FirstOrDefault();

            if (country == null)
                return new Country { Name = "NOT_FOUND", Name_nl = "NOT_FOUND", Region = "", SubRegion = "", Code = "", ShowSubRegion = false, DifficultyLevel = 0 };

            return new Country
            {
                Id = country.CountryId.ToString(),
                Name = country.Name,
                Name_nl = country.Name_nl,
                Region = country.Region,
                SubRegion = country.SubRegion,
                Code = country.Code,
                ShowSubRegion = country.ShowSubRegion,
                DifficultyLevel = country.DifficultyLevel
            };
        }
Exemplo n.º 33
0
        public ActionResult Edit(CountryView countryView)
        {
            if (ModelState.IsValid)
            {
                ICountriesRepository countriesRepository = new CountriesRepository(db);
                Country country = countriesRepository.GetCountryByPK((int)countryView.CountryPK);

                countryView.ConvertTo(countryView, country);

                countriesRepository.SaveChanges();

                TempData["message"] = LayoutHelper.GetMessage("UPDATE", country.CountryPK);

                return(RedirectToAction("Index", "Country"));
            }
            else
            {
                return(View(countryView));
            }
        }
        public QuestionCountryViewModel Get(int difficultyLevel, string excludeList)
        {
            var excludeCountries = new List<int>();
            if (excludeList != null)
            {
                string[] ar = excludeList.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                foreach (var item in ar)
                {
                    excludeCountries.Add(int.Parse(item));
                }
            }

            // ToDo: Take excludeList into account.

            var db = new CountriesRepository();

            var countries = db.Countries.Where(x => x.DifficultyLevel == difficultyLevel).ToArray();

            Random random = new Random();

            List<int> answers = new List<int>();

            // Get answer to question
            var cntry = GetRandomUniqueCountry(random, countries, excludeCountries, true);
            var answerId = cntry.CountryId;
            answers.Add(answerId);
            var region = cntry.Region;
            var subRegion = cntry.SubRegion;

            // Try to get 4 answers from the same region
            var countriesSameSubRegion = db.Countries.Where(x => x.Region == region &&
                                                                 x.SubRegion == subRegion).ToArray();
            if (countriesSameSubRegion.Length <= 4)
            {
                foreach (var c in countriesSameSubRegion)
                {
                    if (c.CountryId != answerId)
                    answers.Add(c.CountryId);
                }
            }
            else
            {
                for (int i = 0; i < 4; i++)
                {
                    var country = GetRandomUniqueCountry(random, countriesSameSubRegion, answers);
                    if (country != null)
                    {
                        answers.Add(country.CountryId);
                    }
                }
            }
            // Get other multiple choice answers
            var allCountries = db.Countries.ToArray();
            var answerCount = NumberOfChoices - answers.Count;
            int y= 0;
            while (y < answerCount)
            {
                var country = GetRandomUniqueCountry(random, allCountries, answers);
                if (country != null)
                {
                    answers.Add(country.CountryId);
                    y++;
                }
            }

            var questionCountries = GetCountries(answers);

            var shuffeledCountries = GetShuffeledCountries(random, questionCountries);

            return new QuestionCountryViewModel() { Answer = questionCountries[0], Choices = shuffeledCountries };
        }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="id">Answer to the question</param>
 /// <param name="count">Random other answers</param>
 /// <returns></returns>
 private Country[] GetCountries(List<int> ids)
 {
     var countries = new Country[ids.Count];
     var db = new CountriesRepository();
     int i = 0;
     foreach (var id in ids)
     {
         countries[i] = GetCountry(db, id);
         i++;
     }
     return countries;
 }
Exemplo n.º 36
0
 // GET: api/Countries/5
 public Country Get(int id)
 {
     var db = new CountriesRepository();
     return GetCountry(db, id);
 }