/// <summary>
        /// Creates initial, default action mapping data.
        /// </summary>
        /// <returns>True if needed to create data, false otherwise</returns>
        public async Task<bool> InitializeDataIfNecessaryAsync()
        {
            var existingMappings = await _actionMappingRepository.GetAllMappingsAsync();

            if (existingMappings.Count > 0)
            {
                return false;
            }

            var am1 = new ActionMapping()
            {
                RuleOutput = _ruleOutputAlarmTemp,
                ActionId = "Send Message"
            };

            await _actionMappingRepository.SaveMappingAsync(am1);

            var am2 = new ActionMapping()
            {
                RuleOutput = _ruleOutputAlarmHumidity,
                ActionId = "Raise Alarm"
            };

            await _actionMappingRepository.SaveMappingAsync(am2);

            return true;
        }
        public async Task SaveMappingAsync(ActionMapping m)
        {
            ActionMappingBlobResults existingResults = await GetActionsAndEtagAsync();

            List<ActionMapping> existingMappings = existingResults.ActionMappings;

            // look for the new mapping
            ActionMapping found = existingMappings.FirstOrDefault(a => a.RuleOutput.ToLower() == m.RuleOutput.ToLower());

            if (found == null)
            {
                // add the new mapping
                existingMappings.Add(m);
            }
            else
            {
                // update the ActionId for the found mapping
                found.ActionId = m.ActionId;
            }

            // now save back to the blob
            string newJsonData = JsonConvert.SerializeObject(existingMappings);
            byte[] newBytes = Encoding.UTF8.GetBytes(newJsonData);

            await _blobStorageManager.UploadFromByteArrayAsync(
                _blobName,
                newBytes,
                0,
                newBytes.Length,
                AccessCondition.GenerateIfMatchCondition(existingResults.ETag),
                null,
                null);
        }
        public async Task UpdateAction(string ruleOutput, string actionId)
        {
            var actionMapping = new ActionMapping();

            actionMapping.RuleOutput = ruleOutput;
            actionMapping.ActionId = actionId;
            await _actionMappingLogic.SaveMappingAsync(actionMapping);
        }
        public async Task<HttpResponseMessage> UpdateActionAsync(string ruleOutput, string actionId)
        {
            var actionMapping = new ActionMapping();
            actionMapping.RuleOutput = ruleOutput;
            actionMapping.ActionId = actionId;

            return await GetServiceResponseAsync(async () =>
            {
                await _actionMappingLogic.SaveMappingAsync(actionMapping);
            });
        }
 public async Task SaveMappingAsync(ActionMapping action)
 {
     await _actionMappingRepository.SaveMappingAsync(action);   
 }