public ScCaseSearchViewModel() { //Default values Results = new AvailableDatesByLocation(); TimeSlotExpired = false; CaseLocationName = string.Empty; CaseRegistryId = -1; BookingLocationName = string.Empty; BookingRegistryId = -1; ContainerId = -1; SelectedCaseDate = string.Empty; CaseNumber = string.Empty; HearingTypeId = -1; HearingTypeName = string.Empty; }
public void AvailableDatesByLocation() { const int vancouver = 1; const int victoria = 2; const int trialManagementConference = 9090; AvailableDatesByLocation vancouverResults = _soapClient .AvailableDatesByLocationAsync(vancouver, trialManagementConference) .Result; Assert.NotNull(vancouverResults); AvailableDatesByLocation victoriaResults = _soapClient .AvailableDatesByLocationAsync(victoria, trialManagementConference) .Result; Assert.NotNull(victoriaResults); }
/// <summary> /// Book court case /// </summary> public async Task <ScCaseConfirmViewModel> BookCourtCase(ScCaseConfirmViewModel model, string userGuid, string userDisplayName) { //if the user could not be detected return if (string.IsNullOrWhiteSpace(userGuid)) { return(model); } ScSessionBookingInfo bookingInfo = _session.ScBookingInfo; // check the schedule again to make sure the time slot wasn't taken by someone else AvailableDatesByLocation schedule = await _client.AvailableDatesByLocationAsync( bookingInfo.BookingRegistryId, bookingInfo.HearingTypeId); //ensure time slot is still available if (IsTimeStillAvailable(schedule, bookingInfo.ContainerId)) { //build object to send to the API var bookInfo = new BookHearingInfo { CEIS_Physical_File_ID = bookingInfo.CaseId, containerID = bookingInfo.ContainerId, dateTime = model.FullDate, hearingLength = bookingInfo.HearingLengthMinutes, locationID = bookingInfo.BookingRegistryId, requestedBy = $"{userDisplayName} {model.Phone} {model.EmailAddress}", hearingTypeId = bookingInfo.HearingTypeId }; //submit booking BookingHearingResult result = await _client.BookingHearingAsync(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 await _dbContext.SaveChangesAsync(); //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; var emailBody = await GetEmailBody(); //send email await _mailService.SendEmail( //"*****@*****.**", model.EmailAddress, EmailSubject, emailBody); //clear booking info session _session.ScBookingInfo = 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.ScBookingInfo = bookingInfo; return(model); }
/// <summary> /// Check if a time slot is still available for a court booking /// </summary> public bool IsTimeStillAvailable(AvailableDatesByLocation schedule, int containerId) { //check if the container ID is still available return(schedule.AvailableDates.Any(x => x.ContainerID == containerId)); }
public async Task <List <ScAvailableDayViewModel> > AvailableScDatesByLocation(int locationId, int hearingType) { // call the remote API AvailableDatesByLocation soapResult = await _client .AvailableDatesByLocationAsync(locationId, hearingType); // sort the available times chronologically IOrderedEnumerable <ContainerInfo> dates = soapResult .AvailableDates .OrderBy(d => d.Date_Time); // create the return object var result = new List <ScAvailableDayViewModel>(); ScAvailableDayViewModel day = null; DateTime?lastDate = null; // loop through the available times and group them by date foreach (ContainerInfo item in dates) { DateTime date = item.Date_Time.Date; if (date != lastDate) { // starting a new day grouping... // add the previous day grouping to the result collection if (lastDate != null) { result.Add(day); } // create a new day grouping day = new ScAvailableDayViewModel { Date = date, Weekday = date.DayOfWeek.ToString(), FormattedDate = date.ToString("MMMM dd, yyyy"), Times = new List <ScAvailableTimeViewModel>() }; } // add the timeslot to the day grouping day.Times.Add(new ScAvailableTimeViewModel { ContainerId = item.ContainerID, StartDateTime = item.Date_Time, Start = item.Date_Time.ToString("hh:mmtt").ToLower(), End = item.Date_Time.AddMinutes(soapResult.BookingDetails.detailBookingLength) .ToString("hh:mmtt").ToLower() }); lastDate = date; } // add the last day grouping to the result collection if (day != null) { result.Add(day); } // return the list of day groupings return(result); }
/// <summary> /// Search for available times /// </summary> public async Task <ScCaseSearchViewModel> GetSearchResults(ScCaseSearchViewModel model) { // Load locations from cache var retval = new ScCaseSearchViewModel { HearingTypeId = model.HearingTypeId, CaseRegistryId = model.CaseRegistryId, CaseNumber = model.CaseNumber, TimeSlotExpired = model.TimeSlotExpired, SelectedCourtClass = model.SelectedCourtClass }; //set hearing type name if (retval.HearingTypeId > 0 && ScHearingType.HearingTypeNameMap.ContainsKey(retval.HearingTypeId)) { retval.HearingTypeName = ScHearingType.HearingTypeNameMap[retval.HearingTypeId]; } //set selected registry name retval.CaseLocationName = await _cache.GetLocationNameAsync(retval.CaseRegistryId); // set booking location information retval.BookingRegistryId = await _cache.GetBookingLocationIdAsync( retval.CaseRegistryId, retval.HearingTypeId ) ?? retval.CaseRegistryId; retval.BookingLocationName = await _cache.GetLocationNameAsync(retval.BookingRegistryId); //search the current case number string caseNumber = await BuildCaseNumber(model.CaseNumber, model.CaseRegistryId); int caseId = await _client.caseNumberValidAsync(caseNumber); if (caseId == 0) { //case could not be found retval.IsValidCaseNumber = false; //empty result set retval.Results = new AvailableDatesByLocation(); //get contact information retval.RegistryContactNumber = GetRegistryContactNumber(model.CaseRegistryId); } else { //valid case number retval.IsValidCaseNumber = true; AvailableDatesByLocation schedule = await _client.AvailableDatesByLocationAsync( retval.BookingRegistryId, model.HearingTypeId ); int hearingLength = schedule.BookingDetails.detailBookingLength; retval.Results = schedule; string bookingTime = ""; DateTime?dt = null; //check for valid date if (model.ContainerId > 0) { if (!IsTimeStillAvailable(schedule, model.ContainerId)) { retval.TimeSlotExpired = true; } //convert JS ticks to .Net date dt = new DateTime(Convert.ToInt64(model.SelectedCaseDate)); //set date properties retval.ContainerId = model.ContainerId; retval.SelectedCaseDate = model.SelectedCaseDate; bookingTime = $"{dt.Value:hh:mm tt} to {dt.Value.AddMinutes(hearingLength):hh:mm tt}"; retval.TimeSlotFriendlyName = $"{dt.Value:MMMM dd} from {bookingTime}"; } _session.ScBookingInfo = new ScSessionBookingInfo { ContainerId = model.ContainerId, CaseNumber = model.CaseNumber.ToUpper().Trim(), FullCaseNumber = caseNumber, CaseId = caseId, HearingTypeId = model.HearingTypeId, HearingTypeName = retval.HearingTypeName, HearingLengthMinutes = hearingLength, CaseRegistryId = model.CaseRegistryId, CaseLocationName = retval.CaseLocationName, BookingRegistryId = retval.BookingRegistryId, BookingLocationName = retval.BookingLocationName, TimeSlotFriendlyName = bookingTime, SelectedCaseDate = model.SelectedCaseDate, DateFriendlyName = dt?.ToString("dddd, MMMM dd, yyyy") ?? "" }; } return(retval); }