public async Task SaveAppointment_ReturnsAppointment() { //Arrrange var mockRepo = new Mock <IAppointmentRepository>(); mockRepo.Setup(repo => repo.SaveAsync()).ReturnsAsync(true); var mockMapper = new MapperConfiguration(cfg => { cfg.AddProfile(new AutoMapperProfile()); }); var mapper = mockMapper.CreateMapper(); var service = new AppoinmentService(mockRepo.Object, mapper); //Act AppointmentDTO dto = new AppointmentDTO { AppointmentTypeId = 1, Date = DateTime.Now, IsCancelled = false, Notes = "", PatientId = 1, }; var result = await service.Add(dto); //Assert Assert.NotNull(result); Assert.IsType <AppointmentDTO>(result); }
public async Task SaveAppointment_WithPreviousAppointment_ReturnsThrow() { //Arrrange var mockRepo = new Mock <IAppointmentRepository>(); mockRepo.Setup(repo => repo.HasAppointment(1, It.IsAny <DateTime>())).Returns(true); var mockMapper = new MapperConfiguration(cfg => { cfg.AddProfile(new AutoMapperProfile()); }); var mapper = mockMapper.CreateMapper(); var service = new AppoinmentService(mockRepo.Object, mapper); //Act AppointmentDTO dto = new AppointmentDTO { AppointmentTypeId = 1, Date = DateTime.Now, IsCancelled = false, Notes = "", PatientId = 1, }; Task act() => service.Add(dto); //Assert var exception = await Assert.ThrowsAsync <Exception>(act); Assert.Equal("This patient has already an appointment for this date", exception.Message); }
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($"Your ticket was created, your number is: " + _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() .OnCompletion(processOrder) .Build()); }
/// <summary> /// Get calendars by service id and an specific date /// </summary> /// <param name="serviceId"></param> /// <param name="date"></param> /// <returns></returns> static List <OTempus.Library.Class.Calendar> GetCalendar(string serviceId, DateTime date) { try { return(AppoinmentService.GetCalendars(serviceId, date)); } catch (Exception ex) { throw new Exception("error in Get Calendar: " + ex.Message); } }
/// <summary> /// Get a list of the actual services, optional we can filtee by the unit selected /// </summary> /// <returns></returns> /// static List <OTempus.Library.Class.Service> GetServicesOtempues(int unitId) { Service _Service = new Service(); _Service.Name = "No services to select, write 'quit' for continue..."; List <Service> listServices = new List <OTempus.Library.Class.Service>(); listServices = AppoinmentService.GetListServices(unitId); if (listServices.Count > 0) { return(AppoinmentService.GetListServices(unitId)); } else { listServices.Add(_Service); return(listServices); } }
public async Task CancelAppointment_WithBadTime_ReturnsThrow() { //Arrrange var mockRepo = new Mock <IAppointmentRepository>(); mockRepo.Setup(repo => repo.IsCancellable(It.IsAny <long>())).Returns(false); var mockMapper = new Mock <IMapper>(); var service = new AppoinmentService(mockRepo.Object, mockMapper.Object); //Act Task act() => service.CancelAppoiment(It.IsAny <int>()); //Assert var exception = await Assert.ThrowsAsync <Exception>(act); Assert.Equal("Appointments must be cancelled at least 24 hours in advance", exception.Message); }
public async Task CancelAppointment_ReturnsTrue() { //Arrrange var mockRepo = new Mock <IAppointmentRepository>(); mockRepo.Setup(repo => repo.IsCancellable(It.IsAny <long>())).Returns(true); mockRepo.Setup(repo => repo.GetById(It.IsAny <long>())).Returns(new Appointment { }); var mockMapper = new Mock <IMapper>(); var service = new AppoinmentService(mockRepo.Object, mockMapper.Object); //Act var result = await service.CancelAppoiment(It.IsAny <int>()); //Assert Assert.True(result); }
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()); }
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()); }
//private static ConcurrentDictionary<CultureInfo, IForm<AppoinmentForm>> _forms = new ConcurrentDictionary<CultureInfo, IForm<AppoinmentForm>>(); public static IForm <AppoinmentForm> BuildForm() { OnCompletionAsyncDelegate <AppoinmentForm> processOrder = async(context, state) => { await context.PostAsync("We will send you the status."); }; CultureInfo ci = new CultureInfo("en"); Thread.CurrentThread.CurrentCulture = ci; Thread.CurrentThread.CurrentUICulture = ci; FormBuilder <AppoinmentForm> form = new FormBuilder <AppoinmentForm>(); return(form.Message("Fill the information for schedule an appoinment, please") .Field("Office", validate: async(state, value) => { ValidateResult vResult = new ValidateResult(); List <ACFAppointment> listAppoinments = await Services.AppoinmentService.GetAppoinments(); StringBuilder response = new StringBuilder(); if (listAppoinments.Count <= 0) { response.Append("No se encontraron items ").ToString(); vResult.Feedback = string.Format(response.ToString()); vResult.IsValid = false; } else { foreach (ACFAppointment item in listAppoinments) { response.Append(item.Name + ", \n"); } //vResult.Feedback = string.Format(response.ToString()); vResult.Feedback = "sdas"; vResult.Value = "asdas"; vResult.IsValid = true; } return vResult; }) .Field(new FieldReflector <AppoinmentForm>(nameof(Service)) .SetType(null) .SetDefine((state, field) => { string office; if (!String.IsNullOrEmpty(state.Office)) { office = state.Office.ToString(); } if (GetServicesOtempues().Count > 0) { foreach (var prod in GetServicesOtempues()) { field .AddDescription(prod.Name, prod.Name) .AddTerms(prod.Name, prod.Name); } return Task.FromResult(true); } else { return Task.FromResult(false); } })) .Field("StartDate", validate: async(state, response) => { ValidateResult vResult = new ValidateResult(); var result = new ValidateResult { IsValid = true, Value = response }; var address = (response as string).Trim(); List <OTempus.Library.Class.Calendar> listCalendars = new List <OTempus.Library.Class.Calendar>(); if (GetServicesOtempues().Count > 0) { //Service two and date... listCalendars = GetCalendar("2", "9/21/2017"); } List <ACFAppointment> listAppoinments = await Services.AppoinmentService.GetAppoinments(); List <CalendarGetSlotsResults> listGetAvailablesSlots = new List <CalendarGetSlotsResults>(); StringBuilder responses = new StringBuilder(); responses.Append("No existen slots").ToString(); vResult.Feedback = string.Format(responses.ToString()); vResult.IsValid = false; if (listCalendars.Count > 0) { listGetAvailablesSlots = AppoinmentService.GetAvailablesSlots(listCalendars[0].Id); bool availablesSlots = true; foreach (OTempus.Library.Class.CalendarGetSlotsResults calendarSlots in listGetAvailablesSlots) { //The status 0 is available, the status 4 is locked, 1 reserved if (calendarSlots.Status != 0) { availablesSlots = false; //In the example here we reserve the first that we find //AppoinmentService.ReserveSlots(listCalendars[0].Id,calendarSlots.OrdinalNumber,1); /*Example to freeup slots*/ AppoinmentService.FreeUpSlots(listCalendars[0].Id, calendarSlots.OrdinalNumber); /*Example to lock slots*/ //AppoinmentService.LockSlots(listCalendars[0].Id, calendarSlots.OrdinalNumber); } } if (availablesSlots) { vResult.Feedback = "Si hay slots"; vResult.Value = "slot 1"; vResult.IsValid = true; } else { responses.Append("No existen slots disponibles").ToString(); vResult.Feedback = string.Format(response.ToString()); vResult.IsValid = false; } } return vResult; }) .Field(new FieldReflector <AppoinmentForm>(nameof(Calendar)) .SetType(null) .SetDefine((state, field) => { string date; string service; if (!String.IsNullOrEmpty(state.StartDate) && !String.IsNullOrEmpty(state.Service)) { date = state.StartDate.ToString(); service = state.Service.ToString(); if (GetServicesOtempues().Count > 0) { // foreach (var prod in GetCalendar("2", "9/19/2017")) foreach (var prod in GetCalendar(service, date)) { field .AddDescription(prod.CalendarDate.ToString(), prod.CalendarDate.ToString()) .AddTerms(prod.CalendarDate.ToString(), prod.CalendarDate.ToString()); } return Task.FromResult(true); } else { return Task.FromResult(false); } } return Task.FromResult(false); })) /*.Field(nameof(Calendar),validate: async (state, value) => * { * ValidateResult vResult = new ValidateResult(); * var values = ((List<object>)value).OfType<Appoinment>(); * var result = new ValidateResult { IsValid = true, Value = values }; * * * List<Appoinment> listAppoinments = await AppoinmentService.GetAppoinments(); * StringBuilder response = new StringBuilder(); * //vResult.Feedback = string.Format(response.ToString()); * // vResult.Feedback = state.Office.ToString(); * vResult.IsValid = true; * vResult.Value = state.Office.ToString() + " " + state.Service.ToString(); * vResult.Feedback = state.Office.ToString() + " " + state.Service.ToString(); * return vResult; * })*/ .Field("Test", validate: async(state, value) => { string office = state.Calendar.ToString(); ValidateResult vResult = new ValidateResult(); List <ACFAppointment> listAppoinments = await AppoinmentService.GetAppoinments(); StringBuilder response = new StringBuilder(); //vResult.Feedback = string.Format(response.ToString()); // vResult.Feedback = state.Office.ToString(); vResult.IsValid = true; vResult.Value = state.Office.ToString() + " " + state.Service.ToString(); vResult.Feedback = state.Office.ToString() + " " + state.Service.ToString(); return vResult; }) .Field(nameof(Color)) .Confirm("Are you selected the office: {Office} \n, the color: {Color} \n And the Service {Service}? (yes/no)") .AddRemainingFields() .Message("The process for create the appoinment has been started!") .OnCompletion(processOrder) .Build()); }
/// <summary> /// This show a menu of services /// </summary> /// <param name="context"></param> private void ShowOptionsServices(IDialogContext context) { List <string> serviceListNames = AppoinmentService.GetServicesNames(); PromptDialog.Choice(context, this.OnOptionSelected, serviceListNames, "Select the service please", "Not a valid option", 3); }
static List <OTempus.Library.Class.Service> GetServicesOtempues() { return(AppoinmentService.GetListServices(0)); }
static List <OTempus.Library.Class.Calendar> GetCalendar(string serviceId, string date) { return(AppoinmentService.GetCalendars(serviceId, date)); }
/// <summary> /// Get a list with the actual units configured /// </summary> /// <returns></returns> static List <OTempus.Library.Class.Unit> GetListUnitsConfigured() { return(AppoinmentService.GetListUnitsConfigured()); }
/// <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()); }
/// <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> /// 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()); }
/// <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()); }
/// <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> /// 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()); }