/// <summary> /// Renders the template for the email body to a string (~/Views/CoaBooking/Email.cshtml) /// </summary> private async Task <string> GetEmailBody() { //user information SessionUserInfo user = _session.GetUserInformation(); // booking information CoaSessionBookingInfo booking = _session.CoaBookingInfo; //set ViewModel for the email var viewModel = new EmailViewModel { EmailAddress = user.Email, Phone = user.Phone, CourtFileNumber = booking.CaseNumber, RelatedCaseList = booking.RelatedCaseList, CaseType = booking.CaseType, TypeOfConference = booking.HearingTypeName, HearingLength = booking.IsFullDay ?? false ? "Full Day" : "Half Day", Date = booking.SelectedDate?.ToString("dddd, MMMM dd, yyyy") ?? "", RelatedCasesString = "" }; if (booking.RelatedCaseList != null && booking.RelatedCaseList.Any()) { viewModel.RelatedCasesString = "\nRELATED FILE NUMBER(S):\n" + string.Join(", ", booking.RelatedCaseList) + "\n"; } var template = $"CoaBooking/EmailText"; //Render the email template return(await _viewRenderService.RenderToStringAsync(template, viewModel)); }
public IActionResult CaseConfirm() { CoaSessionBookingInfo bookingInfo = _session.CoaBookingInfo; if (string.IsNullOrEmpty(bookingInfo.CaseNumber)) { return(Redirect("/scjob/booking/coa/CaseSearch")); } //user information SessionUserInfo cui = _session.GetUserInformation(); //Swapping Case Number to the main case file if it was selected from the search result of a sub case file number if (bookingInfo.CaseList.Length > 1) { var mainCase = bookingInfo.CaseList.Where(x => x.Main).First(); var finalCaseNumber = bookingInfo.SelectedCases.Where(x => x == mainCase.Case_Num).FirstOrDefault() ?? bookingInfo.CaseNumber; //Store final main case number back to the session bookingInfo.CaseNumber = finalCaseNumber; //Filtering out related cases var relatedCaseList = new List <string>(); foreach (var x in bookingInfo.SelectedCases) { if (x != finalCaseNumber) { relatedCaseList.Add(x); } } //Store final main case number back to the session bookingInfo.RelatedCaseList = relatedCaseList; } //Time-slot is still available var model = new CoaCaseConfirmViewModel { CaseNumber = bookingInfo.CaseNumber, CaseType = bookingInfo.CaseType, CertificateOfReadiness = bookingInfo.CertificateOfReadiness, DateIsAgreed = bookingInfo.DateIsAgreed, //LowerCourtOrder = bookingInfo.LowerCourtOrder, IsFullDay = bookingInfo.IsFullDay, HearingTypeId = bookingInfo.HearingTypeId, HearingTypeName = bookingInfo.HearingTypeName, SelectedDate = bookingInfo.SelectedDate, EmailAddress = cui.Email, Phone = cui.Phone, CaseList = bookingInfo.CaseList, SelectedCases = bookingInfo.SelectedCases, RelatedCaseList = bookingInfo.RelatedCaseList }; // save the booking info back to the session _session.CoaBookingInfo = bookingInfo; return(View(model)); }
public IActionResult CaseBooked() { CoaSessionBookingInfo bookingInfo = _session.CoaBookingInfo; if (string.IsNullOrEmpty(bookingInfo.CaseNumber)) { return(Redirect("/scjob/booking/coa/CaseSearch")); } return(View()); }
/// <summary> /// Search for available times /// </summary> public async Task <CoaCaseSearchViewModel> GetSearchResults(CoaCaseSearchViewModel model) { var retval = model; bool invalidCaseNumberFormat = false; COACaseList caseNumberResult = new COACaseList(); //search the current case number try { caseNumberResult = await _client.CoACaseNumberValidAsync(model.CaseNumber); } catch (FaultException ex) { if (ex.Message.ToLower().Contains("string was not in a correct format")) { invalidCaseNumberFormat = true; } } if (invalidCaseNumberFormat || caseNumberResult.CaseType.ToLower() == "not found") { //case could not be found retval.IsValidCaseNumber = false; //empty result set retval.Results = new Dictionary <DateTime, List <DateTime> >(); //retval.CaseId = 0; } else { //case ID int caseId = caseNumberResult.CaseList[0].CaseId; retval.CaseId = caseId; //case type string caseType = caseNumberResult.CaseType; retval.CaseType = caseType; //valid case number retval.IsValidCaseNumber = true; retval.CaseList = caseNumberResult.CaseList; if (caseType == CoaCaseType.Civil) { retval.HearingTypeId = 24; } else if (caseType == CoaCaseType.Criminal) { retval.HearingTypeId = model.HearingTypeId; } if (model.Step2Complete) { retval.HearingTypeName = CoaHearingType .GetHearingTypes() .FirstOrDefault(h => h.HearingTypeId == model.HearingTypeId)? .Description ?? ""; } var bookingInfo = new CoaSessionBookingInfo { CaseId = caseId, CaseNumber = model.CaseNumber.ToUpper().Trim(), CaseType = caseType, CertificateOfReadiness = model.CertificateOfReadiness, DateIsAgreed = model.DateIsAgreed, //LowerCourtOrder = model.LowerCourtOrder, IsFullDay = model.IsFullDay, HearingTypeName = retval.HearingTypeName, SelectedDate = model.SelectedDate, CaseList = retval.CaseList, SelectedCases = model.SelectedCases, }; if (model.HearingTypeId != null) { bookingInfo.HearingTypeId = model.HearingTypeId.Value; } _session.CoaBookingInfo = bookingInfo; } return(retval); }
/// <summary> /// Book court case /// </summary> public async Task <CoaCaseConfirmViewModel> BookCourtCase(CoaCaseConfirmViewModel model, string userGuid, string userDisplayName) { //if the user could not be detected return if (string.IsNullOrWhiteSpace(userGuid)) { return(model); } CoaSessionBookingInfo bookingInfo = _session.CoaBookingInfo; // check the schedule again to make sure the time slot wasn't taken by someone else CoAAvailableDates schedule = await _client.COAAvailableDatesAsync(); //ensure time slot is still available if (IsTimeStillAvailable(schedule, bookingInfo.SelectedDate.Value)) { //Fetch final main case file after ruling out selection of cases with main case and related cases var finalCase = bookingInfo.CaseList.Where(x => x.Case_Num == bookingInfo.CaseNumber).First(); var relatedCases = ""; if (finalCase.Main && model.RelatedCaseList != null && model.RelatedCaseList.Count > 0) { var relatedCaseIDList = bookingInfo.CaseList.Where(x => model.RelatedCaseList.Contains(x.Case_Num)).Select(x => x.CaseId).ToList(); relatedCases = string.Join("|", relatedCaseIDList); } //build object to send to the API var bookInfo = new CoABookingHearingInfo { caseID = finalCase.CaseId, MainCase = finalCase.Main, RelatedCases = relatedCases, email = $"{model.EmailAddress}", hearingDate = DateTime.Parse($"{model.SelectedDate.Value}"), hearingLength = (bookingInfo.IsFullDay ?? false) ? "Full" : "Half", phone = $"{model.Phone}", hearingTypeId = bookingInfo.HearingTypeId, requestedBy = $"{userDisplayName}" }; //submit booking BookingHearingResult result = await _client.CoAQueueHearingAsync(bookInfo); //get the raw result bookingInfo.RawResult = result.bookingResult; //test to see if the booking was successful if (result.bookingResult.ToLower().StartsWith("success")) { //create database entry DbSet <BookingHistory> bookingHistory = _dbContext.Set <BookingHistory>(); bookingHistory.Add(new BookingHistory { ContainerId = bookingInfo.ContainerId, SmGovUserGuid = userGuid, Timestamp = DateTime.Now }); //save to DB _dbContext.SaveChanges(); //update model model.IsBooked = true; bookingInfo.IsBooked = true; //store user info in session for next booking var userInfo = new SessionUserInfo { Phone = model.Phone, Email = model.EmailAddress, ContactName = $"{userDisplayName}" }; _session.UserInfo = userInfo; //send email await _mailService.SendEmail( model.EmailAddress, EmailSubject, await GetEmailBody()); //clear booking info session _session.CoaBookingInfo = null; } else { model.IsBooked = false; bookingInfo.IsBooked = false; } } else { //The booking is not available anymore //user needs to choose a new time slot model.IsTimeSlotAvailable = false; model.IsBooked = false; bookingInfo.IsBooked = false; } // save the booking info back to the session _session.CoaBookingInfo = bookingInfo; return(model); }