private static async Task UpdateQuestion(Question question, ILogger log) { try { var entity = await DbContext.Questions.FirstOrDefaultAsync(x => x.Id == question.QuestionId); if (entity == null) { entity = new Data.Entities.UmQuestion { Id = question.QuestionId }; UpdateQuestionEntityFromDto(entity, question); DbContext.Questions.Add(entity); } else { UpdateQuestionEntityFromDto(entity, question); DbContext.Questions.Update(entity); } int changes = await DbContext.SaveChanges(); log.LogTrace($"Changes updated {changes}"); } catch (Exception ex) { log.LogError(ex, $"Unable to update question {question.QuestionId}"); throw; } }
private static void UpdateQuestionEntityFromDto(Data.Entities.UmQuestion entity, Question dto) { entity.IsNegative = dto.IsNegative; entity.NegativeResultDisplayText = dto.NegativeResultDisplayText; entity.Order = dto.Order; entity.PositiveResultDisplayText = dto.PositiveResultDisplayText; entity.SfId = dto.SfId; entity.TraitCode = dto.TraitCode; entity.Text = dto.Texts.FirstOrDefault()?.Text; entity.LastUpdatedDt = dto.LastUpdatedDt.UtcDateTime; }