Beispiel #1
0
        private void SaveAndContinueButton_Click(object sender, RoutedEventArgs e)
        {
            // Don't allow the user to submit their application until these are valid:
            // Title, First Name, Surname, Email, Year, Month
            if (!TitleBoxIsValid() ||
                !TextEntryIsValid(FirstNameTextEntry) ||
                !TextEntryIsValid(SurnameTextEntry) ||
                !EmailIsValid(EmailEntry) ||
                !DateDropDownIsValid(YearComboBox, YearsList, YearsTitle) ||
                !DateDropDownIsValid(MonthComboBox, MonthsList, MonthsTitle))
            {
                return;
            }

            // Parse the birthdate and title
            DateTime applicantBirthDate
                = ParseAndFormatBirthdate(DayComboBox.Text, MonthComboBox.Text, YearComboBox.Text);

            Titles title = (Titles)TitleComboBox.SelectedIndex;

            // Process the applicant's application
            CrudManager.CreateApplication(title, FirstNameTextEntry.Text, MiddleNameTextEntry.Text, SurnameTextEntry.Text, applicantBirthDate, EmailEntry.Text, "07722 222 222", "07722 222 222", 25_000, 1_000);

            // Dependency-inject the credit checker and process the check
            CreditChecker creditChecker = new InternalCreditChecker();
            var           approval      = creditChecker.PerformCreditCheck(null);
            bool          accepted      = approval.Approved;

            var acceptedWindow = new AcceptedWindow(accepted); // Make new window

            acceptedWindow.Show();
            acceptedWindow.Focus();
            Close(); // Close current window
        }
Beispiel #2
0
        public async Task UploadToCosmos(CrudManager <TraveltimeSegment> crudManager, List <TraveltimeSegment> segments)
        {
            {
                List <Task> tasks = new List <Task>();
                foreach (var segment in segments)
                {
                    concurrencySemaphore.Wait();

                    var t = Task.Factory.StartNew(() =>
                    {
                        try
                        {
                            crudManager.Create(segment).Wait();
                        }
                        finally
                        {
                            concurrencySemaphore.Release();
                            UpdateProgress();
                        }
                    });

                    tasks.Add(t);
                }

                await Task.WhenAll(tasks.ToArray());
            }
        }
Beispiel #3
0
        public BookFlightViewModel(CrudManager crudManager, PageController pageController, FlightInfo selectedFlight, int adults, int children, int infants)
        {
            m_crudManager    = crudManager;
            m_pageController = pageController;

            SelectedFlight = selectedFlight;
            Adults         = adults;
            Children       = children;
            Infants        = infants;

            PassengerInfo = new List <PassengerInfo>();

            for (int i = 1; i <= Adults + Children + Infants; ++i)
            {
                PassengerInfo.Add(new PassengerInfo {
                    Index = i, DateOfBirth = DateTime.Today
                });
            }

            Nationalities = new List <NationalityInfo>();

            SelectedTicketType = SelectedFlight.TicketPrices[0];

            UiState = UiState.Normal;

            InitCommands();

            GetNationalities();
        }
Beispiel #4
0
        public void CrudManagerCanReadAllApplications()
        {
            List <Applicant> entries = CrudManager.RetrieveAllApplications();

            // Assertions
            Assert.NotNull(entries);
            Assert.Greater(entries.Count, 0);
        }
        public FlightSearchViewModel(CrudManager crudManager, PageController pageController)
        {
            m_crudManager    = crudManager;
            m_pageController = pageController;

            OriginCitySearchResult      = new List <CityInfo>();
            DestinationCitySearchResult = new List <CityInfo>();
            FlightSearchResult          = new List <FlightInfo>();

            InitCommands();
        }
Beispiel #6
0
        public void CrudManagerCanCreateValidApplication()
        {
            // Old
            int oldApplicantsCount = CrudManager.RetrieveAllApplications().Count;
            // Current
            Applicant applicantAdded         = CreateApplication();
            int       currentApplicantsCount = CrudManager.RetrieveAllApplications().Count;

            // Assertions
            Assert.AreEqual(ApplicantToTest, applicantAdded);
            Assert.Greater(currentApplicantsCount, oldApplicantsCount);
        }
Beispiel #7
0
        public AddFlightViewModel(CrudManager crudManager, PageController pageController)
        {
            m_crudManager    = crudManager;
            m_pageController = pageController;

            AirlineSearchResult = new List <AirlineInfo>();
            AirportSearchResult = new List <AirportInfo>();
            RouteSearchResult   = new List <RouteInfo>();

            SelectedDate = DateTime.Today;

            UiState = UiState.Normal;

            InitCommands();
        }
