/// <summary> /// This method get a list of available slots of the calendar, we will pass the calendar Id /// </summary> /// <param name="calendarId"></param> /// <returns></returns> public static int CancelAppoinment(int processId, string fromDate, string toDate, string comment) { int result = 0; WebAppoinmentsClientLibrary.Appoinments appoinment = new WebAppoinmentsClientLibrary.Appoinments(); int cancelReasonId = 0; int parentCaseId = 0; int cancelationType = 0; bool removeWaitingListRequest = false; int customerTretmentPlaneId = 0; int treatmentPlantype = 0; DateTime fromDateString = DateTime.Parse(fromDate, System.Globalization.CultureInfo.InvariantCulture); DateTime toDatestring = DateTime.Parse(toDate, System.Globalization.CultureInfo.InvariantCulture); try { appoinment.CancelAppoinment( processId, cancelReasonId, parentCaseId, cancelationType, comment, removeWaitingListRequest, customerTretmentPlaneId, treatmentPlantype ); return(result); } catch (Exception ex) { throw ex; } }
/// <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 <ReservationCancel> BuildForm() { //Instance of library for manage appointments WebAppoinmentsClientLibrary.Appoinments appointmentLibrary = new WebAppoinmentsClientLibrary.Appoinments(); OnCompletionAsyncDelegate <ReservationCancel> processOrder = async(context, state) => { //Then when we have our object , we can cancel the appointment because we have his process id if (Convert.ToInt32(state.processId) > 0) { ResultObjectBase result = appointmentLibrary.CancelAppoinment(Convert.ToInt32(state.processId), 0, 0, 0, "notes", false, 0, 0 ); if (result.ReturnCode > 0) { } else { await context.PostAsync($"Your appointment was cancelled!"); } } // 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 appointment Id: \n*" + state.processId); } }; CultureInfo ci = new CultureInfo("en"); Thread.CurrentThread.CurrentCulture = ci; Thread.CurrentThread.CurrentUICulture = ci; var culture = Thread.CurrentThread.CurrentUICulture; var form = new FormBuilder <ReservationCancel>(); 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("Select one of the dates availables for cancel the appointment, please") .Field(new FieldReflector <ReservationCancel>(nameof(ReservationCancel.processId)) .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; //personalIdState = customerState.PersonaId; //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) { return await Task.FromResult(false); } 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.ProcessId.ToString(), data + "|" + listCustomer.ServiceName + " in " + listCustomer.UnitName) //here we put the process id and the date of the appointment of this process .AddTerms(listCustomer.ProcessId.ToString(), data + "|" + listCustomer.ServiceName + " in " + listCustomer.UnitName); } return await Task.FromResult(true); } else { await ReservationCancel.context.PostAsync($"No records found"); } return await Task.FromResult(true); } })) .Field(new FieldReflector <ReservationCancel>(nameof(ReservationCancel._customerId)).SetActive(InactiveField)) .Confirm("Are you sure you want to cancel the appointment? " + "\n* (yes/no) ") .AddRemainingFields() .OnCompletion(processOrder) .Build()); }