public async Task SaveTenantAsync(Tenant tenant)
        {
            await this.tenantBlobContainer.SaveAsync(tenant.TenantId.ToLowerInvariant(), tenant).ConfigureAwait(false);

            if (this.CacheEnabled)
            {
                await TenantCacheHelper.AddToCacheAsync(tenant.TenantId, TenantAccountTag, tenant).ConfigureAwait(false);
            }
        }
        public async Task SaveSurveyAsync(Survey survey)
        {
            if (string.IsNullOrEmpty(survey.SlugName) && string.IsNullOrEmpty(survey.Title))
            {
                throw new ArgumentNullException("survey", "The survey for saving has to have the slug or the title.");
            }

            var slugName = string.IsNullOrEmpty(survey.SlugName) ? GenerateSlug(survey.Title, 100) : survey.SlugName;

            var surveyRow = new SurveyRow
            {
                SlugName     = slugName,
                Title        = survey.Title,
                CreatedOn    = DateTime.UtcNow,
                PartitionKey = survey.TenantId
            };

            surveyRow.RowKey = string.Format(CultureInfo.InvariantCulture, "{0}_{1}", survey.TenantId, surveyRow.SlugName);

            var questionRows = new List <QuestionRow>(survey.Questions.Count);

            for (int i = 0; i < survey.Questions.Count; i++)
            {
                var question    = survey.Questions[i];
                var questionRow = new QuestionRow
                {
                    Text            = question.Text,
                    Type            = Enum.GetName(typeof(QuestionType), question.Type),
                    PossibleAnswers = question.PossibleAnswers
                };

                questionRow.PartitionKey = surveyRow.RowKey;
                questionRow.RowKey       = string.Format(CultureInfo.InvariantCulture, "{0}_{1}", DateTime.UtcNow.GetFormatedTicks(), i.ToString("D3"));

                questionRows.Add(questionRow);
            }

            //// First add the questions
            await this.questionTable.AddAsync(questionRows);

            try
            {
                //// Then add the survey
                //// If this fails, the questions may end up orphan but data will be consistent for the user
                await this.surveyTable.AddAsync(surveyRow);

                if (this.CacheEnabled)
                {
                    await TenantCacheHelper.AddToCacheAsync(survey.TenantId, slugName, survey).ConfigureAwait(false);
                }
            }

            //TODO: update this catch for Azure Table client SDK
            catch (DataServiceRequestException ex)
            {
                TraceHelper.TraceError(ex.TraceInformation());

                var dataServiceClientException = ex.InnerException as DataServiceClientException;
                if (dataServiceClientException != null)
                {
                    if (dataServiceClientException.StatusCode == 409)
                    {
                        await this.questionTable.DeleteAsync(questionRows);

                        throw;
                    }
                }

                throw;
            }
        }