示例#1
0
 public static AllClientsAccount GetSampleAccount()
 {
     AllClientsAccount result = new AllClientsAccount
     {
         AccountId = 2326,
         Active = true,
         APIKey = "44E7D143D6CF3B3EEF56FB6191BC7562",
         ClientName = "DeveloperTest01",
         Group = "Fitness Owners"
     };
     return result;
 }
示例#2
0
 public static XElement GetContacts(AllClientsAccount account)
 {
     XElement result = null;
     try
     {
         result = CommonService.AllClientsRequest("GetContacts.aspx", account.AccountId, account.APIKey);
     }
     catch (System.Exception ex)
     {
         throw new MessagingException("Failed to retrieve contacts from AllClients", ex, "GetContacts", String.Empty);
     }
     return result;
 }
示例#3
0
        public void GetContactExportParametersTest()
        {
            AllClientsAccount account = new AllClientsAccount
            {
                AccountId = 1000,
                APIKey = "123456789"
            };
            AllClientsWebform webform = new AllClientsWebform
            {
                Account = account,
                FormKey = "123",
                FormName = "TestForm",
                WebformType = Types.Enumerations.WebformType.ActiveCustomer
            };

            AllClientsContactExport export = new AllClientsContactExport();
            export.AllClientsWebform = webform;
            export.Account = account;
            export.Contact = CommonService.FromXml(typeof(AllClientsContact), GetWellKnownContactElement().ToString()) as AllClientsContact;

            
            Dictionary<string, string> actual;
            actual = AllClientsService.GetContactExportParameters(export);
            Assert.IsTrue(actual.ContainsKey("accountid"));
            Assert.IsTrue(actual.ContainsKey("apikey"));
            Assert.IsTrue(actual.ContainsKey("birthday_month"));
            Assert.IsTrue(actual.ContainsKey("birthday_day"));
            Assert.IsTrue(actual.ContainsKey("birthday_year"));
        }
示例#4
0
 public void GetContactsTest()
 {
     DomainContext ctx = new DomainContext();
     var client = ctx.Client.Where(n => n.Id == new Guid("3E7930E4-524B-4814-AF47-90E39D5E555A")).Single();
     AllClientsAccount account = new AllClientsAccount
     {
         AccountId = 2308,
         Active = true,
         APIKey = client.ApiKey,
         ClientName = "DeveloperTesting"
     };
             
     
    
     XElement actual;
     actual = AllClientsService.GetContacts(account);
     
     Assert.IsTrue(actual.Descendants().Count() > 0);
     
 }
示例#5
0
        public static bool AddRemoveFlag(AllClientsAccount account, bool remove, string emailAddress, string flag)
        {
            bool result = false;
            Dictionary<string, string> parameters = new Dictionary<string, string>();


            parameters.Add("accountId", account.AccountId.ToString());
            parameters.Add("apikey", account.APIKey);
            parameters.Add("identifyMethod", "2");
            parameters.Add("identifyValue", emailAddress);
            //1 for add flag 2 for remove
            parameters.Add("mode", remove ? "2" : "1");
            parameters.Add("flag", flag);
            var messageResult = CommonService.AllClientsRequest("ContactFlags.aspx", parameters) as XElement;
            result = messageResult != null && messageResult.Element("message").Value == "Success";
            return result;

        }
