Exemplo n.º 1
0
        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;
        }
Exemplo n.º 2
0
 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();
         }
     }
 }
Exemplo n.º 3
0
        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;

        }
Exemplo n.º 4
0
        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();
                }
            }
        }
Exemplo n.º 5
0
 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;
 }
Exemplo n.º 6
0
        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;
        }
Exemplo n.º 7
0
        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();
        }
Exemplo n.º 8
0
        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;

        }