Exemple #1
0
        public async Task Update(MicrotingDbContext dbContext)
        {
            options option = await dbContext.options.FirstOrDefaultAsync(x => x.Id == Id);

            if (option == null)
            {
                throw new NullReferenceException($"Could not find option with Id: {Id}");
            }

            option.QuestionId         = QuestionId;
            option.Weight             = Weight;
            option.WeightValue        = WeightValue;
            option.NextQuestionId     = NextQuestionId;
            option.ContinuousOptionId = ContinuousOptionId;
            option.OptionsIndex       = OptionsIndex;
            option.DisplayIndex       = DisplayIndex;

            if (dbContext.ChangeTracker.HasChanges())
            {
                Version  += 1;
                UpdatedAt = DateTime.UtcNow;

                dbContext.option_versions.Add(MapVersions(option));
                await dbContext.SaveChangesAsync().ConfigureAwait(false);
            }
        }
Exemple #2
0
 private option_versions MapVersions(options option)
 {
     return(new option_versions
     {
         QuestionId = option.QuestionId,
         Weight = option.Weight,
         WeightValue = option.WeightValue,
         NextQuestionId = option.NextQuestionId,
         ContinuousOptionId = option.ContinuousOptionId,
         OptionsIndex = option.OptionsIndex,
         OptionId = option.Id,
         CreatedAt = option.CreatedAt,
         Version = option.Version,
         UpdatedAt = option.UpdatedAt,
         WorkflowState = option.WorkflowState,
         MicrotingUid = option.MicrotingUid,
         DisplayIndex = option.DisplayIndex
     });
 }
Exemple #3
0
        public async Task Delete(MicrotingDbContext dbContext)
        {
            options option = await dbContext.options.FirstOrDefaultAsync(x => x.Id == Id);

            if (option == null)
            {
                throw new NullReferenceException($"Could not find option with Id: {Id}");
            }

            option.WorkflowState = Constants.Constants.WorkflowStates.Removed;

            if (dbContext.ChangeTracker.HasChanges())
            {
                Version  += 1;
                UpdatedAt = DateTime.UtcNow;

                dbContext.option_versions.Add(MapVersions(option));
                await dbContext.SaveChangesAsync().ConfigureAwait(false);
            }
        }
Exemple #4
0
        private async Task CreateSpecialOption(MicrotingDbContext dbContext, int weight, int weightedValue, string text, int languageId, int optionIndex)
        {
            var result = (from ot in dbContext.OptionTranslations
                          join o in dbContext.options
                          on ot.OptionId equals o.Id
                          where o.Weight == weight &&
                          o.WeightValue == weightedValue &&
                          ot.Name == text &&
                          ot.LanguageId == languageId &&
                          o.QuestionId == this.Id
                          select new
            {
                Id = o.Id
            }).ToList();

            if (!result.Any())
            {
                options option = new options()
                {
                    Weight       = weight,
                    WeightValue  = weightedValue,
                    OptionsIndex = optionIndex,
                    QuestionId   = this.Id
                };

                await option.Create(dbContext).ConfigureAwait(false);

                option_translations optionTranslation = new option_translations()
                {
                    OptionId   = option.Id,
                    Name       = text,
                    LanguageId = languageId
                };
                await optionTranslation.Create(dbContext).ConfigureAwait(false);
            }
        }