public static void ClientImportPostProcess( FileInfo file, int imported, int rejected ) { using( DomainContext ctx = new DomainContext() ) { Manager mgr = new Manager( ctx ); ClientFileImportManager clientFileImportManager = new ClientFileImportManager( mgr ); clientFileImportManager.SaveClientFileImport( file.Name, imported, rejected ); } }
static List<Contact> GetExistingContacts(Client client) { DomainContext ctx = new DomainContext(); var result = ctx.Contact.Where(n => n.ClientId == client.Id).ToList(); return result; }
public static IClient GetClientFromImportFile( FileInfo file ) { IClient result = null; using( DomainContext ctx = new DomainContext() ) { Manager mgr = new Manager( ctx ); ClientFileImportManager clientFileImportManager = new ClientFileImportManager( mgr ); result = clientFileImportManager.GetClientFromImportFilename( file.Name ); } return result; }
public static List<FileInfo> GetClientImportFiles(IClient client) { List<FileInfo> result = new List<FileInfo>(); using( DomainContext ctx = new DomainContext() ) { Manager mgr = new Manager( ctx ); ClientFileImportManager clientFileImportManager = new ClientFileImportManager( mgr ); var imports = clientFileImportManager.GetClientFileImports( client ); imports.Select( n => new FileInfo( n.ImportedFilePath ) ).ToList().ForEach( n => { result.Add( n ); } ); } return result; }
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 XmlImportInfo TransformToXml(CsvFileInfo csvFileInfo, List<FieldMap> fieldMaps) { string csvFilePath = csvFileInfo.Path; var rawRows = GetRawRows(csvFilePath).Skip(csvFileInfo.FirstRowContainsColumnHeadings ? 1 : 0); var category = _xmlRepository.GetCategory(csvFileInfo.Category); var flag = _xmlRepository.GetFlag(csvFileInfo.Flag); var rowsToContacts = ConvertRowsToContacts(rawRows, fieldMaps, category, flag); var xmlFilePath = csvFilePath.Replace(Path.GetExtension(csvFilePath), ".xml"); XmlImportInfo importResult = null; try { GenerateXml(rowsToContacts.Contacts, xmlFilePath); using (DomainContext ctx = new DomainContext()) { var account = System.Web.HttpContext.Current.Session["allClientsAccountModel"] as AllClientsAccountModel; var importRecord = new ClientFileImport(); importRecord.Id = Guid.NewGuid(); importRecord.ImportedFilePath = xmlFilePath; importRecord.UploadFilePath = csvFileInfo.Path; importRecord.RecordsImported = rowsToContacts.SuccessCount; importRecord.RecordsFailed = rowsToContacts.FailureCount; importRecord.ClientId = account.ClientId; importRecord.LastUpdated = System.DateTime.Now; ctx.ClientFileImport.InsertOnSubmit(importRecord); ctx.SubmitChanges(); } var importFile = new FileInfo(xmlFilePath); importResult = new XmlImportInfo { SuccessCount = rowsToContacts.SuccessCount, FailureCount = rowsToContacts.FailureCount, DuplicateCount = rowsToContacts.DuplicateCount, FileName = Path.GetFileName(xmlFilePath) }; ImportWorkflow(importFile, importResult); } catch (Exception e) { throw e; } return importResult; }
public static List<IClient> GetActiveClients() { var aimServiceConfiguration = System.Configuration.ConfigurationManager.GetSection("aimServiceConfigurationGroup/aimServiceConfiguration") as AIMServiceConfigurationSection; List<IClient> result = new List<IClient>(); using (DomainContext ctx = new DomainContext()) { Manager mgr = new Manager(ctx); ClientManager clientManager = new ClientManager(mgr); if (aimServiceConfiguration.ServiceConfiguration.TestClientId != Guid.Empty) result = clientManager.GetActive() .Where(x => x.Id == aimServiceConfiguration.ServiceConfiguration.TestClientId) .ToList(); else result = clientManager.GetActive().ToList(); } return result; }
public static IClient GetSampleClient() { Client result = null; using (DomainContext ctx = new DomainContext()) { result = ctx.Client.Where(n => n.Id == WellKnownAccountID).Single(); } return result; }
public static List<AllClientsContact> GetExistingContacts(IClient client) { List<AllClientsContact> result = null; using (DomainContext ctx = new DomainContext()) { result = ctx.Contact.Where(n => n.ClientId == client.Id) .Select(n => CommonService.FromXml(typeof(AllClientsContact), n.ContactElement.Element("{http://www.aimscrm.com/schema/2011/common/contact}AllClientsContact") .ToString())).OfType<AllClientsContact>().ToList(); } return result; }
public List<IImportType> GetAllClientTypes() { List<IImportType> result = null; using (DomainContext ctx = new DomainContext()) { Manager mgr = new Manager(ctx); ImportTypeManager importTypeManager = new ImportTypeManager(mgr); result = importTypeManager.GetAll().ToList(); } return result; }
public void SaveClient(ClientModel model, NameValueCollection requestParameters) { using (DomainContext ctx = new DomainContext()) { Manager mgr = new Manager(ctx); ClientManager clientManager = new ClientManager(mgr); var existing = clientManager.GetByKey(model.Id); if (existing != null) { if (existing.ClientProperties == null) { existing.ClientProperties = new ClientProperties(); } existing.ClientProperties.AllClientsUsername = model.Email; existing.ClientProperties.AllClientsPassword = model.AllClientsPassword; existing.AccountId = model.AccountId; existing.ImportTypeId = model.ImportTypeId; existing.EnableUpdates = model.EnableUpdates; existing.Active = model.Active; existing.ApiKey = model.ApiKey; existing.Company = model.Company; existing.ClientParameters = GetClientParametersObject(model, requestParameters).GetClientParameters; ctx.SubmitChanges(); } } }
public ClientModel GetClientModelByID(Guid ID) { ClientModel result = null; using (DomainContext ctx = new DomainContext()) { Manager mgr = new Manager(ctx); ClientManager clientManager = new ClientManager(mgr); ImportTypeManager importTypeManager = new ImportTypeManager(mgr); var client = clientManager.GetByKey(ID); if (client != null) { result = new ClientModel { Id = client.Id, AccountId = client.AccountId, EnableUpdates = client.EnableUpdates, Active = client.Active, ApiKey = client.ApiKey, Company = client.Company, Created = client.Created, Updated = client.Updated, ImportTypeId = client.ImportTypeId, ImportType = importTypeManager.GetByKey(client.ImportTypeId), ClientParameters = client.ClientParameters, ClientParametersObject = client.ImportTypeId == 1 ? new MindBodyParameters(client.ClientParameters) : new ClientParametersObject() }; if (client.ClientProperties != null) { result.Email = client.ClientProperties.AllClientsUsername; result.AllClientsPassword = client.ClientProperties.AllClientsPassword; } } } return result; }
public List<ClientModel> GellAllClients() { List<ClientModel> result = null; using (DomainContext ctx = new DomainContext()) { Manager mgr = new Manager(ctx); ClientManager clientManager = new ClientManager(mgr); ImportTypeManager importTypeManager = new ImportTypeManager(mgr); result = clientManager.GetAll().Select(n => new ClientModel { Id = n.Id, IsDeleted = n.IsDeleted, AccountId = n.AccountId, Active = n.Active, EnableUpdates = n.EnableUpdates, ApiKey = n.ApiKey, Company = n.Company, Created = n.Created, Updated = n.Updated, ImportTypeId = n.ImportTypeId, ImportType = importTypeManager.GetByKey(n.ImportTypeId), ClientParameters = n.ClientParameters, ClientParametersObject = n.ImportTypeId == 1 ? new MindBodyParameters(n.ClientParameters) : new ClientParametersObject() }).ToList(); } return result; }
public static List<IClient> GetActiveClients() { var aimServiceConfiguration = System.Configuration.ConfigurationManager.GetSection("aimServiceConfigurationGroup/aimServiceConfiguration") as AIMServiceConfigurationSection; List<IClient> result = null; using (DomainContext ctx = new DomainContext()) { Manager mgr = new Manager(ctx); ClientManager cmgr = new ClientManager(mgr); if(aimServiceConfiguration.ServiceConfiguration.TestClientId != Guid.Empty) result = cmgr.GetActive().Where(n => n.ImportType.TypeName == IMPORT_TYPE && n.Id == aimServiceConfiguration.ServiceConfiguration.TestClientId).OfType<IClient>().ToList(); else result = cmgr.GetActive().Where(n => n.ImportType.TypeName == IMPORT_TYPE).OfType<IClient>().ToList(); } return result.ToList(); }
// // You can use the following additional attributes as you write your tests: // // Use ClassInitialize to run code before running the first test in the class // [ClassInitialize()] // public static void MyClassInitialize(TestContext testContext) { } // // Use ClassCleanup to run code after all tests in a class have run // [ClassCleanup()] // public static void MyClassCleanup() { } // // Use TestInitialize to run code before running each test // [TestInitialize()] // public void MyTestInitialize() { } // // Use TestCleanup to run code after each test has run // [TestCleanup()] // public void MyTestCleanup() { } // #endregion static Client GetTestClient() { DomainContext ctx = new DomainContext(); var result = ctx.Client.Where(n => n.Id == new Guid("3E7930E4-524B-4814-AF47-90E39D5E555A")).Single(); return result; }
public static XElement CreateAccount(string email, string password, string group, string newsletter, string fullname, string company, string address, string citystatezip, string phone, string website, int importTypeId, bool enableUpdates, bool active, XElement clientParameters) { Contract.Requires(!String.IsNullOrEmpty(group)); IClient newClient = null; Dictionary<string, string> parameters = new Dictionary<string, string>(); parameters.Add("apiusername", "x6knh8g83dsc4dqr"); parameters.Add("apipassword", "9keyceyf3mtf7tza"); if (!string.IsNullOrEmpty(email)) parameters.Add("email", email.Trim()); if (!string.IsNullOrEmpty(password)) parameters.Add("password", password.Trim()); if (!string.IsNullOrEmpty(group)) parameters.Add("group", group.Trim()); if (!string.IsNullOrEmpty(fullname)) parameters.Add("mailmerge_fullname", fullname.Trim()); if (!string.IsNullOrEmpty(company)) parameters.Add("mailmerge_company", company.Trim()); if (!string.IsNullOrEmpty(newsletter)) parameters.Add("mailmerge_newsletter", newsletter.Trim()); if (!string.IsNullOrEmpty(address)) parameters.Add("mailmerge_address", address.Trim()); if (!string.IsNullOrEmpty(citystatezip)) parameters.Add("mailmerge_citystatezip", citystatezip.Trim()); if (!string.IsNullOrEmpty(phone)) parameters.Add("mailmerge_phone", phone.Trim()); parameters.Add("mailmerge_email", email.Trim()); if (!string.IsNullOrEmpty(website)) parameters.Add("mailmerge_website", website.Trim()); XElement response = CommonService.AllClientsRequest("AddAccount.aspx", parameters); if (response.Descendants("apikey").Count() > 0) { using (DomainContext ctx = new DomainContext()) { Manager mgr = new Manager(ctx); ClientManager clientManager = new ClientManager(mgr); newClient = clientManager.GetNewClient(); newClient.AccountId = int.Parse(response.Descendants("accountid").Single().Value); newClient.Active = active; newClient.ApiKey = response.Descendants("apikey").Single().Value; newClient.Company = company.Trim(); newClient.Created = System.DateTime.Now; newClient.Updated = System.DateTime.Now; newClient.ImportTypeId = importTypeId; newClient.EnableUpdates = enableUpdates; newClient.ClientParameters = clientParameters; newClient.ClientProperties.AllClientsUsername = email; newClient.ClientProperties.AllClientsPassword = password; ctx.SubmitChanges(); } } else { if (response.Descendants("error").Count() > 0) throw new AccountSetupException(String.Format("All Clients Returned an error on account creation: {0}", response.Descendants("error").First().Value)); } return response; }
public static List<AllClientsContactExport> SaveContacts(List<AllClientsContactExport> contactExports) { List<AllClientsContactExport> errors = new List<AllClientsContactExport>(); if (contactExports.Count > 0) { using (DomainContext ctx = new DomainContext()) { Manager mgr = new Manager(ctx); ContactManager contactManager = new ContactManager(mgr); ClientManager clientManager = new ClientManager(mgr); IClient client = clientManager.GetByCompany(contactExports.First().Account.ClientName); contactExports.ForEach(export => { try { XElement element = new XElement("Export"); XElement account = Common.Services.CommonService.ToXml(typeof(AllClientsAccount), export.Account); XElement webform = Common.Services.CommonService.ToXml(typeof(AllClientsWebform), export.AllClientsWebform); XElement contact = Common.Services.CommonService.ToXml(typeof(AllClientsContact), export.Contact); element.Add(account); element.Add(webform); element.Add(contact); IContact newContact = contactManager.GetNewContact(); newContact.ContactElement = element; newContact.ClientId = client.Id; } catch { errors.Add(export); } finally { ctx.SubmitChanges(); } }); } } return errors; }
public void DeleteClient(Guid Id) { using (DomainContext ctx = new DomainContext()) { Manager mgr = new Manager(ctx); ClientManager clientManager = new ClientManager(mgr); var existing = clientManager.GetByKey(Id); if (existing != null) { clientManager.DeleteClient(existing); ctx.SubmitChanges(); } } }
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); }
public object GetClientParametersObject(ClientModel model) { object result = null; switch (model.ImportTypeId) { case 1: if (model.ClientParameters == null) { using (DomainContext ctx = new DomainContext()) { Manager mgr = new Manager(ctx); var existingProperties = ctx.Client.SingleOrDefault(x => x.Id == model.Id); if (existingProperties != null) { model.ClientParameters = existingProperties.ClientParameters; result = new MindBodyParameters { StudioID = model.ClientParameters.Element("StudioID").Value, Sourcename = model.ClientParameters.Element("Sourcename").Value, Password = model.ClientParameters.Element("Password").Value }; } else { result = new MindBodyParameters(); } } } break; default: break; } return result; }
public ActionResult PasswordRecovery(string email) { try { string password = string.Empty; using (var ctx = new DomainContext()) { var account = ctx.ClientProperties.SingleOrDefault(n => n.AllClientsUsername.ToLower() == email.ToLower()); ViewData.Add("Email", email); ViewData.Add("Result", 2); if (account != null) { password = account.AllClientsPassword; var emailTemplate = String.Format("Your password is {0}", password); string fromEmail = ConfigurationManager.AppSettings["SupportEmail"].ToString(); string toEmail = account.AllClientsUsername; var message = new System.Net.Mail.MailMessage(fromEmail, toEmail); message.Subject = "Fitness Auto Pilot Request"; message.Body = emailTemplate; var smtp = new System.Net.Mail.SmtpClient(); var enableSsl = false; bool.TryParse(System.Configuration.ConfigurationManager.AppSettings["EnableSSL"], out enableSsl); smtp.EnableSsl = enableSsl; smtp.Send(message); ViewData["Result"] = 0; } else { ViewData["Result"] = 1; } } } catch { ViewData["Result"] = 2; } return View(); }
public bool SignIn(AIM.Administration.Models.AllClientsAccountModel allClientsModel ) { var result = false; ClientProperties clientProperties = null; using( DomainContext ctx = new DomainContext() ) { clientProperties = ctx.ClientProperties.SingleOrDefault( x => x.AllClientsUsername == allClientsModel.UserName&& x.AllClientsPassword == allClientsModel.Password ); } if( clientProperties != null ) { allClientsModel.ClientId = clientProperties.ClientId; PostSubmitter submitter = new PostSubmitter(); submitter.Url = "https://www.aimscrm.com/api/ApiSignOn.aspx"; submitter.Type = global::Common.Messaging.PostTypeEnum.Post; submitter.PostEncoding = global::Common.Messaging.PostEncodingEnum.URLEncoded; submitter.PostItems.Add( "email", allClientsModel.UserName ); submitter.PostItems.Add( "password", allClientsModel.Password ); submitter.PostItems.Add( "url", "Home.aspx" ); result = !submitter.Post().Contains( "Invalid Email/Password" ); } if( result ) { SignIn( allClientsModel.ClientUsername, false ); System.Web.HttpContext.Current.Session.Add( "allClientsAccountModel", allClientsModel ); } return result; }