コード例 #1
0
        //This method show the menu when the user is logged with correct credentials
        public virtual async Task MessageReceivedAsync2(IDialogContext context, IAwaitable <IMessageActivity> result)
        {
            ACFCustomer customerState2 = new ACFCustomer();

            if (!context.PrivateConversationData.TryGetValue <ACFCustomer>("customerState", out customerState2))
            {
                customerState2 = new ACFCustomer();
            }
            int testCustomerStateId = customerState2.CustomerId;

            this.ShowOptions(context);
        }
コード例 #2
0
        /// <summary>
        /// This method show the menu 2 (see in the instructions on the top)
        /// </summary>
        /// <param name="context"></param>
        public void ShowOptions(IDialogContext context)
        {
            ACFCustomer customerState2 = new ACFCustomer();

            if (!context.PrivateConversationData.TryGetValue <ACFCustomer>("customerState", out customerState2))
            {
                customerState2 = new ACFCustomer();
            }
            int testCustomerStateId = customerState2.CustomerId;

            PromptDialog.Choice(context, this.OnOptionSelected, new List <string>()
            {
                BookOption, StatusOption, RescheduleOption, CancelOption, SaveCustomerOption, LogOut
            }, "Please choose the operation that you want", "Not a valid option", 3);
        }
コード例 #3
0
        /// <summary>
        /// This method create an Iform (form flow) for reschedule an appointement
        /// </summary>
        /// <returns></returns>
        public static IForm <ReservationReschedule> BuildForm()
        {
            //Instance of library for manage appoinments
            WebAppoinmentsClientLibrary.Appoinments appointmentLibrary = new WebAppoinmentsClientLibrary.Appoinments();
            #region On complete, process Order
            OnCompletionAsyncDelegate <ReservationReschedule> processOrder = async(context, state) =>
            {
                try
                {
                    Char     delimiter        = '.';
                    string[] arrayInformation = state.processIdServiceId.Split(delimiter);
                    int      processId        = Convert.ToInt32(arrayInformation[0]);
                    int      serviceId        = Convert.ToInt32(arrayInformation[1]);

                    string[] dateInformation = state.Date.Split(delimiter);
                    string   stringDate      = dateInformation[1];
                    //stringDate = stringDate.Replace("-", " ");
                    stringDate = Utilities.Util.GetDateWithOutTime(stringDate);
                    //Here I create the new date
                    string newDate = stringDate + " " + state.Hour;
                    string newDat2 = Utilities.Util.GetDateWithCorrectPositionOfTheMonth(newDate);
                    int    result  = 0;
                    try
                    {
                        result = AppoinmentService.RescheduleAppoinment(processId, newDat2, serviceId);
                    }
                    catch (Exception)
                    {
                        result = AppoinmentService.RescheduleAppoinment(processId, newDate, serviceId);
                    }
                    AppointmentGetResults _appointment = AppoinmentService.GetAppointmentById(result);
                    await context.PostAsync($"The appointment was rescheduled, Ticket: " + _appointment.QCode + _appointment.QNumber);
                }
                catch (Exception ex)
                {
                    await context.PostAsync(ex.Message.ToString());
                }
            };
            #endregion
            #region set language and create a container for form builder
            CultureInfo ci = new CultureInfo("en");
            Thread.CurrentThread.CurrentCulture   = ci;
            Thread.CurrentThread.CurrentUICulture = ci;
            var culture  = Thread.CurrentThread.CurrentUICulture;
            var form     = new FormBuilder <ReservationReschedule>();
            var yesTerms = form.Configuration.Yes.ToList();
            var noTerms  = form.Configuration.No.ToList();
            yesTerms.Add("Yes");
            noTerms.Add("No");
            form.Configuration.Yes = yesTerms.ToArray();
            return(form
                   #endregion
                   #region process and service ids
                   .Field(new FieldReflector <ReservationReschedule>(nameof(ReservationReschedule.processIdServiceId))
                          .SetType(null)
                          .SetDefine(async(state, field) =>
            {
                //Get the actual user state of the customer
                ACFCustomer customerState = new ACFCustomer();
                int customerIdState = 0;
                customerIdState = state._customerId;
                string personalIdState = string.Empty;
                //Instance of library for manage customers
                WebAppoinmentsClientLibrary.Customers customerLibrary = new WebAppoinmentsClientLibrary.Customers();
                //Instance of library for manage cases
                WebAppoinmentsClientLibrary.Cases caseLibrary = new WebAppoinmentsClientLibrary.Cases();
                //Here we will to find the customer by customer id or personal id
                Customer customer = null;
                if (!string.IsNullOrEmpty(customerIdState.ToString()))
                {
                    //Get the object ObjectCustomer and inside of this the object Customer
                    try
                    {
                        customer = customerLibrary.GetCustomer(customerIdState).Customer;
                    }
                    catch (Exception)
                    {
                        // throw; here we not send the exception beacuse we need to do the next method below
                    }
                }
                //If not found by customer id , we will try to find by personal id
                else
                {
                    int idType = 0;
                    //Get the object ObjectCustomer and inside of this the object Customer
                    try
                    {
                        customer = customerLibrary.GetCustomerByPersonalId(personalIdState, idType).Customer;
                    }
                    catch (Exception)
                    {
                        //throw;
                    }
                }
                if (customer == null)
                {
                    throw new Exception("No records found");
                }
                else
                {
                    //Declaration of Calendar Get Slots Results object
                    CalendarGetSlotsResults slotToShowInformation = new CalendarGetSlotsResults();
                    //Set the parameters for get the expected appoinments
                    int customerTypeId = 0;
                    string customerTypeName = "";
                    int customerId = customer.Id;
                    DateTime startDate = DateTime.Today;
                    //here we add ten days to the startdate
                    DateTime endDate = startDate.AddDays(10);
                    string fromDate = startDate.ToString();
                    string toDate = endDate.ToString();
                    string typeSeriaizer = "XML";
                    //Declaration of the ocject to save the result of the GetExpectedAppoinment
                    ObjectCustomerGetExpectedAppointmentsResults objectCustomerGetExpectedAppointmentsResults = new ObjectCustomerGetExpectedAppointmentsResults();
                    objectCustomerGetExpectedAppointmentsResults = customerLibrary.GetExpectedAppoinment(customerTypeId, customerTypeName, customerId, startDate, endDate, typeSeriaizer);
                    if (objectCustomerGetExpectedAppointmentsResults.ListCustomerGetExpectedAppointmentsResults.Count > 0)
                    {
                        foreach (CustomerGetExpectedAppointmentsResults listCustomer in objectCustomerGetExpectedAppointmentsResults.ListCustomerGetExpectedAppointmentsResults)
                        {
                            //At first I need to find the appoinment by appoiment id, for saw the actual status
                            Appointment appointment = appointmentLibrary.GetAppoinment(listCustomer.AppointmentId).AppointmentInformation;
                            string data = appointment.AppointmentDate.ToString();
                            string processIdAndServiceId = appointment.ProcessId + "." + appointment.ServiceId + "." + Utilities.Util.GetDateWithOutTime(data);
                            field
                            .AddDescription(processIdAndServiceId, data + " | " + listCustomer.ServiceName)              //here we put the process id and the date of the appointment of this process
                            .AddTerms(processIdAndServiceId, data + " | " + listCustomer.ServiceName);
                        }
                        return await Task.FromResult(true);
                    }
                    else
                    {
                        throw new Exception("No records found");
                    }
                }
            }))
                   #endregion
                   #region Date
                   .Field(new FieldReflector <ReservationReschedule>(nameof(ReservationReschedule.Date))
                          .SetType(null)
                          .SetDefine(async(state, field) =>
            {
                List <OTempus.Library.Class.Calendar> listCalendars;
                StringBuilder response = new StringBuilder();
                List <CalendarGetSlotsResults> listGetAvailablesSlots = new List <CalendarGetSlotsResults>();
                if (!String.IsNullOrEmpty(state.processIdServiceId))
                {
                    Char delimiter = '.';
                    string[] arrayInformation = state.processIdServiceId.Split(delimiter);
                    int processId = Convert.ToInt32(arrayInformation[0]);
                    int serviceId = Convert.ToInt32(arrayInformation[1]);
                    string currentAppoinmentDate = arrayInformation[2];
                    DateTime dateFromString = DateTime.Parse(currentAppoinmentDate, System.Globalization.CultureInfo.CurrentCulture);
                    try
                    {
                        listCalendars = new List <OTempus.Library.Class.Calendar>();

                        listCalendars = GetCalendar(serviceId.ToString(), dateFromString);

                        if (listCalendars.Count == 0)
                        {
                            throw new Exception("No records found");
                        }
                        else
                        {
                            foreach (var calendar in listCalendars)
                            {
                                string data = calendar.Id + "." + calendar.CalendarDate.ToString();
                                string data1 = Utilities.Util.GetDateWithOutTime(calendar.CalendarDate.ToString());//we see this in form flow
                                field
                                .AddDescription(data, data1)
                                .AddTerms(data, data1);
                            }
                            return await Task.FromResult(true);
                        } //End else
                    }     //End try
                    catch (Exception e) { }
                }
                return await Task.FromResult(true);
            }))
                   #endregion
                   #region Period day
                   .Field(nameof(ReservationReschedule.dayPeriod))
                   #endregion
                   #region hour
                   .Field(new FieldReflector <ReservationReschedule>(nameof(ReservationReschedule.Hour))
                          .SetType(null)
                          .SetDefine(async(state, value) =>
            {
                string date;
                List <OTempus.Library.Class.Calendar> listCalendars;
                List <CalendarSlot> listGetAvailablesSlots;
                if (!String.IsNullOrEmpty(state.Date) && !String.IsNullOrEmpty(state.dayPeriod.ToString()) && !String.IsNullOrEmpty(state.processIdServiceId))
                {
                    Char delimiter = '.';
                    string[] arrayInformation = state.processIdServiceId.Split(delimiter);
                    int processId = Convert.ToInt32(arrayInformation[0]);
                    int serviceId = Convert.ToInt32(arrayInformation[1]);
                    string currentAppoinmentDate = arrayInformation[2];
                    DateTime dateFromString = DateTime.Parse(currentAppoinmentDate, System.Globalization.CultureInfo.CurrentCulture);


                    int periodDay = Convert.ToInt32(Utilities.Util.GetIntPeriodDay(state.dayPeriod.ToString()));
                    string calendarId = Utilities.Util.GetCalendarIdFromBotOption(state.Date);
                    try
                    {
                        listCalendars = new List <OTempus.Library.Class.Calendar>();
                        date = state.Date;
                        listCalendars = GetCalendar(serviceId.ToString(), dateFromString);
                        listGetAvailablesSlots = new List <CalendarSlot>();

                        StringBuilder response = new StringBuilder();
                        response.Append("Not exists slots").ToString();
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("Here are the error: " + ex.Message);
                    }
                    date = state.Date.ToString();
                    if (listCalendars.Count > 0)
                    {
                        listGetAvailablesSlots = AppoinmentService.GetSlotsByPeriod(Convert.ToInt32(calendarId), periodDay.ToString(), 0.ToString());
                        if (listGetAvailablesSlots.Count > 0)
                        {
                            int cont = 0;
                            foreach (OTempus.Library.Class.CalendarSlot calendarSlots in listGetAvailablesSlots)
                            {
                                if (calendarSlots.Status.ToString() == "Vacant")
                                {
                                    string data = calendarSlots.StartTime.ToString();
                                    DateTime date1 = DateTime.Today;
                                    date1 = date1.AddMinutes(calendarSlots.StartTime);
                                    string data1 = date1.ToShortTimeString();
                                    //string data1 = string.Format("{0:hh:mm-tt}", date1);
                                    //assign the calendar id
                                    value
                                    .AddDescription(data1, data1)
                                    .AddTerms(data1, data1);
                                    cont++;
                                }
                            }
                            return await Task.FromResult(true);
                        }
                        else
                        {
                            throw new Exception("No records found");
                        }
                    }
                    else
                    {
                        throw new Exception("No records found");
                    }
                }
                return await Task.FromResult(false);
            }))
                   .Field(new FieldReflector <ReservationReschedule>(nameof(ReservationReschedule._customerId)).SetActive(InactiveField))

                   #endregion
                   .OnCompletion(processOrder)
                   .Build());
        }