示例#6
0
        public static List<AllClientsWebform> GetAllClientsWebforms(AllClientsAccount account)
        {

            List<AllClientsWebform> result = new List<AllClientsWebform>();
            try
            {
                XElement webforms = CommonService.AllClientsRequest("GetWebforms.aspx", account.AccountId, account.APIKey);

                //standard form names
                string appointmentReminderFormName = "6. sys_action_assign_appt_reminder";
                string leadToCustomerFormName = "5. sys_action_import_lead to customer";
                string customerFormName = "4. sys_action_import_customer";
                string customerInactiveFormName = "2. sys_action_import_customer_inactive";
                string leadFormName = "3. sys_action_import_lead";
                string newCustomerFormName = "1. sys_action_import_customer_new";
                string aimsAutoNotificationFormName = "AIMS Auto Notification";
                //webforms from All Clients as Elements
                XElement leadToCustomerForm = webforms.Descendants("webform").Where(n => n.Element("name").Value == leadToCustomerFormName).First();
                XElement customerForm = webforms.Descendants("webform").Where(n => n.Element("name").Value == customerFormName).First();
                XElement customerInactiveForm = webforms.Descendants("webform").Where(n => n.Element("name").Value == customerInactiveFormName).First();
                XElement leadForm = webforms.Descendants("webform").Where(n => n.Element("name").Value == leadFormName).First();
                XElement newCustomerForm = webforms.Descendants("webform").Where(n => n.Element("name").Value == newCustomerFormName).First();
                XElement aimsAutoNotificationForm = webforms.Descendants("webform").Where(n => n.Element("name").Value == aimsAutoNotificationFormName).FirstOrDefault();
                XElement appointmentReminderForm = webforms.Descendants("webform").Where(n => n.Element("name").Value == appointmentReminderFormName).FirstOrDefault();
                
                //Assign new forms with FormKeys
                AllClientsWebform leadToCustomerWebForm = new AllClientsWebform();
                leadToCustomerWebForm.WebformType = Enumerations.WebformType.LeadToCustomer;
                leadToCustomerWebForm.FormKey = leadToCustomerForm.Element("formkey").Value;

                AllClientsWebform customerWebform = new AllClientsWebform();
                customerWebform.WebformType = Enumerations.WebformType.ActiveCustomer;
                customerWebform.FormKey = customerForm.Element("formkey").Value;

                AllClientsWebform customerInactiveWebform = new AllClientsWebform();
                customerInactiveWebform.WebformType = Enumerations.WebformType.InactiveCustomer;
                customerInactiveWebform.FormKey = customerInactiveForm.Element("formkey").Value;

                AllClientsWebform customerLeadWebform = new AllClientsWebform();
                customerLeadWebform.WebformType = Enumerations.WebformType.Lead;
                customerLeadWebform.FormKey = leadForm.Element("formkey").Value;

                AllClientsWebform newCustomerWebform = new AllClientsWebform();
                newCustomerWebform.WebformType = Enumerations.WebformType.NewCustomer;
                newCustomerWebform.FormKey = newCustomerForm.Element("formkey").Value;

                if (aimsAutoNotificationForm != null)
                {
                    AllClientsWebform aimsAutoNotificationWebform = new AllClientsWebform();
                    aimsAutoNotificationWebform.WebformType = Enumerations.WebformType.AutoNotification;
                    aimsAutoNotificationWebform.FormKey = aimsAutoNotificationForm.Element("formkey").Value;
                    aimsAutoNotificationWebform.Account = account;
                    result.Add(aimsAutoNotificationWebform);
                }

                if (appointmentReminderForm != null)
                {
                    AllClientsWebform appointmentReminderWebForm = new AllClientsWebform();
                    appointmentReminderWebForm.WebformType = Enumerations.WebformType.AppointmentReminder;
                    appointmentReminderWebForm.FormKey = appointmentReminderForm.Element("formkey").Value;
                    appointmentReminderWebForm.Account = account;
                    result.Add(appointmentReminderWebForm);
                }
                //Assign Accounts 
                leadToCustomerWebForm.Account = account;
                customerWebform.Account = account;
                customerInactiveWebform.Account = account;
                customerLeadWebform.Account = account;
                newCustomerWebform.Account = account;
                //Assign FormName
                leadToCustomerWebForm.FormName = leadToCustomerFormName;
                customerWebform.FormName = customerFormName;
                customerInactiveWebform.FormName = customerInactiveFormName;
                customerLeadWebform.FormName = leadFormName;
                newCustomerWebform.FormName = newCustomerFormName;

                result.Add(leadToCustomerWebForm);
                result.Add(customerWebform);
                result.Add(customerInactiveWebform);
                result.Add(customerLeadWebform);
                result.Add(newCustomerWebform);
                return result;
            }
            catch (System.Exception ex)
            {
                throw new AccountSetupException(String.Format("Could not retrieve expected webforms for client: {0}", account.ClientName), ex);
            }

            

        }
