From b55884129e0a31559af93f361cdbcb27dec85f9a Mon Sep 17 00:00:00 2001 From: Gregory Rudolph Date: Tue, 3 Aug 2021 08:33:38 -0400 Subject: [PATCH] Only let user into posting if they are set up properly. --- Pages/Index.cshtml.cs | 22 +++++++++++++++++----- Pages/Settings.cshtml | 16 ++++++++-------- Pages/Settings.cshtml.cs | 1 + Posting.cs | 3 +-- 4 files changed, 27 insertions(+), 15 deletions(-) diff --git a/Pages/Index.cshtml.cs b/Pages/Index.cshtml.cs index 3f90ab6..d63d674 100644 --- a/Pages/Index.cshtml.cs +++ b/Pages/Index.cshtml.cs @@ -43,6 +43,9 @@ namespace StateJobsNYSubmit.Pages public void OnGet(string vacancyID) { GetUserData(); + if (userData.skillOptions.Count == 0) { + Response.Redirect("Settings"); + } if (vacancyID != null && !vacancyID.Trim().Equals("")) { posting = new Posting(vacancyID); @@ -57,16 +60,25 @@ namespace StateJobsNYSubmit.Pages string coverLetterFormat = Request.Cookies["CoverLetter"]; if (vacancyID != null && !vacancyID.Trim().Equals("")) { - posting = new Posting(vacancyID); - if (!string.IsNullOrEmpty(Request.Form["SkillCheckboxes"])) + try + { + + posting = new Posting(vacancyID.Trim()); + if (!string.IsNullOrEmpty(Request.Form["SkillCheckboxes"])) + { + this.CoverLetter = posting.GenerateLetter(coverLetterFormat, userData, Request.Form["SkillCheckboxes"]); + } + this.Posting_ID = vacancyID; + } + catch (Exception e) { - this.CoverLetter = posting.GenerateLetter(coverLetterFormat, userData, Request.Form["SkillCheckboxes"]); + Console.WriteLine($"Vacancy ID {vacancyID} caused exception {e}"); + _logger.LogError(e.ToString()); } - this.Posting_ID = vacancyID; } else { - Console.WriteLine($"Unable to get Posting ID from form."); + _logger.LogDebug($"Unable to get Posting ID from form."); } } diff --git a/Pages/Settings.cshtml b/Pages/Settings.cshtml index 1d9f1b5..69e27fa 100644 --- a/Pages/Settings.cshtml +++ b/Pages/Settings.cshtml @@ -7,26 +7,26 @@
- Settings + Settings - Don't forget to save!
- - - + + + - +
- - Write your cover letter above, using variables like $name, $title, $vacancy, $box to auto-fill from the posting. + + Write your cover letter above, using variables like $name, $title, $vacancy, $box, and $skills to auto-fill from the posting.
- + List your skills for applications above, one skill per line.
diff --git a/Pages/Settings.cshtml.cs b/Pages/Settings.cshtml.cs index 32c51f8..2ba615a 100644 --- a/Pages/Settings.cshtml.cs +++ b/Pages/Settings.cshtml.cs @@ -47,6 +47,7 @@ namespace StateJobsNYSubmit.Pages Response.Cookies.Append("PrivateData", p.EncryptString(JsonConvert.SerializeObject(userData))); userData.coverLetter = Request.Cookies["CoverLetter"]; skills = Request.Cookies["Skills"]; + Response.Redirect("/"); } } } diff --git a/Posting.cs b/Posting.cs index 599417f..34f5d99 100644 --- a/Posting.cs +++ b/Posting.cs @@ -58,7 +58,7 @@ public class Posting case 1: this.Title = link.InnerHtml.Trim(); break; case 2: this.OccupationalCategory = link.InnerHtml.Trim(); break; case 3: this.SalaryGrade = link.InnerHtml.Trim(); break; - case 4: this.BargainingUnit = link.InnerHtml.Trim(); break; + case 4: this.BargainingUnit = link.InnerHtml.Trim().Replace("&", "&"); break; case 5: this.SalaryRange = link.InnerHtml.Trim(); break; case 6: this.EmploymentType = link.InnerHtml.Trim(); break; case 7: this.AppointmentType = link.InnerHtml.Trim(); break; @@ -89,7 +89,6 @@ public class Posting this.BoxNumber = boxRegex.Matches(this.NotesOnApplying)[0].Value.Replace("Box ", ""); } catch (Exception) { } - this.BargainingUnit = this.BargainingUnit.Replace("&", "&"); this.VacancyID = id; }