forked from MDCPS/DamageAssessment_Backend
Update survey response, adding EmployeeId , Location Id as int, adjust end point for ansers submission in batch
This commit is contained in:
@ -2,11 +2,7 @@
|
||||
using DamageAssesment.Api.Questions.Db;
|
||||
using DamageAssesment.Api.Questions.Interfaces;
|
||||
using DamageAssesment.Api.Questions.Models;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Internal;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace DamageAssesment.Api.Questions.Providers
|
||||
{
|
||||
@ -130,7 +126,7 @@ namespace DamageAssesment.Api.Questions.Providers
|
||||
}
|
||||
return QuestionTranslations;
|
||||
}
|
||||
public MultiLanguage CreateMultiLanguageObject(List<Models.QuestionsTranslation> questions)
|
||||
public Dictionary<string, string> CreateMultiLanguageObject(List<Models.QuestionsTranslation> questions)
|
||||
{
|
||||
MultiLanguage MultiLanguage = new MultiLanguage();
|
||||
Dictionary<string, string> dict = new Dictionary<string, string>();
|
||||
@ -138,10 +134,10 @@ namespace DamageAssesment.Api.Questions.Providers
|
||||
{
|
||||
dict.Add(item.Language, item.QuestionText);
|
||||
}
|
||||
MultiLanguage.questionText = dict;
|
||||
return MultiLanguage;
|
||||
//MultiLanguage.questionText = dict;
|
||||
return dict;
|
||||
}
|
||||
public async Task<(bool IsSuccess, IEnumerable<Models.MultiLanQuestion> Questions, string ErrorMessage)> GetQuestionsAsync(string language)
|
||||
public async Task<(bool IsSuccess, IEnumerable<Models.MultiLanguage> Questions, string ErrorMessage)> GetQuestionsAsync(string language)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -151,10 +147,10 @@ namespace DamageAssesment.Api.Questions.Providers
|
||||
{
|
||||
|
||||
//logger?.LogInformation($"{question} customer(s) found");
|
||||
var result = mapper.Map<IEnumerable<Db.Question>, IEnumerable<Models.MultiLanQuestion>>(questions);
|
||||
foreach (var question in result)
|
||||
var result = mapper.Map<IEnumerable<Db.Question>, IEnumerable<Models.MultiLanguage>>(questions);
|
||||
foreach (var item in result)
|
||||
{
|
||||
question.Questions = CreateMultiLanguageObject(GetQuestionsTranslations(question.Id, language));
|
||||
item.Text = CreateMultiLanguageObject(GetQuestionsTranslations(item.Id, language));
|
||||
}
|
||||
return (true, result, null);
|
||||
}
|
||||
@ -166,7 +162,7 @@ namespace DamageAssesment.Api.Questions.Providers
|
||||
return (false, null, ex.Message);
|
||||
}
|
||||
}
|
||||
public async Task<(bool IsSuccess, Models.MultiLanQuestion Question, string ErrorMessage)> GetQuestionAsync(int id, string language)
|
||||
public async Task<(bool IsSuccess, Models.MultiLanguage Question, string ErrorMessage)> GetQuestionAsync(int id, string language)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -175,8 +171,8 @@ namespace DamageAssesment.Api.Questions.Providers
|
||||
if (question != null)
|
||||
{
|
||||
logger?.LogInformation($"{question} customer(s) found");
|
||||
var result = mapper.Map<Db.Question, Models.MultiLanQuestion>(question);
|
||||
result.Questions = CreateMultiLanguageObject(GetQuestionsTranslations(id, language));
|
||||
var result = mapper.Map<Db.Question, Models.MultiLanguage>(question);
|
||||
result.Text = CreateMultiLanguageObject(GetQuestionsTranslations(id, language));
|
||||
return (true, result, null);
|
||||
}
|
||||
return (false, null, "Not found");
|
||||
@ -187,11 +183,11 @@ namespace DamageAssesment.Api.Questions.Providers
|
||||
return (false, null, ex.Message);
|
||||
}
|
||||
}
|
||||
public List<Models.MultiLanQuestion> GetSurveyQuestion(List<Models.MultiLanQuestion> questions, string language)
|
||||
public List<Models.MultiLanguage> GetSurveyQuestion(List<Models.MultiLanguage> questions, string language)
|
||||
{
|
||||
foreach (var item in questions)
|
||||
{
|
||||
item.Questions = CreateMultiLanguageObject(GetQuestionsTranslations(item.Id, language));
|
||||
item.Text = CreateMultiLanguageObject(GetQuestionsTranslations(item.Id, language));
|
||||
}
|
||||
return questions;
|
||||
}
|
||||
@ -214,7 +210,7 @@ namespace DamageAssesment.Api.Questions.Providers
|
||||
CategoryId = item.Id,
|
||||
IconLibrary = item.IconLibrary,
|
||||
IconName = item.IconName,
|
||||
Questions = GetSurveyQuestion(mapper.Map<List<Db.Question>, List<Models.MultiLanQuestion>>(questions.Where(a => a.CategoryId == item.Id).ToList()), language)
|
||||
QuestionsText = GetSurveyQuestion(mapper.Map<List<Db.Question>, List<Models.MultiLanguage>>(questions.Where(a => a.CategoryId == item.Id).ToList()), language)
|
||||
});
|
||||
}
|
||||
|
||||
@ -229,7 +225,7 @@ namespace DamageAssesment.Api.Questions.Providers
|
||||
return (false, null, ex.Message);
|
||||
}
|
||||
}
|
||||
public async Task<(bool IsSuccess, Models.MultiLanQuestion Question, string ErrorMessage)> PostQuestionAsync(Models.Question Question)
|
||||
public async Task<(bool IsSuccess, Models.MultiLanguage Question, string ErrorMessage)> PostQuestionAsync(Models.Question Question)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -242,8 +238,8 @@ namespace DamageAssesment.Api.Questions.Providers
|
||||
questionDbContext.QuestionsTranslations.AddRange(dbquestiontranslation);
|
||||
questionDbContext.SaveChanges();
|
||||
Question.Id = dbquestion.Id;
|
||||
var result = mapper.Map<Db.Question, Models.MultiLanQuestion>(dbquestion);
|
||||
result.Questions = CreateMultiLanguageObject(GetQuestionsTranslations(result.Id,""));
|
||||
var result = mapper.Map<Db.Question, Models.MultiLanguage>(dbquestion);
|
||||
result.Text = CreateMultiLanguageObject(GetQuestionsTranslations(result.Id,""));
|
||||
return (true, result, null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -252,7 +248,7 @@ namespace DamageAssesment.Api.Questions.Providers
|
||||
return (false, null, ex.Message);
|
||||
}
|
||||
}
|
||||
public async Task<(bool IsSuccess, Models.MultiLanQuestion Question, string ErrorMessage)> UpdateQuestionAsync(Models.Question Question)
|
||||
public async Task<(bool IsSuccess, Models.MultiLanguage Question, string ErrorMessage)> UpdateQuestionAsync(Models.Question Question)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -266,8 +262,8 @@ namespace DamageAssesment.Api.Questions.Providers
|
||||
dbquestiontranslation.ForEach(i => i.QuestionId = dbquestion.Id);
|
||||
questionDbContext.QuestionsTranslations.AddRange(dbquestiontranslation);
|
||||
questionDbContext.SaveChanges();
|
||||
var result = mapper.Map<Db.Question, Models.MultiLanQuestion>(dbquestion);
|
||||
result.Questions = CreateMultiLanguageObject(GetQuestionsTranslations(result.Id, ""));
|
||||
var result = mapper.Map<Db.Question, Models.MultiLanguage>(dbquestion);
|
||||
result.Text = CreateMultiLanguageObject(GetQuestionsTranslations(result.Id, ""));
|
||||
return (true, result, null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -277,7 +273,7 @@ namespace DamageAssesment.Api.Questions.Providers
|
||||
return (false, null, ex.Message);
|
||||
}
|
||||
}
|
||||
public async Task<(bool IsSuccess, Models.MultiLanQuestion Question, string ErrorMessage)> DeleteQuestionAsync(int id)
|
||||
public async Task<(bool IsSuccess, Models.MultiLanguage Question, string ErrorMessage)> DeleteQuestionAsync(int id)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -285,8 +281,8 @@ namespace DamageAssesment.Api.Questions.Providers
|
||||
|
||||
if (question != null)
|
||||
{
|
||||
var result = mapper.Map<Db.Question, Models.MultiLanQuestion>(question);
|
||||
result.Questions = CreateMultiLanguageObject(GetQuestionsTranslations(result.Id, ""));
|
||||
var result = mapper.Map<Db.Question, Models.MultiLanguage>(question);
|
||||
result.Text = CreateMultiLanguageObject(GetQuestionsTranslations(result.Id, ""));
|
||||
questionDbContext.Questions.Remove(question);
|
||||
questionDbContext.SaveChanges();
|
||||
return (true, result, $"QuestionID {id} deleted Successfuly");
|
||||
|
Reference in New Issue
Block a user