Exemplo n.º 1
0
        /// <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
            (retval.FullCaseNumber, retval.LocationPrefix) = await BuildCaseNumber(model.CaseNumber, model.CaseRegistryId);

            retval.CourtFiles = await _client.caseNumberValidAsync(retval.FullCaseNumber);

            if (!retval.IsValidCaseNumber)
            {
                //get contact information
                retval.RegistryContactNumber = GetRegistryContactNumber(model.CaseRegistryId);
            }
            else
            {
                retval.Results = await _client.AvailableDatesByLocationAsync(
                    retval.BookingRegistryId,
                    model.HearingTypeId
                    );

                //check for valid date
                if (model.ContainerId > 0)
                {
                    retval.TimeSlotExpired = !IsTimeStillAvailable(retval.Results, model.ContainerId);

                    //convert JS ticks to .Net date
                    DateTime?dt = new DateTime(Convert.ToInt64(model.SelectedCaseDate));

                    //set date properties
                    retval.ContainerId      = model.ContainerId;
                    retval.SelectedCaseDate = model.SelectedCaseDate;

                    string bookingTime = $"{dt.Value:hh:mm tt} to {dt.Value.AddMinutes(retval.HearingLengthMinutes):hh:mm tt}";

                    retval.TimeSlotFriendlyName = $"{dt.Value:MMMM dd} from {bookingTime}";
                }

                _session.ScBookingInfo = new ScSessionBookingInfo
                {
                    ContainerId         = model.ContainerId,
                    CaseNumber          = model.CaseNumber.ToUpper().Trim(),
                    FullCaseNumber      = retval.FullCaseNumber,
                    CaseId              = (int)retval.CourtFiles[0].physicalFileId,
                    HearingTypeId       = model.HearingTypeId,
                    HearingTypeName     = retval.HearingTypeName,
                    Results             = retval.Results,
                    CaseRegistryId      = model.CaseRegistryId,
                    CaseLocationName    = retval.CaseLocationName,
                    BookingRegistryId   = retval.BookingRegistryId,
                    BookingLocationName = retval.BookingLocationName,
                    SelectedCaseDate    = model.SelectedCaseDate,
                };
            }

            return(retval);
        }
        /// <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);
        }