Beispiel #8
0
 public Applicant CreateApplication()
 {
     return(CrudManager.CreateApplication
            (
                (Titles)ApplicantToTest.TitleId,
                ApplicantToTest.FirstName,
                ApplicantToTest.MiddleName,
                ApplicantToTest.Surname,
                ApplicantToTest.BirthDate,
                ApplicantToTest.Email,
                ApplicantToTest.MobileNum,
                ApplicantToTest.HomeTelephoneNum,
                ApplicantToTest.AnnualPersonalIncome,
                ApplicantToTest.OtherHouseholdIncome
            ));
 }
Beispiel #9
0
        public void DeleteFromDatabase()
        {
            List <Applicant> applicantsToDelete = CrudManager
                                                  .RetrieveAllApplications()
                                                  .Where(a => a.Equals(ApplicantToTest) || a.Equals(ApplicantToTest_Edited)).ToList();

            if (null != applicantsToDelete && applicantsToDelete.Count > 0)
            {
                foreach (Applicant a in applicantsToDelete)
                {
                    if (null != a)
                    {
                        CrudManager.DeleteApplication(a);
                    }
                }
            }
        }
Beispiel #10
0
        public void CrudManagerCanDeleteValidEntry()
        {
            // Old
            int oldCount = CrudManager.RetrieveAllApplications().Count;
            // Current
            Applicant applicant    = CreateApplication();
            int       currentCount = CrudManager.RetrieveAllApplications().Count;

            // Final
            CrudManager.DeleteApplication(applicant);
            List <Applicant> finalApplicants = CrudManager.RetrieveAllApplications();
            int finalCount = finalApplicants.Count;

            // Assertions
            Assert.Less(oldCount, currentCount);
            Assert.Less(finalCount, currentCount);
        }
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var BlobName       = Request.Form["blobName"];
            var BlobKey        = Request.Form["blobKey"];
            var BlobContainer  = Request.Form["blobContainer"];
            var CosmosUrl      = Request.Form["cosmosUrl"];
            var CosmosKey      = Request.Form["cosmosKey"];
            var DatabaseName   = Request.Form["OutputDB"];
            var CollectionName = Request.Form["OutputColl"];
            var Path           = Request.Form["folder"];

            BlobManager          blobManager = new BlobManager(BlobName, BlobKey);
            List <IListBlobItem> items       = blobManager.ListAllBlobsAsync(BlobContainer, Path).Result;

            _logger.LogInformation($"{items.Count} items found to import");
            List <TraveltimeSegmentStatic> segments = new List <TraveltimeSegmentStatic>();

            foreach (IListBlobItem item in items)
            {
                segments.AddRange(CSVReader.GetStaticsFromCSVString(blobManager.DownloadBlob(item.Container.Name, BlobManager.getBlobIdFromURI(item.Uri)).Result));
            }
            _logger.LogInformation($"{segments.Count} documents parsed");

            CrudManager <TraveltimeSegmentStatic> crudManager = new CrudManager <TraveltimeSegmentStatic>
            {
                DatabaseUri    = CosmosUrl,
                DatabaseKey    = CosmosKey,
                DatabaseName   = DatabaseName,
                CollectionName = CollectionName
            };

            crudManager.Init();

            foreach (TraveltimeSegmentStatic segment in segments)
            {
                await crudManager.Create(segment);
            }

            return(RedirectToPage("/BE-Mobile/BEM_import_static"));
        }
Beispiel #12
0
        /// <summary>
        /// Se obtiene el administrador de CRUD de la entidad definida basada en el namespace de CrudImplementationAttribute.
        /// DefaultCrud debe ser el nombre de la implementación por defecto
        /// </summary>
        /// <typeparam name="Entity">Entidad qie se desea procesar</typeparam>
        /// <returns></returns>
        public static ICrudManager <Entity> GetCrudManager <Entity>()
            where Entity : class
        {
            if (string.IsNullOrWhiteSpace(CRUD_NAMESPACE))
            {
                throw new ImplementationException("No se ha configurado el CRUD_NAMESPACE en el CudManagerFactory");
            }
            if (string.IsNullOrWhiteSpace(CRUD_VALIDATOR_NAMESPACE))
            {
                throw new ImplementationException("No se ha configurado el CRUD_VALIDATOR_NAMESPACE en el CudManagerFactory");
            }
            if (string.IsNullOrWhiteSpace(ENTITIES_NAMESPACE))
            {
                throw new ImplementationException("No se ha configurado el ENTITIES_NAMESPACE en el CudManagerFactory");
            }

            var crudManager = new CrudManager <Entity>(_BuildCrudManager <Entity>());

            crudManager.CrudValidator = _BuildCrudValidator <Entity>();
            return(crudManager);
        }
