/// <summary> /// This method get an appoinment by id /// </summary> /// <returns></returns> public static AppointmentGetResults GetAppointmentById(int appointmentId) { AppointmentGetResults appoinment = new AppointmentGetResults(); try { WebAppoinmentsClientLibrary.Appoinments _appoinmentLibray = new WebAppoinmentsClientLibrary.Appoinments(); appoinment = _appoinmentLibray.GetAppoinment(appointmentId).AppointmentInformation; } catch (Exception) { throw; } return(appoinment); }
/// <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()); }
/// <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()); }
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()); }