private option_translation_versions MapVersions(option_translations optionTranslations) { return(new option_translation_versions() { LanguageId = optionTranslations.LanguageId, OptionId = optionTranslations.OptionId, WorkflowState = optionTranslations.WorkflowState, OptionTranslationId = optionTranslations.Id, Name = optionTranslations.Name, CreatedAt = optionTranslations.CreatedAt, UpdatedAt = optionTranslations.UpdatedAt, Version = optionTranslations.Version, MicrotingUid = optionTranslations.MicrotingUid }); }
public async Task Delete(MicrotingDbContext dbContext) { option_translations option_translation = await dbContext.OptionTranslations.SingleOrDefaultAsync(x => x.Id == Id); if (option_translation == null) { throw new NullReferenceException($"Could not find notification with id {Id}"); } option_translation.WorkflowState = Constants.Constants.WorkflowStates.Removed; if (dbContext.ChangeTracker.HasChanges()) { option_translation.UpdatedAt = DateTime.UtcNow; option_translation.Version += 1; dbContext.OptionTranslationVersions.Add(MapVersions(option_translation)); await dbContext.SaveChangesAsync().ConfigureAwait(false); } }
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); } }
public async Task Update(MicrotingDbContext dbContext) { option_translations optionTranslation = await dbContext.OptionTranslations.SingleOrDefaultAsync(x => x.Id == Id); if (optionTranslation == null) { throw new NullReferenceException($"Could not find option_translation with id {Id}"); } optionTranslation.WorkflowState = WorkflowState; optionTranslation.LanguageId = LanguageId; optionTranslation.OptionId = OptionId; optionTranslation.MicrotingUid = MicrotingUid; optionTranslation.Name = Name; if (dbContext.ChangeTracker.HasChanges()) { optionTranslation.UpdatedAt = DateTime.UtcNow; optionTranslation.Version += 1; dbContext.OptionTranslationVersions.Add(MapVersions(optionTranslation)); await dbContext.SaveChangesAsync().ConfigureAwait(false); } }