Beispiel #13
0
        public AddRouteViewModel(CrudManager crudManager, PageController pageController)
        {
            m_crudManager    = crudManager;
            m_pageController = pageController;

            AirlineSearchResult     = new List <AirlineInfo>();
            OriginSearchResult      = new List <AirportInfo>();
            DestinationSearchResult = new List <AirportInfo>();
            AircraftSearchResult    = new List <AircraftInfo>();

            FlightDurations     = new ObservableCollection <FlightDuration>();
            ClassPricingSchemes = new ObservableCollection <ClassPricingScheme>();

            TravelClasses = new List <TravelClassInfo>();

            UiState = UiState.Normal;

            InitCommands();

            GetTravelClasses();
        }
Beispiel #14
0
        public void CrudManagerCanUpdateValidApplication()
        {
            // Old
            Applicant originalApplicant = CreateApplication();
            int       oldCount          = CrudManager.RetrieveAllApplications().Count;
            // Current
            Applicant applicantToEdit = originalApplicant.CreateMemberwiseClone();

            applicantToEdit.FirstName  = "Uma";
            applicantToEdit.MiddleName = "Karuna";
            applicantToEdit.Surname    = "Thurman";
            CrudManager.UpdateApplication(originalApplicant, applicantToEdit);
            // Final
            List <Applicant> finalApplicants = CrudManager.RetrieveAllApplications();
            int finalCount = finalApplicants.Count;

            // Assertions
            Assert.AreEqual(finalCount, oldCount);
            // The original remains in the database, just edited:
            Assert.False(finalApplicants.Contains(applicantToEdit));
            Assert.True(finalApplicants.Contains(originalApplicant));
        }
Beispiel #15
0
        public async Task Import(TaskModel model)
        {
            if (model.BlobInput == null)
            {
                Console.WriteLine("No Storage account connection info found, skipping task");
                return;
            }
            Console.WriteLine($"Starting blob import task for {model.BlobInput.AccountName},{model.BlobInput.Container},{model.BlobInput.Key} path {model.BlobInput.Path}");

            BlobManager manager = new BlobManager(model.BlobInput.AccountName, model.BlobInput.Key);

            List <Task> runningUploadTasks = new List <Task>();

            foreach (var path in model.BlobInput.Path)
            {
                Console.WriteLine($"Fetching al blobs at path {path}");
                List <IListBlobItem> items = manager.ListAllBlobsAsync(model.BlobInput.Container, path).Result;
                Console.WriteLine($"Found {items.Count} items at path {path}, parsing...");

                List <TraveltimeSegment> segments = new List <TraveltimeSegment>();
                foreach (IListBlobItem item in items)
                {
                    segments.AddRange(CSVReader.GetSegmentsFromCSVString(manager.DownloadBlob(item.Container.Name, BlobManager.getBlobIdFromURI(item.Uri)).Result));
                }

                CrudManager <TraveltimeSegment> crudManager = new CrudManager <TraveltimeSegment>
                {
                    DatabaseKey    = model.Output.Key,
                    DatabaseUri    = model.Output.URL,
                    DatabaseName   = model.Output.Database,
                    CollectionName = model.Output.Collection,
                };
                crudManager.Init();
                TotalToProcess += segments.Count;
                runningUploadTasks.Add(UploadToCosmos(crudManager, segments));
            }
            await Task.WhenAll();
        }
Beispiel #16
0
        public void Execute(ILogger logger, IBlockingQueue <BeMobileTaskModel, BEMobileSegmentTaskModel> queue)
        {
            if (BlobName == null && BlobKey == null)
            {
                logger.LogWarning("Execute called upon empty task");
                return;
            }
            logger.LogInformation("Starting BE-Mobile import task");
            BlobManager                     manager     = new BlobManager(BlobName, BlobKey);
            List <IListBlobItem>            items       = manager.ListAllBlobsAsync(BlobContainer, $"BE-Mobile/{Month}/Reistijden/{Traject}/").Result;
            CrudManager <TraveltimeSegment> crudManager = new CrudManager <TraveltimeSegment>
            {
                DatabaseKey    = CosmosKey,
                DatabaseUri    = CosmosUrl,
                DatabaseName   = DatabaseName,
                CollectionName = CollectionName,
            };

            crudManager.Init();

            List <TraveltimeSegment> segments = new List <TraveltimeSegment>();

            foreach (IListBlobItem item in items)
            {
                segments.AddRange(CSVReader.GetSegmentsFromCSVString(manager.DownloadBlob(item.Container.Name, BlobManager.getBlobIdFromURI(item.Uri)).Result));
            }

            foreach (TraveltimeSegment segment in segments)
            {
                queue.DocumentQueue.Add(new BEMobileSegmentTaskModel
                {
                    CreationMethod  = crudManager.Create,
                    SegmentToCreate = segment
                });
            }
            queue.DocumentsFinished += 1;
        }
Beispiel #17
0
 public void Setup()
 {
     m_crudManager = new CrudManager();
 }