コード例 #4
0
        /// <summary>
        /// Creation of the IForm(Form flow for cancel an appointment)
        /// </summary>
        /// <returns></returns>
        public static IForm <CancelForm> BuildForm()
        {
            OnCompletionAsyncDelegate <CancelForm> processOrder = async(context, state) =>
            {
                //Get the actual user state of the customer
                ACFCustomer customerState = new ACFCustomer();
                try
                {
                    if (!context.UserData.TryGetValue <ACFCustomer>("customerState", out customerState))
                    {
                        customerState = new ACFCustomer();
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception("Not exists a user session");
                }
                int customerIdState = 0;
                customerIdState = customerState.CustomerId;
                string personalIdState = string.Empty;
                personalIdState = customerState.PersonaId;

                //Instance of library for manage customers
                WebAppoinmentsClientLibrary.Customers customerLibrary = new WebAppoinmentsClientLibrary.Customers();
                //Instance of library for manage appoinments
                WebAppoinmentsClientLibrary.Appoinments appointmentLibrary = new WebAppoinmentsClientLibrary.Appoinments();
                //Instance of library for manage cases
                WebAppoinmentsClientLibrary.Cases caseLibrary = new WebAppoinmentsClientLibrary.Cases();
                //Here we will to find the customer by customer id or personal id
                Customer customer = null;
                if (!String.IsNullOrEmpty(customerIdState.ToString()))
                {
                    //Get the object ObjectCustomer and inside of this the object Customer
                    try
                    {
                        customer = customerLibrary.GetCustomer(customerIdState).Customer;
                    }
                    catch (Exception)
                    {
                        // throw; here we not send the exception beacuse we need to do the next method below
                    }
                }
                //If not found by customer id , we will try to find by personal id
                else
                {
                    int idType = 0;
                    //GEt the object ObjectCustomer and inside of this the object Customer
                    try
                    {
                        customer = customerLibrary.GetCustomerByPersonalId(personalIdState, idType).Customer;
                    }
                    catch (Exception)
                    {
                        //throw;
                    }
                }

                if (customer == null)
                {
                    await context.PostAsync($"The user is not valid");
                }
                else
                {
                    //Declaration of Calendar Get Slots Results oobject
                    CalendarGetSlotsResults slotToShowInformation = new CalendarGetSlotsResults();
                    //Set the parameters for get the expected appoinments
                    int    customerTypeId   = 0;
                    string customerTypeName = "";
                    int    customerId       = customer.Id;
                    //This variables are in hard code because...
                    string fromDate = "09/21/2017 ";
                    string toDate   = "10/21/2018 ";

                    //DateTime fromDate = DateTime.Today;
                    //DateTime toDate = DateTime.Today.AddDays(5);
                    string typeSeriaizer = "XML";
                    //get the appoinment id fore filter in the below results
                    int appoinmentId = state.appoinmentId;

                    //At first I need to find the appoinment by appoiment id, for saw the actual status
                    Appointment appoinment = appointmentLibrary.GetAppoinment(appoinmentId).AppointmentInformation;

                    //Get the case for get the status of the appoinment (check for more information QFlow documentation)
                    // Case cases= caseLibrary.GetCase(customerId).CaseList;
                    //cases.
                    //Declare the object for keept the value of the appoinment find it
                    CustomerGetExpectedAppointmentsResults customerGetExpectedAppointmentsResults = new CustomerGetExpectedAppointmentsResults();
                    //Declaration of the ocject to save the result of the GetExpectedAppoinment
                    ObjectCustomerGetExpectedAppointmentsResults objectCustomerGetExpectedAppointmentsResults = new ObjectCustomerGetExpectedAppointmentsResults();
                    objectCustomerGetExpectedAppointmentsResults = customerLibrary.GetExpectedAppoinment(customerTypeId, customerTypeName, customerId, fromDate, toDate, typeSeriaizer);
                    foreach (CustomerGetExpectedAppointmentsResults listCustomer in objectCustomerGetExpectedAppointmentsResults.ListCustomerGetExpectedAppointmentsResults)
                    {
                        if (listCustomer.AppointmentId.Equals(appoinmentId))
                        {
                            customerGetExpectedAppointmentsResults.CaseId              = listCustomer.CaseId;
                            customerGetExpectedAppointmentsResults.ProcessId           = listCustomer.ProcessId;
                            customerGetExpectedAppointmentsResults.ServiceId           = listCustomer.ServiceId;
                            customerGetExpectedAppointmentsResults.AppointmentTypeId   = listCustomer.AppointmentTypeId;
                            customerGetExpectedAppointmentsResults.AppointmentTypeName = listCustomer.AppointmentTypeName;
                        }
                        //Maybe we not found the appoiment that we want, because when pass a short time, a job of sql is in charge to change the status of the appoinments
                        //it means , by default the state is in expected but when pass determinate time, it can change to absent for example
                        //So the recomendation is find the appointment by id and administrate the error
                    }

                    //Then when we have our object , we can cancel the appoinment because we have his process id

                    if (customerGetExpectedAppointmentsResults.ProcessId > 0)
                    {
                        appointmentLibrary.CancelAppoinment(customerGetExpectedAppointmentsResults.ProcessId,
                                                            0, 0, 0, "notes", false, 0, 0
                                                            );
                    }
                    // in other hand we can't find the record, so we will send the appropiate message
                    else
                    {
                        await context.PostAsync($"I don't found a record with appoinment Id: \n*" + state.appoinmentId);
                    }
                }
            };
            CultureInfo ci = new CultureInfo("en");

            Thread.CurrentThread.CurrentCulture   = ci;
            Thread.CurrentThread.CurrentUICulture = ci;
            var culture  = Thread.CurrentThread.CurrentUICulture;
            var form     = new FormBuilder <CancelForm>();
            var yesTerms = form.Configuration.Yes.ToList();
            var noTerms  = form.Configuration.No.ToList();

            yesTerms.Add("Yes");
            noTerms.Add("No");
            form.Configuration.Yes = yesTerms.ToArray();

            return(form.Message("Fill the information for cancel the appoinment, please")
                   .Field(nameof(appoinmentId))
                   .Confirm("Are you selected:  " +
                            "\n* appoinmentId: {appoinmentId}: ? \n" +
                            "(yes/no)")
                   .AddRemainingFields()
                   .Message("The process for cancel the appoinment has been started!")
                   .OnCompletion(processOrder)
                   .Build());
        }
コード例 #5
0
        public static IForm <ReservationStatus> BuildForm()
        {
            //Instance of library for manage appoinments
            WebAppoinmentsClientLibrary.Appoinments       appointmentLibrary = new WebAppoinmentsClientLibrary.Appoinments();
            OnCompletionAsyncDelegate <ReservationStatus> processOrder       = async(context, state) =>
            {
                //Get the appoinment by appoinment id
                AppointmentGetResults _appointment = AppoinmentService.GetAppointmentById(Convert.ToInt32(state.appointmentId));

                if (_appointment != null)
                {
                    await context.PostAsync($"Appointment Details:" +
                                            " \n* Ticket: " + _appointment.QCode + _appointment.QNumber +
                                            " \n* Service name: " + _appointment.ServiceName +
                                            " \n* Appointment date: " + _appointment.AppointmentDate

                                            );
                }
                // in other hand we can't find the record, so we will send the appropiate message
                else
                {
                    await context.PostAsync($"I don't found record with the appointment id: \n* " + state.appointmentId);
                }
            };
            CultureInfo ci = new CultureInfo("en");

            Thread.CurrentThread.CurrentCulture   = ci;
            Thread.CurrentThread.CurrentUICulture = ci;
            var culture  = Thread.CurrentThread.CurrentUICulture;
            var form     = new FormBuilder <ReservationStatus>();
            var yesTerms = form.Configuration.Yes.ToList();
            var noTerms  = form.Configuration.No.ToList();

            yesTerms.Add("Yes");
            noTerms.Add("No");
            form.Configuration.Yes = yesTerms.ToArray();
            return(form
                   .Field(new FieldReflector <ReservationStatus>(nameof(ReservationStatus.appointmentId))
                          .SetType(null)
                          .SetDefine(async(state, field) =>
            {
                //Get the actual user state of the customer
                ACFCustomer customerState = new ACFCustomer();

                int customerIdState = 0;
                //customerIdState = customerState.CustomerId;
                customerIdState = state._customerId;

                string personalIdState = string.Empty;
                //Instance of library for manage customers
                WebAppoinmentsClientLibrary.Customers customerLibrary = new WebAppoinmentsClientLibrary.Customers();

                //Instance of library for manage cases
                WebAppoinmentsClientLibrary.Cases caseLibrary = new WebAppoinmentsClientLibrary.Cases();
                //Here we will to find the customer by customer id or personal id
                Customer customer = null;
                if (!string.IsNullOrEmpty(customerIdState.ToString()))
                {
                    //Get the object ObjectCustomer and inside of this the object Customer
                    try
                    {
                        customer = customerLibrary.GetCustomer(customerIdState).Customer;
                    }
                    catch (Exception)
                    {
                        // throw; here we not send the exception beacuse we need to do the next method below
                    }
                }
                //If not found by customer id , we will try to find by personal id
                else
                {
                    int idType = 0;
                    //Get the object ObjectCustomer and inside of this the object Customer
                    try
                    {
                        customer = customerLibrary.GetCustomerByPersonalId(personalIdState, idType).Customer;
                    }
                    catch (Exception)
                    {
                        //throw;
                    }
                }

                if (customer == null)
                {
                    throw new Exception("No records found");
                }
                else
                {
                    //Declaration of Calendar Get Slots Results object
                    CalendarGetSlotsResults slotToShowInformation = new CalendarGetSlotsResults();
                    //Set the parameters for get the expected appoinments
                    int customerTypeId = 0;
                    string customerTypeName = "";
                    int customerId = customer.Id;
                    DateTime startDate = DateTime.Today;
                    //here we add ten days to the startdate
                    DateTime endDate = startDate.AddDays(10);
                    string fromDate = startDate.ToString();
                    string toDate = endDate.ToString();
                    string typeSeriaizer = "XML";

                    //Declaration of the ocject to save the result of the GetExpectedAppoinment
                    ObjectCustomerGetExpectedAppointmentsResults objectCustomerGetExpectedAppointmentsResults = new ObjectCustomerGetExpectedAppointmentsResults();
                    objectCustomerGetExpectedAppointmentsResults = customerLibrary.GetExpectedAppoinment(customerTypeId, customerTypeName, customerId, startDate, endDate, typeSeriaizer);
                    if (objectCustomerGetExpectedAppointmentsResults.ListCustomerGetExpectedAppointmentsResults.Count > 0)
                    {
                        foreach (CustomerGetExpectedAppointmentsResults listCustomer in objectCustomerGetExpectedAppointmentsResults.ListCustomerGetExpectedAppointmentsResults)
                        {
                            //At first I need to find the appoinment by appoiment id, for saw the actual status
                            Appointment appointment = appointmentLibrary.GetAppoinment(listCustomer.AppointmentId).AppointmentInformation;
                            //string data = appointment.AppointmentDate.ToString();
                            string data = string.Format("{0:dd/MM/yyyy-hh:mmtt}", appointment.AppointmentDate);

                            field
                            .AddDescription(listCustomer.AppointmentId.ToString(), data + "|" + listCustomer.ServiceName)                  //here we put the process id and the date of the appointment of this process
                            .AddTerms(listCustomer.AppointmentId.ToString(), data + "|" + listCustomer.ServiceName);
                        }
                        return await Task.FromResult(true);
                    }
                    else
                    {
                        await ReservationCancel.context.PostAsync($"No records found");
                        throw new Exception("No records found");
                    }
                }
            }))
                   .Field(new FieldReflector <ReservationStatus>(nameof(ReservationStatus._customerId)).SetActive(InactiveField))
                   .AddRemainingFields()
                   .OnCompletion(processOrder)
                   .Build());
        }
コード例 #6
0
        public static IForm <StatusFormApp> BuildForm()
        {
            OnCompletionAsyncDelegate <StatusFormApp> processOrder = async(context, state) =>
            {
                //Get the actual user state of the customer
                ACFCustomer customerState = new ACFCustomer();
                try
                {
                    if (!context.UserData.TryGetValue <ACFCustomer>("customerState", out customerState))
                    {
                        customerState = new ACFCustomer();
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception("Not exists a user session");
                }
                //Instance of library for manage customers
                WebAppoinmentsClientLibrary.Customers customerLibrary = new WebAppoinmentsClientLibrary.Customers();
                //Instance of library for manage appoinments
                WebAppoinmentsClientLibrary.Appoinments appointmentLibrary = new WebAppoinmentsClientLibrary.Appoinments();
                //Instance of library for manage cases
                WebAppoinmentsClientLibrary.Cases caseLibrary = new WebAppoinmentsClientLibrary.Cases();
                //Here we will to find the customer by customer id or personal id
                Customer customer = null;
                if (!String.IsNullOrEmpty(customerState.CustomerId.ToString()))
                {
                    //Get the object ObjectCustomer and inside of this the object Customer
                    try
                    {
                        customer = customerLibrary.GetCustomer(customerState.CustomerId).Customer;
                    }
                    catch (Exception)
                    {
                        // throw; here we not send the exception beacuse we need to do the next method below
                    }
                }
                //If not found by customer id , we will try to find by personal id
                if (customer.Id <= 0)
                {
                    int idType = 0;
                    //GEt the object ObjectCustomer and inside of this the object Customer
                    try
                    {
                        customer = customerLibrary.GetCustomerByPersonalId(customerState.PersonaId, idType).Customer;
                    }
                    catch (Exception)
                    {
                        //throw;
                    }
                }

                if (customer == null)
                {
                    await context.PostAsync($"The user is not valid");
                }
                else
                {
                    int customerId = customer.Id;

                    //get the appoinment id for filter in the below results
                    int appoinmentId = state.appoinmentId;


                    //Get a list of cases by customer id (no trae resultados)
                    List <Case>        listCases = caseLibrary.GetCase(customerId).CaseList;
                    CaseCustomerResult cd        = new CaseCustomerResult();

                    //Get the appoinment by appoinment id
                    AppointmentGetResults _appoinment = AppoinmentService.GetAppointmentById(appoinmentId);

                    //Declare a case for save the specific case that we search
                    Case caseForSaveResult = new Case();

                    string test = caseForSaveResult.OTUnitName;

                    if (_appoinment.ProcessId > 0)
                    {
                        await context.PostAsync($"The appointment have the next information " +
                                                " \n* Process Id: " + _appoinment.ProcessId +
                                                " \n* Appointment date: " + _appoinment.AppointmentDate +
                                                " \n* Q-Code: " + _appoinment.QCode +
                                                " \n* Q-Number: " + _appoinment.QNumber +
                                                //" \n* Arrival date: " + _appoinment.ArrivalDate +
                                                " \n* Customer Id: " + _appoinment.CustomerId +
                                                // " \n* Date called: " + _appoinment.DateCalled +
                                                // " \n* Name: " + _appoinment.Name +
                                                " \n* Case Id: " + _appoinment.CaseId +
                                                //  " \n* Is Walkin: " + _appoinment.IsWalkIn +
                                                " \n* Is Active: " + _appoinment.IsActive +
                                                " \n* Service Name: " + _appoinment.ServiceName
                                                // " \n* Cancelreason name: " + _appoinment.CancelationReasonName
                                                );
                    }
                    // in other hand we can't find the record, so we will send the appropiate message
                    else
                    {
                        await context.PostAsync($"I don't found record with the appointment id: \n*" + state.appoinmentId);
                    }
                }
            };
            CultureInfo ci = new CultureInfo("en");

            Thread.CurrentThread.CurrentCulture   = ci;
            Thread.CurrentThread.CurrentUICulture = ci;
            var culture  = Thread.CurrentThread.CurrentUICulture;
            var form     = new FormBuilder <StatusFormApp>();
            var yesTerms = form.Configuration.Yes.ToList();
            var noTerms  = form.Configuration.No.ToList();

            yesTerms.Add("Yes");
            noTerms.Add("No");
            form.Configuration.Yes = yesTerms.ToArray();
            return(form.Message("Fill the information for search the appointment, please")
                   .Field(nameof(appoinmentId))
                   .Confirm("Are you selected the appointment id: {appoinmentId}: ? (yes/no)")
                   .AddRemainingFields()
                   .OnCompletion(processOrder)
                   .Build());
        }
コード例 #7
0
ファイル: RootDialog.cs プロジェクト: crowster/barcbot
        //This method will be executed after select one of the option of book,cancel,get status, or reschedule an appointment
        private async Task OnOptionSelected(IDialogContext context, IAwaitable <string> result)
        {
            try
            {
                // ACFCustomer customerState2 = new ACFCustomer();
                //if (!context.PrivateConversationData.TryGetValue<ACFCustomer>("customerState", out customerState2)) { customerState2 = new ACFCustomer(); }
                //int testCustomerStateId = customerState2.CustomerId;
                string optionSelected = await result;

                switch (optionSelected)
                {
                case BookOption:
                    BookFormApp.context = context;
                    var bookFormDialog = FormDialog.FromForm(BookFormApp.BuildForm, FormOptions.PromptInStart);
                    context.Call(bookFormDialog, ResumeAfterBookDialog);

                    /*BookFormApp.context = context;
                     * var bookFormDialog = FormDialog.FromForm(BookFormApp.BuildForm, FormOptions.PromptInStart);
                     * context.Call(bookFormDialog, ResumeAfterBookDialog);*/
                    break;

                case RescheduleOption:
                    //RescheduleFormApp.context = context;
                    //var rescheduleFormDialog = FormDialog.FromForm(RescheduleFormApp.BuildForm, FormOptions.PromptInStart);
                    //context.Call(rescheduleFormDialog, ResumeAfterRescheduleDialog);

                    /*RescheduleFormAppThree.context = context;
                     * var rescheduleFormDialog = FormDialog.FromForm(RescheduleFormAppThree.BuildForm, FormOptions.PromptInStart);
                     * context.Call(rescheduleFormDialog, ResumeAfterRescheduleDialog);*/
                    ACFCustomer customerState3 = new ACFCustomer();
                    if (!context.UserData.TryGetValue <ACFCustomer>("customerState", out customerState3))
                    {
                        customerState3 = new ACFCustomer();
                    }

                    var form3 = new FormDialog <ReservationReschedule>(
                        new ReservationReschedule(customerState3.CustomerId),
                        RescheduledFormAppReservation.BuildForm,
                        FormOptions.PromptInStart
                        //,null//,result.Entities}
                        );
                    context.Call(form3, ResumeAfterRescheduleDialog);

                    break;

                case CancelOption:
                    // CancelForm.context = context;
                    //var cancelFormDialog = FormDialog.FromForm(CancelForm.BuildForm, FormOptions.PromptInStart);
                    //context.Call(cancelFormDialog, ResumeAfterCancelDialog);

                    /* CancelFormApp.context = context;
                     * var cancelFormDialog = FormDialog.FromForm(CancelFormApp.BuildForm, FormOptions.PromptInStart);
                     * context.Call(cancelFormDialog, ResumeAfterCancelDialog);*/
                    ACFCustomer customerState = new ACFCustomer();
                    if (!context.UserData.TryGetValue <ACFCustomer>("customerState", out customerState))
                    {
                        customerState = new ACFCustomer();
                    }

                    var form = new FormDialog <ReservationCancel>(
                        new ReservationCancel(customerState.CustomerId),
                        CancelFormAppReservation.BuildForm,
                        FormOptions.PromptInStart
                        //,null//,result.Entities}
                        );
                    context.Call(form, ResumeAfterCancelDialog);
                    break;

                case StatusOption:
                    /*StatusForm.context = context;
                     * var statusFormDialog = FormDialog.FromForm(StatusFormApp.BuildForm, FormOptions.PromptInStart);
                     * context.Call(statusFormDialog, ResumeAfterStatusDialog*/
                    /*StatusFormAppTwo.context = context;
                     * var statusFormDialog = FormDialog.FromForm(StatusFormAppTwo.BuildForm, FormOptions.PromptInStart);
                     * context.Call(statusFormDialog, ResumeAfterStatusDialog);*/
                    ACFCustomer customerState2 = new ACFCustomer();
                    if (!context.UserData.TryGetValue <ACFCustomer>("customerState", out customerState2))
                    {
                        customerState2 = new ACFCustomer();
                    }

                    var form2 = new FormDialog <ReservationStatus>(
                        new ReservationStatus(customerState2.CustomerId),
                        StatusFormAppReservation.BuildForm,
                        FormOptions.PromptInStart
                        //,null//,result.Entities}
                        );
                    context.Call(form2, ResumeAfterStatusDialog);

                    break;

                case SaveCustomerOption:
                    SaveCustomerFormApp.context = context;
                    var saveCustomerFormDialog = FormDialog.FromForm(SaveCustomerFormApp.BuildForm, FormOptions.PromptInStart);
                    context.Call(saveCustomerFormDialog, ResumeAfterSaveCustomerDialog);
                    break;

                case MainMenu:
                    //context.Wait.StartAsync(context);
                    bool creatingUser = true;
                    context.UserData.SetValue <bool>("creatingUser", creatingUser);
                    await StartAsync(context);

                    break;

                case LogOut:
                    //context.PrivateConversationData.SetValue<ACFCustomer>("customerState", customerState);
                    context.Done(string.Empty);
                    break;
                }
            }
            catch (TooManyAttemptsException ex)
            {
                await context.PostAsync($"Ooops! Too many attemps :(. But don't worry, I'm handling that exception and you can try again!");

                //context.Done(string.Empty);
                await StartAsync(context);
            }
        }
コード例 #8
0
        /// <summary>
        /// This method create IForm for save the customer information
        /// </summary>
        /// <returns></returns>
        public static IForm <SaveCustomerForm> BuildForm()
        {
            OnCompletionAsyncDelegate <SaveCustomerForm> processOrder = async(context, state) =>
            {
                ACFCustomer customer = new ACFCustomer();
                try
                {
                    customer.CustomerId  = 0;//It is setted to 0, beacuse we will create new user, in other hand we can pass the id for update the record
                    customer.FirstName   = state.FirstName;
                    customer.LastName    = state.LastName;
                    customer.Email       = state.Email;
                    customer.PhoneNumber = state.PhoneNumber;
                    customer.Sex         = GetIntSex(state.Sex.ToString());
                    int customerId = AppoinmentService.SaveCustomer(customer.PhoneNumber, customer.Email, customer.FirstName,
                                                                    customer.LastName, customer.Sex, customer.PhoneNumber, customer.CustomerId);
                    state.customerId = customerId.ToString();
                    if (customerId > 0)
                    {
                        FRService frService = new FRService();
                        //Get the idImage Saved
                        int idImageSaved = 0;
                        if (!context.UserData.TryGetValue <int>("idImageSaveId", out idImageSaved))
                        {
                            idImageSaved = 0;
                        }

                        //Set the FaceRecognition Model,
                        FaceRecognitionModel faceRecognitionModel = new FaceRecognitionModel();
                        faceRecognitionModel.ObjectId = Utilities.Util.generateObjectId(customer.FirstName, customer.LastName, customer.PhoneNumber);
                        faceRecognitionModel.PhotoId  = savedImageId.ToString();
                        faceRecognitionModel.Name     = imageName;
                        faceRecognitionModel.FileName = imageName;
                        context.UserData.SetValue <FaceRecognitionModel>("FaceRecognitionModel", faceRecognitionModel);

                        bool uploadImage = await frService.uploadImage(customer.FirstName, customer.LastName, customer.PhoneNumber
                                                                       , imageName, savedImageId);

                        await context.PostAsync("Your user has been saved succesfully with the id: " + customerId);

                        /* Create the userstate */
                        //Instance of the object ACFCustomer for keept the customer
                        ACFCustomer customerState = new ACFCustomer();
                        customerState.CustomerId  = customerId;
                        customerState.FirstName   = customer.FirstName;
                        customerState.PhoneNumber = customer.PhoneNumber;
                        customerState.Sex         = Convert.ToInt32(customer.Sex);
                        customerState.PersonaId   = customer.PhoneNumber;
                        context.UserData.SetValue <ACFCustomer>("customerState", customerState);
                        context.UserData.SetValue <bool>("SignIn", true);
                    }
                }
                catch (Exception ex)
                {
                    await context.PostAsync("We have an error: " + ex.Message);
                }
            };
            CultureInfo ci = new CultureInfo("en");

            Thread.CurrentThread.CurrentCulture   = ci;
            Thread.CurrentThread.CurrentUICulture = ci;
            var culture  = Thread.CurrentThread.CurrentUICulture;
            var form     = new FormBuilder <SaveCustomerForm>();
            var yesTerms = form.Configuration.Yes.ToList();
            var noTerms  = form.Configuration.No.ToList();

            yesTerms.Add("Yes");
            noTerms.Add("No");
            form.Configuration.Yes = yesTerms.ToArray();
            return(form.Message("Fill the next information, please")
                   .Field(nameof(FirstName))
                   .Field(nameof(LastName))
                   .Field(nameof(Email))
                   .Field(nameof(PhoneNumber))
                   .Field(nameof(Sex))
                   .Field(new FieldReflector <SaveCustomerForm>(nameof(customerId)).SetActive(inActiveField))
                   .Confirm("Are you selected the information: " +
                            "\n* Name: {FirstName} " +
                            "\n* Last name:  {LastName} " +
                            "\n* Email:  {Email} " +
                            "\n* Phone Number: {PhoneNumber} " +
                            "\n* Sex:  {Sex}? \n" +
                            "(yes/no)")
                   .AddRemainingFields()
                   .Message("The process for save your user has been started!")
                   .OnCompletion(processOrder)
                   .Build());
        }
コード例 #9
0
        public static IForm <EnqueueForm> BuildForm()
        {
            OnCompletionAsyncDelegate <EnqueueForm> processOrder = async(context, state) =>
            {
                //Get the actual state of the FaceRecognitionModel , for then get the object id, photoId, name and file name
                FaceRecognitionModel faceRecognitionState = new FaceRecognitionModel();
                AppoinmentService    appointmentService   = new AppoinmentService();
                try
                {
                    if (!context.UserData.TryGetValue <FaceRecognitionModel>("FaceRecognitionModel", out faceRecognitionState))
                    {
                        faceRecognitionState = new FaceRecognitionModel();
                    }
                    FRService frService = new FRService();
                    int       caseId    = await frService.enqueueCustomer(faceRecognitionState.ObjectId, faceRecognitionState.PhotoId, faceRecognitionState.Name, faceRecognitionState.FileName);

                    //Get the actual user state of the customer
                    ACFCustomer customerState = new ACFCustomer();
                    try
                    {
                        if (!context.UserData.TryGetValue <ACFCustomer>("customerState", out customerState))
                        {
                            customerState = new ACFCustomer();
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("Not exists a user session");
                    }
                    //In this case I have the case, that has been enqueue, but the middleware don´thave a method for get by case id,
                    //but have yes a method for get a list of cases of customer id
                    if (caseId > 0)
                    {
                        Case _case = AppoinmentService.GetCaseById(customerState.CustomerId);
                        await context.PostAsync($"Hey!... " + customerState.FirstName + " " + customerState.LastName + " , your case has been enqueue satisfactory with the ticket " +
                                                //" \n* Process Id: " + _case.ProcessId  +
                                                //" \n* Q-Code: " + _case.QCode  +
                                                //" \n* Q-Number: " + _case.QNumber +
                                                //" \n* Status: " + _case.Status
                                                " \n* " + _case.QCode + _case.QNumber
                                                );
                    }
                    else
                    {
                        throw new Exception("Error: The case Id = 0");
                    }
                }
                catch (Exception ex)
                {
                    await context.PostAsync($"Failed with message: {ex.Message}");
                }
            };
            CultureInfo ci = new CultureInfo("en");

            Thread.CurrentThread.CurrentCulture   = ci;
            Thread.CurrentThread.CurrentUICulture = ci;
            FormBuilder <EnqueueForm> form = new FormBuilder <EnqueueForm>();

            return(form.Message("Wait a moment please")
                   .Field(new FieldReflector <EnqueueForm>(nameof(UserId)).SetActive(InactiveField))
                   .AddRemainingFields()
                   .Message("The process for enqueue the case has been started!")
                   .OnCompletion(processOrder)
                   .Build());
        }
コード例 #10
0
        /// <summary>
        /// This method create IForm for save the customer information
        /// </summary>
        /// <returns></returns>
        public static IForm <SaveCustomerFormApp> BuildForm()
        {
            OnCompletionAsyncDelegate <SaveCustomerFormApp> processOrder = async(context, state) =>
            {
                ACFCustomer customer = new ACFCustomer();
                try
                {
                    customer.CustomerId = 0;//It is setted to 0, beacuse we will create new user, in other hand we can pass the id for update the record

                    if (!string.IsNullOrEmpty(state.name) && !string.IsNullOrEmpty(state.LastName))
                    {
                        try
                        {
                            customer.FirstName = state.name;
                            customer.LastName  = state.LastName;
                        }
                        catch (Exception)
                        {
                        }
                    }
                    customer.PhoneNumber = state.PhoneNumber;
                    int customerId = AppoinmentService.SaveCustomer(customer.PhoneNumber, customer.FirstName,
                                                                    customer.LastName, customer.PhoneNumber, customer.CustomerId);
                    state.customerId = customerId.ToString();
                    if (customerId > 0)
                    {
                        FRService frService = new FRService();
                        //Get the idImage Saved
                        int idImageSaved = 0;
                        if (!context.UserData.TryGetValue <int>("idImageSaveId", out idImageSaved))
                        {
                            idImageSaved = 0;
                        }
                        //Set the FaceRecognition Model,
                        FaceRecognitionModel faceRecognitionModel = new FaceRecognitionModel();
                        faceRecognitionModel.ObjectId = Utilities.Util.generateObjectId(customer.FirstName, customer.LastName, customer.PhoneNumber);
                        faceRecognitionModel.PhotoId  = idImageSaved.ToString();
                        faceRecognitionModel.Name     = imageName;
                        faceRecognitionModel.FileName = imageName;
                        context.UserData.SetValue <FaceRecognitionModel>("FaceRecognitionModel", faceRecognitionModel);
                        bool uploadImage = await frService.uploadImage(customer.FirstName, customer.LastName, customer.PhoneNumber
                                                                       , imageName, idImageSaved);

                        await context.PostAsync("Congratulations, your account was created!");

                        /* Create the userstate */
                        //Instance of the object ACFCustomer for keept the customer
                        ACFCustomer customerState = new ACFCustomer();
                        customerState.CustomerId  = customerId;
                        customerState.FirstName   = customer.FirstName;
                        customerState.PhoneNumber = customer.PhoneNumber;
                        customerState.PersonaId   = customer.PhoneNumber;
                        context.UserData.SetValue <ACFCustomer>("customerState", customerState);
                        context.UserData.SetValue <bool>("SignIn", true);
                    }
                }
                catch (Exception ex)
                {
                    await context.PostAsync("We have an error: " + ex.Message);
                }
            };
            CultureInfo ci = new CultureInfo("en");

            Thread.CurrentThread.CurrentCulture   = ci;
            Thread.CurrentThread.CurrentUICulture = ci;
            var culture  = Thread.CurrentThread.CurrentUICulture;
            var form     = new FormBuilder <SaveCustomerFormApp>();
            var yesTerms = form.Configuration.Yes.ToList();
            var noTerms  = form.Configuration.No.ToList();

            yesTerms.Add("Yes");
            noTerms.Add("No");
            form.Configuration.Yes = yesTerms.ToArray();
            return(form//.Message("Fill the next information, please")
                   .Field(nameof(name))
                   .Field(nameof(LastName))
                   .Field(nameof(PhoneNumber), validate: async(state, response) =>
            {
                //This source code appear in warning beacuse not have a method async implemented, but works good without these method
                Regex rgx = new Regex(@"^[1-9][0-9]{7,14}$");
                //Regex rgx = new Regex(@"^(\+44\s?7\d{3}|\(?07\d{3}\)?)\s?\d{3}\s?\d{3}$");
                var result = new ValidateResult {
                    IsValid = true, Value = response
                };
                if (!string.IsNullOrEmpty(result.Value.ToString()))
                {
                    if (rgx.IsMatch(result.Value.ToString()))
                    {
                        result.IsValid = true;
                    }
                    else
                    {
                        result.Feedback = "Invalid phone number format";
                        result.IsValid = false;
                    }
                }
                return result;
            })
                   .Field(new FieldReflector <SaveCustomerFormApp>(nameof(customerId)).SetActive(inActiveField))
                   .AddRemainingFields()
                   .OnCompletion(processOrder)
                   .Build());
        }
コード例 #11
0
ファイル: BookFormApp.cs プロジェクト: crowster/barcbot
        /// <summary>
        /// Create a IForm(Form flow) based in BookFormApp object
        /// </summary>
        /// <returns></returns>
        ///
        public static IForm <BookFormApp> BuildForm()
        {
            #region processOrder
            OnCompletionAsyncDelegate <BookFormApp> processOrder = async(context, state) =>
            {
                //Get the actual user state of the customer
                ACFCustomer customerState = new ACFCustomer();
                try
                {
                    if (!context.UserData.TryGetValue <ACFCustomer>("customerState", out customerState))
                    {
                        customerState = new ACFCustomer();
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception("Not exists a user session");
                }
                try
                {
                    ResultObjectBase resultObjectBase = new ResultObjectBase();
                    int serviceID = 0;
                    int unitId    = 0;
                    unitId = Utilities.Util.GetUnitIdFromBotOption(state.Office);
                    string ordinalNumber = state.Hour.ToString();

                    try
                    {
                        List <Service> listService = AppoinmentService.listServicesByName(state.Service, 1, "en", false, unitId);
                        serviceID = listService[0].Id;
                    }
                    catch (Exception)
                    {
                        throw new Exception("I don't found appointments with the service: " + state.Service);
                    }

                    try
                    {
                        resultObjectBase = AppoinmentService.SetAppoinment(0, serviceID, customerState.CustomerId, Convert.ToInt32(ordinalNumber), Convert.ToInt32(
                                                                               state.CalendarId));
                        //Get the appoinment by appoinment id
                        AppointmentGetResults _appointment = AppoinmentService.GetAppointmentById(resultObjectBase.Id);
                        await context.PostAsync("Your appointment has been scheduled, Ticket: " + _appointment.QCode + _appointment.QNumber);
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("I can't book the appointment, error: " + ex.Message);
                    }
                }
                catch (Exception ex)
                {
                    await context.PostAsync($"Failed with message: {ex.Message}");
                }
            };
            #endregion
            #region Define language and FormBuilder
            CultureInfo ci = new CultureInfo("en");
            Thread.CurrentThread.CurrentCulture   = ci;
            Thread.CurrentThread.CurrentUICulture = ci;
            FormBuilder <BookFormApp> form = new FormBuilder <BookFormApp>();
            return(form
                   #endregion
                   #region office
                   .Field(new FieldReflector <BookFormApp>(nameof(Office))
                          .SetType(null)
                          .SetDefine(async(state, field) =>
            {
                List <Unit> list = GetListUnitsConfigured();
                string data = string.Empty;
                if (list.Count > 0)
                {
                    foreach (var unit in list)
                    {
                        //This format is important, follow this structure
                        data = unit.Id + "." + unit.Name;
                        field
                        .AddDescription(data, unit.Name)
                        .AddTerms(data, unit.Name);
                    }

                    return await Task.FromResult(true);
                }
                else
                {
                    await context.PostAsync($"No records found");
                    throw new Exception("No records found");
                }
            }))
                   #endregion
                   #region service
                   .Field(new FieldReflector <BookFormApp>(nameof(Service))
                          .SetType(null)
                          .SetDefine((state, field) =>
            {
                int unitId = 0;
                if (!String.IsNullOrEmpty(state.Office))
                {
                    //Get the unit id by the option above selected
                    unitId = Utilities.Util.GetUnitIdFromBotOption(state.Office);
                    if (GetServicesOtempues(unitId).Count > 0)
                    {
                        foreach (var prod in GetServicesOtempues(unitId))
                        {
                            field
                            .AddDescription(prod.Name, prod.Name)
                            .AddTerms(prod.Name, prod.Name);
                        }

                        return Task.FromResult(true);
                    }
                    else
                    {
                        throw new Exception("Not exists services");
                    }
                }
                return Task.FromResult(true);
            }))
                   #endregion
                   #region Date
                   .Field(new FieldReflector <BookFormApp>(nameof(Date))
                          .SetType(null)
                          .SetDefine(async(state, field) =>
            {
                List <Service> listService;
                int unitId = 0;
                List <OTempus.Library.Class.Calendar> listCalendars;
                StringBuilder response = new StringBuilder();
                List <CalendarGetSlotsResults> listGetAvailablesSlots = new List <CalendarGetSlotsResults>();
                if (!String.IsNullOrEmpty(state.Service) && !String.IsNullOrEmpty(state.Office))
                {
                    unitId = Utilities.Util.GetUnitIdFromBotOption(state.Office);
                    try
                    {
                        listService = AppoinmentService.listServicesByName(state.Service, 1, "en", false, unitId);
                        int serviceID = listService[0].Id;
                        listCalendars = new List <OTempus.Library.Class.Calendar>();
                        if (GetServicesOtempues(unitId).Count > 0)
                        {
                            listCalendars = GetCalendar(serviceID.ToString(), DateTime.Today);

                            if (listCalendars.Count == 0)
                            {
                                await context.PostAsync($"No records found");

                                throw new Exception("No records found");
                            }
                            else
                            {
                                foreach (var calendar in listCalendars)
                                {
                                    string data = calendar.Id + ".-" + calendar.CalendarDate.ToString();
                                    string data1 = Utilities.Util.GetDateWithOutTime(calendar.CalendarDate);//we see this in form flow
                                    field
                                    .AddDescription(data, data1)
                                    .AddTerms(data, data1);
                                }

                                return await Task.FromResult(true);
                            } //End else
                        }     //End if
                        else
                        {
                            await context.PostAsync($"No records found");

                            throw new Exception("No records found");
                        }
                    }//End try
                    catch (Exception e) { throw e; }
                }
                return await Task.FromResult(true);
            }))
                   #endregion
                   #region calendarId
                   .Field(new FieldReflector <BookFormApp>(nameof(CalendarId)).SetActive(InactiveField))
                   #endregion
                   #region ordinal Slot
                   .Field(new FieldReflector <BookFormApp>(nameof(OrdinalSlot)).SetActive(InactiveField))
                   #endregion
                   #region Period day
                   .Field(nameof(dayPeriod))
                   #endregion
                   #region hour
                   .Field(new FieldReflector <BookFormApp>(nameof(Hour))
                          .SetType(null)
                          .SetDefine(async(state, value) =>
            {
                string date;
                string service;
                List <Service> listService;
                List <OTempus.Library.Class.Calendar> listCalendars;
                listCalendars = new List <OTempus.Library.Class.Calendar>();
                List <CalendarSlot> listGetAvailablesSlots;
                if (!String.IsNullOrEmpty(state.Date) && !String.IsNullOrEmpty(state.Service) && !String.IsNullOrEmpty(state.Office) && !String.IsNullOrEmpty(state.dayPeriod.ToString()))
                {
                    int periodDay = Convert.ToInt32(Utilities.Util.GetIntPeriodDay(state.dayPeriod.ToString()));
                    int unitId = Utilities.Util.GetUnitIdFromBotOption(state.Office);
                    string calendarId = Utilities.Util.GetCalendarIdFromBotOption(state.Date);
                    //assign the calendar id
                    state.CalendarId = calendarId;
                    try
                    {
                        listService = AppoinmentService.listServicesByName(state.Service, 1, "en", false, unitId);
                        if (listService.Count > 0)
                        {
                            //It find the time one record, but in the case this found two,
                            int serviceID = listService[0].Id;

                            date = state.Date; service = state.Service;
                            if (GetServicesOtempues(unitId).Count > 0)
                            {
                                //Service two and date...
                                listCalendars = GetCalendar(serviceID.ToString(), DateTime.Today);
                            }
                            else
                            {
                                await context.PostAsync($"No records found");
                                throw new Exception("No records found");
                            }
                            listGetAvailablesSlots = new List <CalendarSlot>();

                            StringBuilder response = new StringBuilder();
                            response.Append("Not exists slots").ToString();
                        }
                        else
                        {
                            await context.PostAsync($"No records found");
                            throw new Exception("No records found");
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("Here are the error: " + ex.Message);
                    }
                    date = state.Date.ToString();
                    service = state.Service.ToString();
                    if (listCalendars.Count > 0)
                    {
                        listGetAvailablesSlots = AppoinmentService.GetSlotsByPeriod(Convert.ToInt32(calendarId), periodDay.ToString(), 0.ToString());
                        int cont = 0;
                        if (listGetAvailablesSlots.Count > 0)
                        {
                            foreach (OTempus.Library.Class.CalendarSlot calendarSlots in listGetAvailablesSlots)
                            {
                                //string hour = Utilities.Util.GetHourFromStartDate(calendarSlots.DisplayStartTime.ToString()); ;
                                if (calendarSlots.Status.ToString() == "Vacant")
                                {
                                    string data = calendarSlots.OrdinalNumber.ToString();
                                    DateTime date1 = DateTime.Today;
                                    date1 = date1.AddMinutes(calendarSlots.StartTime);
                                    string data1 = string.Format("{0:hh:mm-tt}", date1);
                                    value
                                    .AddDescription(data, data1)
                                    .AddTerms(data, data1);
                                    cont++;
                                }
                            }
                            return await Task.FromResult(true);
                        }
                        else
                        {
                            await context.PostAsync($"No records found");
                            throw new Exception("No records found");
                        }
                    }
                    else
                    {
                        throw new Exception("No records found");
                    }
                }
                return await Task.FromResult(false);
            }))
                   #endregion
                   #region Confirm commented

                   /* .Confirm("Are you selected the information: " +
                    * "\n* Office: {Office} " +
                    * "\n* Slot:  {Hour} " +
                    * "\n* Service:  {Service}? \n" +
                    * "(yes/no)") This lines are commented because, when the user select no,  the user can create inconsistence when user book the appointment (I try to solve by the best way)*/
                   #endregion
                   .AddRemainingFields()
                   .OnCompletion(processOrder)
                   .Build());
        }
コード例 #12
0
        /// <summary>
        /// This method create an Iform (form flow) for reschedule an appointement
        /// </summary>
        /// <returns></returns>
        public static IForm <RescheduleFormApp> BuildForm()
        {
            OnCompletionAsyncDelegate <RescheduleFormApp> processOrder = async(context, state) =>
            {
                try
                {
                    //Get the appointment id from the option selected
                    int appoitmentId = Convert.ToInt32(Utilities.Util.GetAppoitmentIdFromBotOption(state.appointment));

                    WebAppoinmentsClientLibrary.Customers customerLibrary = new WebAppoinmentsClientLibrary.Customers();
                    //Get the actual user state of the customer
                    ACFCustomer customerState = new ACFCustomer();
                    try
                    {
                        if (!context.UserData.TryGetValue <ACFCustomer>("customerState", out customerState))
                        {
                            customerState = new ACFCustomer();
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("Not exists a user session");
                    }
                    string fromDate = state.startDate;
                    string toDate   = state.newDate;
                    //Declaration of Calendar Get Slots Results object
                    CalendarGetSlotsResults slotToShowInformation = new CalendarGetSlotsResults();
                    //Set the parameters for get the expected appoinments
                    int    customerTypeId   = 0;
                    string customerTypeName = "";
                    string typeSeriaizer    = "XML";
                    int    customerId       = customerState.CustomerId;
                    //Declare the object for keept the value of the appoinment find it
                    CustomerGetExpectedAppointmentsResults customerGetExpectedAppointmentsResults = new CustomerGetExpectedAppointmentsResults();
                    //Declaration of the ocject to save the result of the GetExpectedAppoinment
                    ObjectCustomerGetExpectedAppointmentsResults objectCustomerGetExpectedAppointmentsResults = new ObjectCustomerGetExpectedAppointmentsResults();
                    objectCustomerGetExpectedAppointmentsResults = customerLibrary.GetExpectedAppoinment(customerTypeId, customerTypeName, customerId, fromDate, toDate, typeSeriaizer);
                    if (objectCustomerGetExpectedAppointmentsResults.ListCustomerGetExpectedAppointmentsResults.Count > 0)
                    {
                        foreach (CustomerGetExpectedAppointmentsResults listCustomer in objectCustomerGetExpectedAppointmentsResults.ListCustomerGetExpectedAppointmentsResults)
                        {
                            if (appoitmentId == listCustomer.AppointmentId)
                            {
                                //string data = listCustomer.AppointmentId + "" + listCustomer.AppointmentDate;
                                customerGetExpectedAppointmentsResults.AppointmentId       = listCustomer.AppointmentId;
                                customerGetExpectedAppointmentsResults.CaseId              = listCustomer.CaseId;
                                customerGetExpectedAppointmentsResults.ProcessId           = listCustomer.ProcessId;
                                customerGetExpectedAppointmentsResults.ServiceId           = listCustomer.ServiceId;
                                customerGetExpectedAppointmentsResults.AppointmentTypeId   = listCustomer.AppointmentTypeId;
                                customerGetExpectedAppointmentsResults.AppointmentTypeName = listCustomer.AppointmentTypeName;
                            }
                        }
                    }
                    string appointmentId = Utilities.Util.GetOrdinalNumberFromBotOption(state.appointment);
                    // ACFAppointment appointment = new ACFAppointment();
                    // appointment = Utilities.Util.GetAppointment(state.appointment.ToString());
                    int result = AppoinmentService.RescheduleAppoinment(customerGetExpectedAppointmentsResults.ProcessId, state.newDate, customerGetExpectedAppointmentsResults.ServiceId);
                    await context.PostAsync($"The rescheduled is completed with the new Id: " + result);
                }
                catch (Exception ex)
                {
                    await context.PostAsync(ex.Message.ToString());
                }
            };
            CultureInfo ci = new CultureInfo("en");

            Thread.CurrentThread.CurrentCulture   = ci;
            Thread.CurrentThread.CurrentUICulture = ci;
            var culture  = Thread.CurrentThread.CurrentUICulture;
            var form     = new FormBuilder <RescheduleFormApp>();
            var yesTerms = form.Configuration.Yes.ToList();
            var noTerms  = form.Configuration.No.ToList();

            yesTerms.Add("Yes");
            noTerms.Add("No");
            form.Configuration.Yes = yesTerms.ToArray();
            return(form.Message("Fill the information for reschedule the appointment, please")
                   .Field(nameof(startDate))
                   .Field(nameof(newDate))
                   .Field(new FieldReflector <RescheduleFormApp>(nameof(date)).SetActive(InactiveField))
                   .Field(new FieldReflector <RescheduleFormApp>(nameof(processId)).SetActive(InactiveField))
                   .Field(new FieldReflector <RescheduleFormApp>(nameof(appointment))
                          .SetType(null)
                          .SetDefine(async(state, value) =>
            {
                //Instance of library for manage customers
                WebAppoinmentsClientLibrary.Customers customerLibrary = new WebAppoinmentsClientLibrary.Customers();

                if (!String.IsNullOrEmpty(state.startDate) && !String.IsNullOrEmpty(state.newDate))
                {
                    //Get the actual user state of the customer
                    ACFCustomer customerState = new ACFCustomer();
                    try
                    {
                        if (!context.PrivateConversationData.TryGetValue <ACFCustomer>("customerState", out customerState))
                        {
                            customerState = new ACFCustomer();
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("Not exists a user session");
                    }
                    string fromDate = state.startDate;
                    string toDate = state.newDate;
                    //Declaration of Calendar Get Slots Results oobject
                    CalendarGetSlotsResults slotToShowInformation = new CalendarGetSlotsResults();
                    //Set the parameters for get the expected appoinments
                    int customerTypeId = 0;
                    string customerTypeName = "";
                    string typeSeriaizer = "XML";
                    int customerId = customerState.CustomerId;
                    //Declare the object for keept the value of the appoinment find it
                    CustomerGetExpectedAppointmentsResults customerGetExpectedAppointmentsResults = new CustomerGetExpectedAppointmentsResults();
                    //Declaration of the ocject to save the result of the GetExpectedAppoinment
                    ObjectCustomerGetExpectedAppointmentsResults objectCustomerGetExpectedAppointmentsResults = new ObjectCustomerGetExpectedAppointmentsResults();
                    objectCustomerGetExpectedAppointmentsResults = customerLibrary.GetExpectedAppoinment(customerTypeId, customerTypeName, customerId, fromDate, toDate, typeSeriaizer);
                    if (objectCustomerGetExpectedAppointmentsResults.ListCustomerGetExpectedAppointmentsResults.Count > 0)
                    {
                        foreach (CustomerGetExpectedAppointmentsResults listCustomer in objectCustomerGetExpectedAppointmentsResults.ListCustomerGetExpectedAppointmentsResults)
                        {
                            //string data = listCustomer.AppointmentId + ".- "+ listCustomer.ServiceName +" at "+ listCustomer.AppointmentDate;
                            string data = "Appointment Id:" + listCustomer.AppointmentId + ".- \n* Actual appointment date: " + listCustomer.AppointmentDate;
                            customerGetExpectedAppointmentsResults.AppointmentId = listCustomer.AppointmentId;
                            customerGetExpectedAppointmentsResults.CaseId = listCustomer.CaseId;
                            customerGetExpectedAppointmentsResults.ProcessId = listCustomer.ProcessId;
                            customerGetExpectedAppointmentsResults.ServiceId = listCustomer.ServiceId;
                            customerGetExpectedAppointmentsResults.AppointmentTypeId = listCustomer.AppointmentTypeId;
                            customerGetExpectedAppointmentsResults.AppointmentTypeName = listCustomer.AppointmentTypeName;
                            value
                            .AddDescription(data, data)
                            .AddTerms(data, data);
                        }
                    }
                    else
                    {
                        return await Task.FromResult(false);
                    }
                }
                return await Task.FromResult(true);
            }))

                   /* .Confirm("Are you selected: "
                    +"\n* {appointment} "
                    + "\n* New date and time : {newDate} " +
                    + "? \n" +
                    + "(yes/no)")*/
                   .Message("The process for reschdule the appoinment has been started!")
                   .OnCompletion(processOrder)
                   .Build());
        }
コード例 #13
0
        public static IForm <AuthenticationForm> BuildForm()
        {
            OnCompletionAsyncDelegate <AuthenticationForm> processOrder = async(context, state) =>
            {
                //Instance of library for manage customers
                WebAppoinmentsClientLibrary.Customers customerLibrary = new WebAppoinmentsClientLibrary.Customers();
                //Here we will to find the customer by customer id or personal id
                Customer customer = null;
                if (!String.IsNullOrEmpty(state.UserName.ToString()))
                {
                    //Get the object ObjectCustomer and inside of this the object Customer
                    try
                    {
                        customer = customerLibrary.GetCustomerByPersonalId(state.UserName, 0).Customer;
                        if (customer.Id > 0)
                        {
                            /* Create the userstate */
                            //Instance of the object ACFCustomer for keept the customer
                            Models.ACFCustomer customerState = new Models.ACFCustomer();
                            customerState.CustomerId  = customer.Id;
                            customerState.FirstName   = customer.FirstName;
                            customerState.PhoneNumber = customer.TelNumber1;
                            customerState.Sex         = Convert.ToInt32(customer.Sex);
                            customerState.PersonaId   = customer.PersonalId;
                            context.PrivateConversationData.SetValue <ACFCustomer>("customerState", customerState);

                            ///Show the information of the user
                            await context.PostAsync($"I find the record with the next information "
                                                    + " \n* First Name :" + customer.FirstName
                                                    + " \n* Last name :" + customer.LastName
                                                    + " \n* State :" + customer.IsActive
                                                    + " \n* Phone number :" + customer.TelNumber1
                                                    + " \n* Sex :" + customer.Sex
                                                    );

                            state.logged = true;
                            ACFCustomer customerState2 = new ACFCustomer();
                            try
                            {
                                if (!context.PrivateConversationData.TryGetValue <ACFCustomer>("customerState", out customerState2))
                                {
                                    customerState2 = new ACFCustomer();
                                }
                            }
                            catch (Exception ex)
                            {
                                throw new Exception("Not exists a user session");
                            }
                        }

                        else
                        {
                            await context.PostAsync($"The credentials are not valid...: " + state.UserName);

                            state.logged = false;
                        }
                    }
                    catch (Exception)
                    {
                        // throw; here we not send the exception beacuse we need to do the next method below
                    }
                }
            };
            CultureInfo ci = new CultureInfo("en");

            Thread.CurrentThread.CurrentCulture   = ci;
            Thread.CurrentThread.CurrentUICulture = ci;
            var culture  = Thread.CurrentThread.CurrentUICulture;
            var form     = new FormBuilder <AuthenticationForm>();
            var yesTerms = form.Configuration.Yes.ToList();
            var noTerms  = form.Configuration.No.ToList();

            yesTerms.Add("Yes");
            noTerms.Add("No");
            form.Configuration.Yes = yesTerms.ToArray();
            return(form.Message("Fill the follow information, please")
                   .Field(nameof(UserName))
                   .Field(nameof(Password))
                   .Field(new FieldReflector <AuthenticationForm>(nameof(logged)).SetActive(InactiveField))
                   //.Confirm("Are you selected the appoinment id: {appoinmentId}: ? (yes/no)")
                   .AddRemainingFields()
                   //.Message("The process for create the appoinment has been started!")
                   .OnCompletion(processOrder)
                   .Build());
        }
コード例 #14
0
        /// <summary>
        /// Create a IForm(Form flow) based in BookForm object
        /// </summary>
        /// <returns></returns>
        ///
        public static IForm <BookForm> BuildForm()
        {
            #region processOrder
            OnCompletionAsyncDelegate <BookForm> processOrder = async(context, state) =>
            {
                //Get the actual user state of the customer
                ACFCustomer customerState = new ACFCustomer();
                try
                {
                    if (!context.UserData.TryGetValue <ACFCustomer>("customerState", out customerState))
                    {
                        customerState = new ACFCustomer();
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception("Not exists a user session");
                }
                try
                {
                    ResultObjectBase resultObjectBase = new ResultObjectBase();
                    int serviceID = 0;
                    int unitId    = 0;
                    unitId = Utilities.Util.GetUnitIdFromBotOption(state.Office);
                    string ordinalNumber = Utilities.Util.GetOrdinalNumberFromBotOption(state.Hour);
                    try
                    {
                        List <Service> listService = AppoinmentService.listServicesByName(state.Service, 1, "en", false, unitId);
                        serviceID = listService[0].Id;
                    }
                    catch (Exception)
                    {
                        throw new Exception("I don't found appointments with the service: " + state.Service);
                    }

                    try
                    {
                        resultObjectBase = AppoinmentService.SetAppoinment(0, serviceID, customerState.CustomerId, Convert.ToInt32(ordinalNumber), Convert.ToInt32(
                                                                               state.CalendarId));
                        await context.PostAsync("Your appointment has been scheduled with the id: " + resultObjectBase.Id);
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("I can't book the appointment, error: " + ex.Message);
                    }
                }
                catch (Exception ex)
                {
                    await context.PostAsync($"Failed with message: {ex.Message}");
                }
            };
            #endregion
            CultureInfo ci = new CultureInfo("en");
            Thread.CurrentThread.CurrentCulture   = ci;
            Thread.CurrentThread.CurrentUICulture = ci;
            FormBuilder <BookForm> form = new FormBuilder <BookForm>();
            return(form.Message("Fill the information for schedule an appointment, please")
                   .Field(new FieldReflector <BookForm>(nameof(Office))
                          .SetType(null)
                          .SetDefine((state, field) =>
            {
                List <Unit> list = GetListUnitsConfigured();
                string data = string.Empty;
                if (list.Count > 0)
                {
                    foreach (var unit in list)
                    {
                        //This format is important, follow this structure
                        data = unit.Id + "." + unit.Name;
                        field
                        .AddDescription(data, data)
                        .AddTerms(data, data);
                    }
                    return Task.FromResult(true);
                }
                else
                {
                    return Task.FromResult(false);
                }
            }))
                   .Field(new FieldReflector <BookForm>(nameof(Service))
                          .SetType(null)
                          .SetDefine((state, field) =>
            {
                int unitId = 0;
                if (!String.IsNullOrEmpty(state.Office))
                {
                    //Get the unit id by the option above selected
                    unitId = Utilities.Util.GetUnitIdFromBotOption(state.Office);
                    if (GetServicesOtempues(unitId).Count > 0)
                    {
                        foreach (var prod in GetServicesOtempues(unitId))
                        {
                            field
                            .AddDescription(prod.Name, prod.Name)
                            .AddTerms(prod.Name, prod.Name);
                        }
                        return Task.FromResult(true);
                    }
                    else
                    {
                        return Task.FromResult(false);
                    }
                }
                return Task.FromResult(true);
            }))
                   .Field(new FieldReflector <BookForm>(nameof(StartDateAndTime))
                          .SetType(null)
                          .SetDefine((state, field) =>
            {
                string date;
                string service;
                List <Service> listService;
                int unitId = 0;
                List <OTempus.Library.Class.Calendar> listCalendars;
                StringBuilder response = new StringBuilder();
                List <CalendarGetSlotsResults> listGetAvailablesSlots = new List <CalendarGetSlotsResults>();
                if (!String.IsNullOrEmpty(state.Service) && !String.IsNullOrEmpty(state.Office))
                {
                    unitId = Utilities.Util.GetUnitIdFromBotOption(state.Office);
                    try
                    {
                        listService = AppoinmentService.listServicesByName(state.Service, 1, "en", false, unitId);
                        int serviceID = listService[0].Id;
                        listCalendars = new List <OTempus.Library.Class.Calendar>();

                        if (GetServicesOtempues(unitId).Count > 0)
                        {
                            //listCalendars = GetCalendar(serviceID.ToString(), dateAndTime);
                            //i commented this line beacuse i will take today and Thre days more, for get the calendars, and then get the dates of this calendars
                            listCalendars = GetCalendar(serviceID.ToString(), DateTime.Today.ToString());

                            if (listCalendars.Count == 0)
                            {
                                response.Append("Not exists calendars in this date, try it one more time , or write 'quit' for exit").ToString();
                                //vResult.Feedback = string.Format(response.ToString());
                                //vResult.IsValid = false;
                                return Task.FromResult(false);
                            }
                            else
                            {
                                foreach (var calendar in listCalendars)
                                {
                                    string data = calendar.Id + ".-" + calendar.CalendarDate.ToString();
                                    field
                                    .AddDescription(data, data)
                                    .AddTerms(data, data);
                                }
                                return Task.FromResult(true);
                            }          //End else
                        }              //End if
                    }                  //End try
                    catch (Exception e) { }
                }
                return Task.FromResult(true);
            }))

                   /*.Field("StartDateAndTime", validate:
                    * async (state, responses) =>
                    * {
                    *  string date;
                    *  string service;
                    *  List<Service> listService;
                    *  List<OTempus.Library.Class.Calendar> listCalendars;
                    *  //ValidateResult vResult = new ValidateResult();
                    *  var vResult = new ValidateResult { IsValid = true, Value = responses };
                    *  var dateAndTime = (responses as string).Trim();
                    *  StringBuilder response = new StringBuilder();
                    *  List<CalendarGetSlotsResults> listGetAvailablesSlots = new List<CalendarGetSlotsResults>();
                    *  if (!String.IsNullOrEmpty(state.Service) && !String.IsNullOrEmpty(state.Office) && !String.IsNullOrEmpty(dateAndTime))
                    *  {
                    *      int unitId = Utilities.Util.GetUnitIdFromBotOption(state.Office);
                    *      try
                    *      {
                    *      listService = AppoinmentService.listServicesByName(state.Service, 1, "en", false, unitId);
                    *      //It find almost the time one record, but in the case that found two,
                    *      int serviceID = listService[0].Id;
                    *          listCalendars = new List<OTempus.Library.Class.Calendar>();
                    *          date = dateAndTime; service = state.Service;
                    *          if (GetServicesOtempues(unitId).Count > 0)
                    *          {
                    *          //Service two and date...
                    *          listCalendars = GetCalendar(serviceID.ToString(), dateAndTime);
                    *              if (listCalendars.Count == 0)
                    *              {
                    *                  response.Append("Not exists calendars in this date, try it one more time , or write 'quit' for exit").ToString();
                    *                  vResult.Feedback = string.Format(response.ToString());
                    *                  vResult.IsValid = false;
                    *              }
                    *              else
                    *              {
                    *                  vResult.IsValid = true;
                    *                  listGetAvailablesSlots = AppoinmentService.GetAvailablesSlots(listCalendars[0].Id);
                    *                  if (listGetAvailablesSlots.Count > 0)
                    *                  {
                    *                      vResult.IsValid = true;
                    *                  }
                    *                  else
                    *                  {
                    *                      response.Append("There are'n t availables slots in this date, try it one more time , or write 'quit' for exit").ToString();
                    *                      vResult.Feedback = string.Format(response.ToString());
                    *                      vResult.IsValid = false;
                    *                  }
                    *              }//End else
                    *      }//End if GetServicesOtempues(unitId).Count > 0
                    *  }//End try
                    *  catch (Exception ex)
                    *      {
                    *      //throw new Exception("Here are the error: " + ex.Message);
                    *      await context.PostAsync($"Failed with message: {ex.Message}");
                    *      }
                    *  }
                    *  return vResult;
                    * })*/
                   .Field(new FieldReflector <BookForm>(nameof(CalendarId)).SetActive(InactiveField))
                   .Field(new FieldReflector <BookForm>(nameof(OrdinalSlot)).SetActive(InactiveField))
                   /*new source implementation 10/09/17 */
                   .Field(new FieldReflector <BookForm>(nameof(GeneralHour))
                          .SetType(null)
                          .SetDefine(async(state, value) =>
            {
                string date;
                string service;
                List <Service> listService;
                List <OTempus.Library.Class.Calendar> listCalendars;
                List <CalendarGetSlotsResults> listGetAvailablesSlots;
                if (!String.IsNullOrEmpty(state.StartDateAndTime) && !String.IsNullOrEmpty(state.Service) && !String.IsNullOrEmpty(state.Office))
                {
                    int unitId = Utilities.Util.GetUnitIdFromBotOption(state.Office);
                    string calendarId = Utilities.Util.GetCalendarIdFromBotOption(state.StartDateAndTime);
                    //asign the calendar id
                    state.CalendarId = calendarId;
                    string dateSelected = Utilities.Util.GetDateFromBotOption(state.StartDateAndTime);


                    try
                    {
                        listService = AppoinmentService.listServicesByName(state.Service, 1, "en", false, unitId);
                        //It find almost the time one record, but in the case that found two,
                        int serviceID = listService[0].Id;
                        listCalendars = new List <OTempus.Library.Class.Calendar>();
                        date = dateSelected; service = state.Service;
                        if (GetServicesOtempues(unitId).Count > 0)
                        {
                            //Service two and date...
                            listCalendars = GetCalendar(serviceID.ToString(), date);
                        }
                        //List<Appoinment> listAppoinments = await Services.AppoinmentService.GetAppoinments();
                        listGetAvailablesSlots = new List <CalendarGetSlotsResults>();
                        StringBuilder response = new StringBuilder();
                        response.Append("Not exists slots").ToString();
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("Here are the error: " + ex.Message);
                    }
                    date = dateSelected;
                    service = state.Service.ToString();
                    if (listCalendars.Count > 0)
                    {
                        listGetAvailablesSlots = AppoinmentService.GetAvailablesSlots(Convert.ToInt32(state.CalendarId));
                        int cont = 0;
                        foreach (OTempus.Library.Class.CalendarGetSlotsResults calendarSlots in listGetAvailablesSlots)
                        {
                            if (calendarSlots.Status.ToString() == "Vacant")
                            {
                                //I commented this line because I need to cut the message
                                // string data =calendarSlots.OrdinalNumber+".-"+ calendarSlots.DisplayStartTime.ToString() +"-"+calendarSlots.DisplayEndTime+"=>"+calendarSlots.Status;
                                string data = calendarSlots.OrdinalNumber + ".-" + calendarSlots.DisplayStartTime.ToString() + "-" + calendarSlots.DisplayEndTime;
                                string hour = Utilities.Util.GetHourFromStartDate(calendarSlots.DisplayStartTime.ToString());;
                                value
                                // .AddDescription(data, data).AddTerms(data, data);
                                .AddDescription(hour, hour).AddTerms(hour, hour);

                                cont++;
                            }
                        }
                        return await Task.FromResult(true);
                    }
                    else
                    {
                        return await Task.FromResult(false);
                    }
                }
                return await Task.FromResult(false);
            }))
                   /* New source implementation*/
                   .Field(new FieldReflector <BookForm>(nameof(Hour))
                          .SetType(null)
                          .SetDefine(async(state, value) =>
            {
                string date;
                string service;
                List <Service> listService;
                List <OTempus.Library.Class.Calendar> listCalendars;
                List <CalendarGetSlotsResults> listGetAvailablesSlots;
                if (!String.IsNullOrEmpty(state.StartDateAndTime) && !String.IsNullOrEmpty(state.Service) && !String.IsNullOrEmpty(state.Office) && !String.IsNullOrEmpty(state.GeneralHour))
                {
                    string generalHour = state.GeneralHour;
                    int unitId = Utilities.Util.GetUnitIdFromBotOption(state.Office);
                    try
                    {
                        listService = AppoinmentService.listServicesByName(state.Service, 1, "en", false, unitId);
                        //It find almost the time one record, but in the case that found two,
                        int serviceID = listService[0].Id;
                        listCalendars = new List <OTempus.Library.Class.Calendar>();
                        date = state.StartDateAndTime; service = state.Service;
                        if (GetServicesOtempues(unitId).Count > 0)
                        {
                            //Service two and date...
                            listCalendars = GetCalendar(serviceID.ToString(), date);
                        }
                        //List<Appoinment> listAppoinments = await Services.AppoinmentService.GetAppoinments();
                        listGetAvailablesSlots = new List <CalendarGetSlotsResults>();
                        StringBuilder response = new StringBuilder();
                        response.Append("Not exists slots").ToString();
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("Here are the error: " + ex.Message);
                    }
                    date = state.StartDateAndTime.ToString();
                    service = state.Service.ToString();
                    if (listCalendars.Count > 0)
                    {
                        listGetAvailablesSlots = AppoinmentService.GetAvailablesSlots(listCalendars[0].Id);
                        int cont = 0;
                        foreach (OTempus.Library.Class.CalendarGetSlotsResults calendarSlots in listGetAvailablesSlots)
                        {
                            string hour = Utilities.Util.GetHourFromStartDate(calendarSlots.DisplayStartTime.ToString());;

                            if (calendarSlots.Status.ToString() == "Vacant" && hour == generalHour)
                            {
                                //I commented this line because I need to cut the message
                                // string data =calendarSlots.OrdinalNumber+".-"+ calendarSlots.DisplayStartTime.ToString() +"-"+calendarSlots.DisplayEndTime+"=>"+calendarSlots.Status;
                                string data = calendarSlots.OrdinalNumber + ".-" + calendarSlots.DisplayStartTime.ToString() + "-" + calendarSlots.DisplayEndTime;
                                //assign the calendar id
                                //state.CalendarId = calendarSlots.CalendarId.ToString();
                                value
                                .AddDescription(data, data)
                                .AddTerms(data, data);
                                cont++;
                            }
                        }
                        return await Task.FromResult(true);
                    }
                    else
                    {
                        return await Task.FromResult(false);
                    }
                }
                return await Task.FromResult(false);
            }))

                   /* .Confirm("Are you selected the information: " +
                    * "\n* Office: {Office} " +
                    * "\n* Slot:  {Hour} " +
                    * "\n* Service:  {Service}? \n" +
                    * "(yes/no)") This lines are commented because, when the user select no, can crate inconsistence when user book the appointment (I try to solve by the best way)*/
                   .AddRemainingFields()
                   .Message("The process for create the appointment has been started!")
                   .OnCompletion(processOrder)
                   .Build());
        }