Exemplo n.º 1
0
        public void COAAvailableDatesAsync()
        {
            CoAAvailableDates result = _soapClient.COAAvailableDatesAsync().Result;

            Assert.NotNull(result);
            Assert.True(result.AvailableDates.Length == 136);
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Groups Court of Appeal available hearing dates by month and filter by full day if needed
        /// </summary>
        public Dictionary <DateTime, List <DateTime> > GroupAvailableDates(CoAAvailableDates availableDates, bool fullDay)
        {
            var result = new Dictionary <DateTime, List <DateTime> >();

            IOrderedEnumerable <DateTime> dates;

            if (fullDay)
            {
                dates = availableDates.AvailableDates
                        .Where(d => d.availability == "Full Day")
                        .Select(s => s.scheduleDate)
                        .Distinct()
                        .OrderBy(s => s);
            }
            else
            {
                dates = availableDates.AvailableDates
                        .Select(s => s.scheduleDate)
                        .Distinct()
                        .OrderBy(s => s);
            }

            DateTime previousMonth = DateTime.MinValue;

            List <DateTime> availableDatesInMonth = new List <DateTime>();
            DateTime        currentMonth          = previousMonth;

            foreach (DateTime date in dates)
            {
                currentMonth = new DateTime(date.Year, date.Month, 1);

                if (previousMonth.Month != date.Month || previousMonth.Year != date.Year)
                {
                    availableDatesInMonth = new List <DateTime>();

                    if (currentMonth != DateTime.MinValue)
                    {
                        result.Add(currentMonth, availableDatesInMonth);
                    }
                }

                availableDatesInMonth.Add(date);

                previousMonth = currentMonth;
            }

            return(result);
        }
Exemplo n.º 3
0
        /// <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);
        }
Exemplo n.º 4
0
 /// <summary>
 ///     Check if a time slot is still available for a court booking
 /// </summary>
 public bool IsTimeStillAvailable(CoAAvailableDates schedule, DateTime selectedDate)
 {
     //check if the container ID is still available
     return(schedule.AvailableDates.Any(x => x.scheduleDate == selectedDate));
 }