Example #1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ApplicantsDbContext db)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            db.Database.EnsureCreated();

            app.UseCors(builder => builder
                        .AllowAnyOrigin()
                        .AllowAnyMethod()
                        .AllowAnyHeader()
                        );

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseSwagger();

            app.UseSwaggerUI(options =>
                             options.SwaggerEndpoint("/swagger/v1/swagger.json", "Applicant API v1"));

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapGet("/", context =>
                {
                    context.Response.Redirect("/swagger/");
                    return(Task.CompletedTask);
                });
                endpoints.MapControllers();
            });
        }
Example #2
0
        void DoImport(string[] fileNames)
        {
            var list = new List <IEnumerable <Applicant> >();

            foreach (var fileName in fileNames)
            {
                try {
                    list.Add(CsvHelper.ImportCsvFile(fileName));
                } catch (Exception ex) {
                    Dispatcher.Invoke(() => MessageBox.Show(string.Format(_errorImportFile, fileName, ex), Title));
                }
            }

            var db = new ApplicantsDbContext();

            try {
                foreach (var l in list)
                {
                    foreach (var i in l)
                    {
                        db.Insert(i);
                    }
                }
            } catch (Exception ex) {
                Dispatcher.Invoke(() => MessageBox.Show(string.Format(_erorImport, ex), Title));
            }
        }
Example #3
0
        void ReloadData()
        {
            var db = new ApplicantsDbContext();

            if (_viewModel.Applicants != null)
            {
                _viewModel.Applicants.ListChanged -= ApplicantsOnCollectionChanged;
            }
            _viewModel.Applicants              = new BindingList <Applicant>(db.Applicants.Select(c => c).ToList());
            _viewModel.Applicants.ListChanged += ApplicantsOnCollectionChanged;
        }
Example #4
0
 void ApplicantsOnCollectionChanged(object sender, ListChangedEventArgs e)
 {
     if (e.ListChangedType == ListChangedType.ItemChanged)
     {
         var newa = _viewModel.Applicants[e.NewIndex];
         var db   = new ApplicantsDbContext();
         try {
             db.Update(newa);
         } catch (Exception ex) {
             MessageBox.Show(string.Format(_errorUpdate, ex), Title);
         }
     }
 }
Example #5
0
        void AddCommandExecuted(object sender, ExecutedRoutedEventArgs e)
        {
            var db = new ApplicantsDbContext();
            var n  = new Applicant()
            {
                ApplicantId = Guid.NewGuid()
            };

            try {
                db.Insert(n);
            } catch (Exception ex) {
                MessageBox.Show(string.Format(_erroradding, ex), Title);
            } finally {
                ReloadData();
                _viewModel.Current = _viewModel.Applicants.FirstOrDefault(a => a.ApplicantId == n.ApplicantId);
            }
        }
Example #6
0
        void DeleteCommandExecuted(object sender, ExecutedRoutedEventArgs e)
        {
            var a = _viewModel.Current;

            if (a == null)
            {
                return;
            }
            var db = new ApplicantsDbContext();

            try {
                db.Delete(a);
            } catch (Exception ex) {
                MessageBox.Show(string.Format(_errorDelete, ex), Title);
            } finally {
                ReloadData();
            }
        }
Example #7
0
        void ClearCommandExecuted(object sender, ExecutedRoutedEventArgs e)
        {
            var res = MessageBox.Show(_messageClear, Title, MessageBoxButton.YesNo, MessageBoxImage.Question);

            if (res != MessageBoxResult.Yes)
            {
                return;
            }

            var db = new ApplicantsDbContext();

            try {
                db.Applicants.Delete();
            } catch (Exception ex) {
                MessageBox.Show(string.Format(_errorClear, ex), Title);
            } finally {
                ReloadData();
            }
        }
 public ApplicantService(ApplicantsDbContext db)
 {
     _db = db;
 }