示例#7
0
 public static AllClientsContactExport MapToAllClientsContactExport(AllClientsContact contact, List<AllClientsWebform> webforms, AllClientsAccount account)
 {
     var result = new AllClientsContactExport();
     result.Contact = contact;
     result.AllClientsWebform = webforms.SingleOrDefault(n => n.WebformType == (Enumerations.WebformType)Enum.Parse(typeof(Enumerations.WebformType), contact.Categories.First().Id));
     result.Account = account;
     return result;
 }
示例#8
0
        public static AllClientsAccount GetAllClientsAccount(IClient client)
        {
            AllClientsAccount result = null;
            try
            {
                result = new AllClientsAccount();
                result.AccountId = client.AccountId;
                result.APIKey = client.ApiKey;
                result.Active = client.Active;
                result.ClientName = client.Company;

            }
            catch (System.Exception ex)
            {
                throw new AccountSetupException("Could not create valid AllClients account", ex, client);
            }
            return result;
        }
示例#9
0
        public static AllClientsContactExport MapExportForAppointments(AllClientsContact contact, AllClientsAccount account, IClient client, List<AllClientsWebform> webforms)
        {
            var clientNotificationWebform = webforms.FirstOrDefault(x => x.WebformType == Types.Enumerations.WebformType.AppointmentReminder);
            var ownerNotificationWebForm = webforms.FirstOrDefault(x => x.WebformType == Types.Enumerations.WebformType.AutoNotification);
            if (clientNotificationWebform == null || ownerNotificationWebForm == null)
                return null;

            var apptDateTimeProperty = contact.Custom.SingleOrDefault(x => x.Name == "ApptDate");
            var apptTimeProperty = contact.Custom.SingleOrDefault(x => x.Name == "ClassTime");
            if (apptDateTimeProperty == null || apptTimeProperty == null)
                return null;
            
            var apptDate = System.DateTime.MinValue;
            var apptTime = System.DateTime.MinValue;
        
            if(!DateTime.TryParse(apptDateTimeProperty.Value,out apptDate))
                return null;

            if (!DateTime.TryParse(apptTimeProperty.Value, out apptTime))
                return null;
            apptDate = DateTime.Parse(String.Format("{0} {1}", apptDate.Date.ToShortDateString(), apptTime.TimeOfDay.ToString()));

            var result = new AllClientsContactExport
            {
                Account = account,
                Contact = contact
            };
            contact.Custom.Single(x => x.Name == "ApptDate").Value = apptDate.ToString();
            var comment = AllClientsService.GetAppointmentNotificationComments(contact);
            contact.Custom.Add(new CustomElement { Name = "Comments", Value = comment });

           
            //logic to determine action 
            //if appointment has passed
            if (apptDate.AddDays(Properties.Settings.Default.OwnerNotificationDateRange).Date == System.DateTime.Now.Date)
                result.AllClientsWebform = ownerNotificationWebForm;
                //if the appointment date is tomorrow
            else if (apptDate.Date == System.DateTime.Now.Date.AddDays(Properties.Settings.Default.ClientNotificationDateRange).Date)
                result.AllClientsWebform = clientNotificationWebform;
           
            return result;

        }
