public bool ImportSingleContact(Guid clientId, AllClientsContact contact, Enumerations.WebformType webformType) { bool result = false; using (var ctx = new DomainContext()) { var allClientsContactExport = new AllClientsContactExport { Contact = contact }; var client = ctx.Client.Single(n => n.Id == clientId); allClientsContactExport.Account = AllClientsService.GetAllClientsAccount(client); var webForms = AllClientsService.GetAllClientsWebforms(allClientsContactExport.Account); allClientsContactExport.AllClientsWebform = webForms.Single(n => n.WebformType == webformType); result = AllClientsService.ExportContact(allClientsContactExport).Contains("lblThankYou"); } return result; }
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")); }
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; }
public static string ExportContact(AllClientsContactExport export) { Contract.ContractFailed += new EventHandler<ContractFailedEventArgs>(Contract_ContractFailed); Contract.Requires(export.Account.IsValid()); Contract.Requires(export.AllClientsWebform.IsValid()); Contract.Requires(export.Contact.IsValid()); string result; var aimServiceConfiguration = System.Configuration.ConfigurationManager.GetSection("aimServiceConfigurationGroup/aimServiceConfiguration") as AIMServiceConfigurationSection; if (!aimServiceConfiguration.ServiceConfiguration.AllowExport) return "lblThankYou"; XElement contactElement = CommonService.ToXml(typeof(AllClientsContact), export.Contact); Dictionary<string, string> parameters = GetContactExportParameters(export); XElement response = CommonService.AllClientsFormPost(parameters); //remove prospect tag if customer if (export.AllClientsWebform.WebformType != Enumerations.WebformType.Lead) AllClientsService.AddRemoveFlag(export.Account, true, export.Contact.Email, "Prospect/Lead"); result = response.ToString(); return result; }
public static Dictionary<string, string> GetContactExportParameters(AllClientsContactExport export) { Dictionary<string, string> result = new Dictionary<string, string>(); XElement contactElement = CommonService.ToXml(typeof(AllClientsContact), export.Contact); MapBirthdate(contactElement); XElement flags = contactElement.Element("{http://www.aimscrm.com/schema/2011/common/contact}Flags"); XElement categories = contactElement.Element("{http://www.aimscrm.com/schema/2011/common/contact}Categories"); XElement custom = contactElement.Element("{http://www.aimscrm.com/schema/2011/common/contact}Custom"); IEnumerable<XElement> contact = contactElement.Elements().Except(flags.DescendantsAndSelf()).Except(categories.DescendantsAndSelf()).Except(custom.DescendantsAndSelf()); contact.ToList().ForEach(n => { if (n.Name.LocalName != "Categories" && n.Name.LocalName != "Flags" && n.Name.LocalName != "Custom" && n.Name.LocalName != "CustomElement") result.Add(n.Name.LocalName.ToLower(), n.Value); }); if (categories.Descendants().Count() > 0) { result.Add("category", categories.Elements().First().Element("{http://www.aimscrm.com/schema/2011/common/contact}Name").Value); } custom.Descendants().ToList().ForEach(customElement => { try { if (customElement.Elements("{http://www.aimscrm.com/schema/2011/common/contact}Value").Count() > 0) { result.Add( customElement.Element("{http://www.aimscrm.com/schema/2011/common/contact}Name") .Value.ToLower(), customElement.Element("{http://www.aimscrm.com/schema/2011/common/contact}Value").Value); } } catch { //swallow } }); result.Add("key", export.AllClientsWebform.FormKey); result.Add("accountid", export.Account.AccountId.ToString()); result.Add("apikey", export.Account.APIKey); return result; }
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; }
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; }