/// <summary> /// This method reschedule an appoinment /// </summary> /// <param name="slotToShowInformation"></param> /// <param name="dateInput"></param> /// <param name="serviceId"></param> /// <returns></returns> public static int RescheduleAppoinment(int originalProcessId, string dateAndTimeString, int serviceId) { int result = 0; WebAppoinmentsClientLibrary.Appoinments appoinment = new WebAppoinmentsClientLibrary.Appoinments(); int cancelReasonId = 0; int appoinmentTypeId = 0; int treatmentPlantype = 0; DateTime dateAndTime; try { dateAndTime = DateTime.Parse(dateAndTimeString, System.Globalization.CultureInfo.InvariantCulture); } catch (Exception ex) { string message = ex.Message.ToString(); throw; } try { ResultObjectBase resultObjectBase = appoinment.RescheduleAppoinment( originalProcessId, cancelReasonId, serviceId, dateAndTime, appoinmentTypeId, treatmentPlantype ); result = resultObjectBase.Id; if (resultObjectBase.ReturnCode > 0) { throw new Exception(resultObjectBase.ReturnMessage); } return(result); } catch (Exception ex) { throw ex; } }
/// <summary> /// This method can set or book a new appointment /// </summary> /// <param name="parentCaseId"></param> /// <param name="serviceId"></param> /// <param name="customerId"></param> /// <param name="slotOrdinalNumber"></param> /// <param name="calendarId"></param> /// <returns></returns> public static ResultObjectBase SetAppoinment(int parentCaseId, int serviceId, int customerId, int slotOrdinalNumber, int calendarId) //int duration,) { ResultObjectBase resultObjectBase = new ResultObjectBase(); WebAppoinmentsClientLibrary.Appoinments appoinment = new WebAppoinmentsClientLibrary.Appoinments(); DateTime dateandTime = DateTime.Today; int appoimentTypeId = 0; int treatmentPlantype = 0; string subject = ""; string notes = "sd"; string extRef = "asd"; bool preventAutoQueue = false; string languageCode = "en"; bool isWalkIn = false; bool forceSimultaneousAppoiment = true; bool forceWastedDuration = false; bool autoFreeUp = false; int treatmentPlanId = 0; int customerTreatmentPlan = 0; int duration = 0; int basedonAppoimentRequestId = 0; bool simulationOnly = false; bool forceNoDynamicVacancy = false; int userId = 0; string typeSerializer = "XML"; try { resultObjectBase = appoinment.SetAppoinment(parentCaseId, calendarId, serviceId, dateandTime, customerId, appoimentTypeId, treatmentPlanId, subject, notes, extRef, preventAutoQueue, languageCode, isWalkIn, forceSimultaneousAppoiment, forceWastedDuration, autoFreeUp, treatmentPlanId, customerTreatmentPlan, slotOrdinalNumber, calendarId, duration, basedonAppoimentRequestId, simulationOnly, forceWastedDuration, userId, typeSerializer ); return(resultObjectBase); } catch (Exception ex) { throw ex; } }
public static int Enqueue(int serviceId, int customerId, string notes) { int result = 0; try { int avatarId = 0; int userId = 0; string languageCode = "es"; int receptionPointId = 0; string extRef = ""; string subject = ""; string listIntClassificationId = ""; bool printTicket = false; int assingToUserId = 0; int actOptionId = 0; int agentAssignmentType = 0; int priorityLevel = 0; int suspendDuration = 0; int procedureId = 0; string typeSerializer = "xml"; WebAppoinmentsClientLibrary.Customers customerLibrary = new WebAppoinmentsClientLibrary.Customers(); ResultObjectBase resultObjectBase = customerLibrary.Enqueue(serviceId, receptionPointId, userId, customerId , languageCode, subject, notes, extRef, listIntClassificationId, printTicket, assingToUserId, agentAssignmentType, procedureId, actOptionId, priorityLevel, suspendDuration, avatarId, typeSerializer); if (resultObjectBase.Id > 0) { result = resultObjectBase.Id; } if (resultObjectBase.ReturnCode > 0) { throw new Exception("Error: " + resultObjectBase.ReturnException); } } catch (Exception) { throw; } return(result); }
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()); }
/// <summary> /// This method save a customer record an returns his id /// </summary> /// <param name="personalId"></param> /// <param name="customerIdTypeId"></param> /// <param name="customerIdTypeName"></param> /// <param name="customerLevelId"></param> /// <param name="customerLevelName"></param> /// <param name="customProperties"></param> /// <param name="email"></param> /// <param name="firstName"></param> /// <param name="isActive"></param> /// <param name="isCustomerGroup"></param> /// <param name="isMemberOfGroups"></param> /// <param name="languageCode"></param> /// <param name="lastName"></param> /// <param name="name"></param> /// <param name="notes"></param> /// <param name="pictureAttachmentId"></param> /// <param name="sex"></param> /// <param name="telNumber1"></param> /// <param name="telNumber2"></param> /// <param name="userId"></param> /// <param name="customerId"></param> /// <param name="isSignUp"></param> /// <param name="typeSerializer"></param> /// <returns></returns> public static int SaveCustomer(string personalId, //int customerIdTypeId, //string customerIdTypeName, //int customerLevelId, //string customerLevelName, //string customProperties, string firstName, //bool isActive, //bool isCustomerGroup, //bool isMemberOfGroups, //string languageCode, string lastName, //string name, //string notes, //int pictureAttachmentId, string telNumber1, //string telNumber2, //int userId, //bool isSignUp, //string typeSerializer, int customerId) { personalId = firstName; int customerIdTypeId = 0; int result = 0; string customerIdTypeName = ""; int customerLevelId = 0; string customerLevelName = ""; string customProperties = ""; bool isActive = true; bool isCustomerGroup = false; //It is important to have in false for get results of... bool isMemberOfGroups = false; //It is important to have in false for get results of... string languageCode = "es"; string name = firstName; string notes = ""; int pictureAttachmentId = 0; string telNumber2 = ""; int userId = 0; bool isSignUp = true; string typeSerializer = "XML"; string email = ""; int sex = 0; try { WebAppoinmentsClientLibrary.Customers customerLibrary = new WebAppoinmentsClientLibrary.Customers(); ResultObjectBase resultObjectBase = customerLibrary.SaveCustomer( telNumber1, customerIdTypeId, customerIdTypeName, customerLevelId, customerLevelName, customProperties, email, firstName, isActive, isCustomerGroup, isMemberOfGroups, languageCode, lastName, name, notes, pictureAttachmentId, sex, telNumber1, telNumber2, userId, customerId, isSignUp, typeSerializer); if (resultObjectBase.ReturnCode > 0) { throw new Exception(resultObjectBase.ReturnMessage); } else { result = resultObjectBase.Id; } } catch (Exception) { throw; } return(result); }
/// <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()); }
/// <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()); }