示例#10
0
        public static AllClientsContactExport MapExport(List<AllClientsContact> existingContacts, AllClientsAccount account, IClient client, List<AllClientsWebform> webforms, XElement importResponse)
        {
            Contract.Requires(importResponse.Name == "{http://clients.mindbodyonline.com/api/0_5}Row");
            
            AllClientsContactExport result = null;
            try
            {
                bool inactive = importResponse.Element("{http://clients.mindbodyonline.com/api/0_5}Inactive").Value == "True";
                bool prospect = importResponse.Element("{http://clients.mindbodyonline.com/api/0_5}IsProspect").Value == "True";
                string email = importResponse.Element("{http://clients.mindbodyonline.com/api/0_5}EmailName").Value.ToLower();
                bool isinsert = existingContacts.Where(n => n.Email.ToLower() == email).Count() == 0;
                bool isNew = IsNew(importResponse);
                AllClientsContact contact = MapToAllClientsContact(importResponse);
                AllClientsContactExport export = new AllClientsContactExport();
                export.Contact = contact;
                export.Account = account;
                
                if (isinsert)
                {
                    if (isNew)
                    {
                        export.AllClientsWebform = webforms.Where(n => n.WebformType == Types.Enumerations.WebformType.NewCustomer).Single();
                    }
                    else if (prospect)
                    {
                        export.AllClientsWebform = webforms.Where(n => n.WebformType == Types.Enumerations.WebformType.Lead).Single();
                    }
                    else
                    {
                        if (inactive)
                            export.AllClientsWebform = webforms.Where(n => n.WebformType == Types.Enumerations.WebformType.InactiveCustomer).Single();
                        else
                            export.AllClientsWebform = webforms.Where(n => n.WebformType == Types.Enumerations.WebformType.ActiveCustomer).Single();

                    }
                    //if only inserting we only add when not found on allclients
                    
                }
                else if (client.EnableUpdates)
                {
                    //we are an update
                    //perform lookup
                    var matchList = existingContacts.Where(n => n.Email.ToLower() == email);
                    if (matchList.Count() > 0)
                    {
                        //we have a match
                        var match = matchList.First();
                        //if not a lead, and their current allclients account is marked as prospect, they qualify for lead to customer
                        if ((!prospect & !inactive) && (match.Flags.Count > 0) && (match.Flags.Where(n => n.Name == "Prospect/Lead").Count() > 0))
                        {
                            export.AllClientsWebform = webforms.Where(n => n.WebformType == Types.Enumerations.WebformType.LeadToCustomer).Single();
                        }
                        else
                        {
                            export.AllClientsWebform = new AllClientsWebform { Account = account, FormKey = "0", FormName = "Bypass", WebformType = Types.Enumerations.WebformType.None };
                        }
                    }

                }
                else
                {
                    export.AllClientsWebform = new AllClientsWebform { Account = account, FormKey = "0", FormName = "Bypass", WebformType = Types.Enumerations.WebformType.None };
                }
                result = export;
            }
            catch (System.Exception ex)
            {
                throw new AIMException(String.Format("Could not MapExport:{0}", importResponse), ex);
            }
            return result;
        }
示例#11
0
        public void TestMethod1()
        {
            //Make method
            var existingAccounts = GetExistingContacts(GetTestClient()).Select(n => CommonService.FromXml(typeof(AllClientsContact), n.ContactElement.Element("{http://www.aimscrm.com/schema/2011/common/contact}AllClientsContact").ToString())).OfType<AllClientsContact>().ToList();
            var imports = GetMindBodyContacts(GetTestClient()).Descendants("{http://clients.mindbodyonline.com/API/0_4}Row").ToList();
            var ac = GetTestClient();
            var allClientsAccount = new AllClientsAccount
            {
                 AccountId=ac.AccountId,
                 Active=true,
                 APIKey=ac.ApiKey
            };
            var webForms = AllClientsService.GetAllClientsWebforms(allClientsAccount);
            List<AllClientsContactExport> result = new List<AllClientsContactExport>();
            imports.ForEach(n =>
                {
                    var export = MindBodyService.MapExport(existingAccounts, allClientsAccount,ac, webForms, n);
                    result.Add(export);
                });


            Assert.IsTrue(result.Count > 0);
        }