// GET: api/Settings
        public HttpResponseMessage Get(HttpRequestMessage request)
        {
            SettingsViewModel viewModel = new SettingsViewModel();
            viewModel = _service.GetSettings();

            return request.CreateResponse(HttpStatusCode.OK, viewModel);
        }
        public void SaveSettings(SettingsViewModel settings)
        {
            Settings formSettings = new Settings
            {
                AlertsEnabled = settings.AlertsEnabled,
                ContactIntervalMinutes = settings.ContactInterval,
                RefreshIntervalMinutes = settings.RefreshInterval
            };

            List<Email> emails = new List<Email>();

            string[] emailList = settings.Emails.Split(',');
            foreach (var email in emailList)
            {
                email.Trim();
                emails.Add(new Email { EmailAddress = email.Trim() });
            }

            List<Phone> phones = new List<Phone>();

            string[] phoneList = settings.Phones.Split(',');
            foreach (var phone in phoneList)
            {
                phones.Add(new Phone { PhoneNumber = phone.Trim() });
            }

            try
            {
                _settingsRepo.SaveSettings(formSettings, emails, phones, settings.Deltas);
            }
            catch (Exception err)
            {

                return;
            }
        }
        public SettingsViewModel GetSettings()
        {
            var dbFactory = new OrmLiteConnectionFactory(
                _connectionString,
                SqlServerOrmLiteDialectProvider.Instance);

            using (IDbConnection dbConnection = dbFactory.OpenDbConnection())
            {
                Dictionary<string, int> deltas = dbConnection.Dictionary<string, int>("SELECT Name, Delta FROM source");
                int refreshInterval = dbConnection.Scalar<int>("SELECT TOP 1 RefreshIntervalMinutes FROM settings");
                int contactInterval = dbConnection.Scalar<int>("SELECT TOP 1 ContactIntervalMinutes FROM settings");
                bool alertsEnabled = dbConnection.Scalar<bool>("SELECT TOP 1 AlertsEnabled FROM settings");
                List<Email> emails = dbConnection.Select<Email>("SELECT EmailAddress FROM email");
                List<Phone> phones = dbConnection.Select<Phone>("SELECT PhoneNumber FROM phone");
                dbConnection.Close();

                string emailString = string.Empty;
                string phoneString = string.Empty;

                for (int i = 0; i < emails.Count; i++)
                {
                    if (i == emails.Count - 1)
                    {
                        emailString += emails[i].EmailAddress;
                    }
                    else
                    {
                        emailString += emails[i].EmailAddress + ", ";
                    }
                }

                for (int i = 0; i < phones.Count; i++)
                {
                    if (i == phones.Count - 1)
                    {
                        phoneString += phones[i].PhoneNumber;
                    }
                    else
                    {
                        phoneString += phones[i].PhoneNumber + ", ";
                    }
                }

                SettingsViewModel settings = new SettingsViewModel
                {
                    Deltas = deltas,
                    Emails = emailString,
                    Phones = phoneString,
                    RefreshInterval = refreshInterval,
                    ContactInterval = contactInterval,
                    AlertsEnabled = alertsEnabled
                };
                return settings;
            }
        }