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:
@ -40,7 +40,7 @@ namespace DamageAssesment.Api.Questions.Controllers
|
||||
[Route("Questions/{id}/{language:alpha}")]
|
||||
[Route("Questions/{id:int}")]
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> GetQuestionByIdAsync(string? language,int id)
|
||||
public async Task<IActionResult> GetQuestionByIdAsync(int id, string? language)
|
||||
{
|
||||
var result = await this.questionsProvider.GetQuestionAsync(id, language);
|
||||
if (result.IsSuccess)
|
||||
|
@ -4,12 +4,12 @@ namespace DamageAssesment.Api.Questions.Interfaces
|
||||
{
|
||||
public interface IQuestionsProvider : IQuestionTypesProvider
|
||||
{
|
||||
Task<(bool IsSuccess, Models.MultiLanQuestion Question, string ErrorMessage)> GetQuestionAsync(int id, string language);
|
||||
Task<(bool IsSuccess, IEnumerable<Models.MultiLanQuestion> Questions, string ErrorMessage)> GetQuestionsAsync(string language);
|
||||
Task<(bool IsSuccess, Models.MultiLanguage Question, string ErrorMessage)> GetQuestionAsync(int id, string language);
|
||||
Task<(bool IsSuccess, IEnumerable<Models.MultiLanguage> Questions, string ErrorMessage)> GetQuestionsAsync(string language);
|
||||
Task<(bool IsSuccess, List<SurveyQuestions> SurveyQuestions, string ErrorMessage)> GetSurveyQuestionAsync(int surveyId,string language);
|
||||
Task<(bool IsSuccess, Models.MultiLanQuestion Question, string ErrorMessage)> PostQuestionAsync(Models.Question Question);
|
||||
Task<(bool IsSuccess, Models.MultiLanQuestion Question, string ErrorMessage)> UpdateQuestionAsync(Models.Question Question);
|
||||
Task<(bool IsSuccess, Models.MultiLanQuestion Question, string ErrorMessage)> DeleteQuestionAsync(int id);
|
||||
Task<(bool IsSuccess, Models.MultiLanguage Question, string ErrorMessage)> PostQuestionAsync(Models.Question Question);
|
||||
Task<(bool IsSuccess, Models.MultiLanguage Question, string ErrorMessage)> UpdateQuestionAsync(Models.Question Question);
|
||||
Task<(bool IsSuccess, Models.MultiLanguage Question, string ErrorMessage)> DeleteQuestionAsync(int id);
|
||||
|
||||
|
||||
Task<(bool IsSuccess, IEnumerable<Models.MultiLanQuestionCategory> QuestionCategories, string ErrorMessage)> GetQuestionCategoriesAsync(string? language);
|
||||
|
@ -1,29 +1,18 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace DamageAssesment.Api.Questions.Models
|
||||
namespace DamageAssesment.Api.Questions.Models
|
||||
{
|
||||
public class MultiLanQuestion: BaseQuestion
|
||||
{
|
||||
public MultiLanguage Questions { get; set; }
|
||||
}
|
||||
public class Question: BaseQuestion
|
||||
public class Question: BaseQuestion
|
||||
{
|
||||
public List<QuestionsTranslation> Questions { get; set; }
|
||||
}
|
||||
public class BaseQuestion
|
||||
{
|
||||
public int Id { get; set; }
|
||||
//public int QuestionTypeID { get; set; }
|
||||
|
||||
public string TypeText { get; set; } = string.Empty;
|
||||
|
||||
public int QuestionNumber { get; set; }
|
||||
public bool IsRequired { get; set; }
|
||||
public bool Comment { get; set; }
|
||||
|
||||
public bool Key { get; set; }
|
||||
public int? SurveyId { get; set; }
|
||||
public int CategoryId { get; set; }
|
||||
// public int? Survey_SurveyID { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -3,10 +3,10 @@
|
||||
public class QuestionsTranslation
|
||||
{
|
||||
public string QuestionText { get; set; }
|
||||
public string Language { get; set; } = "En";
|
||||
public string Language { get; set; } = "en";
|
||||
}
|
||||
public class MultiLanguage
|
||||
public class MultiLanguage : BaseQuestion
|
||||
{
|
||||
public object questionText { get; set; }
|
||||
public Dictionary<string,string> Text { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,6 @@
|
||||
public int CategoryId { get; set; }
|
||||
public string IconName { get; set; }
|
||||
public string IconLibrary { get; set; }
|
||||
public List<MultiLanQuestion> Questions { get; set; }
|
||||
public List<MultiLanguage> QuestionsText { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ namespace DamageAssesment.Api.Questions.Profiles
|
||||
{
|
||||
CreateMap<Db.Question, Models.Question>().ForMember(dest => dest.TypeText,
|
||||
opt => opt.MapFrom(src => src.QuestionType.TypeText));
|
||||
CreateMap<Db.Question, Models.MultiLanQuestion>().ForMember(dest => dest.TypeText,
|
||||
CreateMap<Db.Question, Models.MultiLanguage>().ForMember(dest => dest.TypeText,
|
||||
opt => opt.MapFrom(src => src.QuestionType.TypeText));
|
||||
CreateMap<Models.QuestionCategory, Db.QuestionCategory>();
|
||||
CreateMap<Db.QuestionCategory, Models.MultiLanQuestionCategory>();
|
||||
|
@ -2,7 +2,6 @@ using DamageAssesment.Api.Questions.Db;
|
||||
using DamageAssesment.Api.Questions.Interfaces;
|
||||
using DamageAssesment.Api.Questions.Providers;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System.Reflection;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
@ -16,7 +15,6 @@ builder.Services.AddControllers();
|
||||
builder.Services.AddScoped<IQuestionsProvider, QuestionsProvider>();
|
||||
builder.Services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());
|
||||
|
||||
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
//builder.Services.AddSwaggerGen();
|
||||
builder.Services.AddSwaggerGen(c =>
|
||||
|
@ -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