2023-08-15 22:52:30 -05:00
using AutoMapper ;
using DamageAssesment.Api.Questions.Db ;
using DamageAssesment.Api.Questions.Interfaces ;
using DamageAssesment.Api.Questions.Models ;
using Microsoft.EntityFrameworkCore ;
namespace DamageAssesment.Api.Questions.Providers
{
public class QuestionsProvider : IQuestionsProvider , IQuestionTypesProvider
{
private QuestionDbContext questionDbContext ;
private ILogger < QuestionsProvider > logger ;
private IMapper mapper ;
public QuestionsProvider ( QuestionDbContext questionDbContext , ILogger < QuestionsProvider > logger , IMapper mapper )
{
this . questionDbContext = questionDbContext ;
this . logger = logger ;
this . mapper = mapper ;
2023-10-06 17:22:37 -05:00
// SeedData();
2023-08-15 22:52:30 -05:00
}
2023-09-04 20:31:41 -05:00
public void SeedData ( )
2023-08-15 22:52:30 -05:00
{
if ( ! questionDbContext . QuestionTypes . Any ( ) )
{
2023-10-04 14:03:59 -05:00
questionDbContext . QuestionTypes . Add ( new Db . QuestionType ( ) { TypeText = "RadioButton" } ) ;
questionDbContext . QuestionTypes . Add ( new Db . QuestionType ( ) { TypeText = "CheckBox" } ) ;
questionDbContext . QuestionTypes . Add ( new Db . QuestionType ( ) { TypeText = "TextBox" } ) ;
2023-08-15 22:52:30 -05:00
questionDbContext . SaveChanges ( ) ;
}
if ( ! questionDbContext . QuestionCategories . Any ( ) )
{
2023-10-06 17:22:37 -05:00
questionDbContext . QuestionCategories . Add ( new Db . QuestionCategory ( ) { IconName = "Flooding" , IconLibrary = "https://example.com/images/img1.png" } ) ;
2023-10-04 14:03:59 -05:00
questionDbContext . QuestionCategories . Add ( new Db . QuestionCategory ( ) { IconName = "Electrical" , IconLibrary = "https://example.com/images/img2.png" } ) ;
questionDbContext . QuestionCategories . Add ( new Db . QuestionCategory ( ) { IconName = "Structural" , IconLibrary = "https://example.com/images/img3.png" } ) ;
questionDbContext . QuestionCategories . Add ( new Db . QuestionCategory ( ) { IconName = "Utility" , IconLibrary = "https://example.com/images/img4.png" } ) ;
questionDbContext . QuestionCategories . Add ( new Db . QuestionCategory ( ) { IconName = "Debris" , IconLibrary = "https://example.com/images/img5.png" } ) ;
2023-09-08 14:40:06 -05:00
questionDbContext . SaveChanges ( ) ;
}
if ( ! questionDbContext . CategoryTranslations . Any ( ) )
{
2023-10-04 14:03:59 -05:00
questionDbContext . CategoryTranslations . Add ( new Db . CategoryTranslation ( ) { CategoryId = 1 , Title = "Flooding" , Language = "en" } ) ;
questionDbContext . CategoryTranslations . Add ( new Db . CategoryTranslation ( ) { CategoryId = 2 , Title = "Electrical" , Language = "en" } ) ;
questionDbContext . CategoryTranslations . Add ( new Db . CategoryTranslation ( ) { CategoryId = 3 , Title = "Structural" , Language = "en" } ) ;
questionDbContext . CategoryTranslations . Add ( new Db . CategoryTranslation ( ) { CategoryId = 4 , Title = "Utility" , Language = "en" } ) ;
questionDbContext . CategoryTranslations . Add ( new Db . CategoryTranslation ( ) { CategoryId = 5 , Title = "Debris" , Language = "en" } ) ;
questionDbContext . CategoryTranslations . Add ( new Db . CategoryTranslation ( ) { CategoryId = 1 , Title = "Inondation" , Language = "fr" } ) ;
questionDbContext . CategoryTranslations . Add ( new Db . CategoryTranslation ( ) { CategoryId = 2 , Title = "Électrique" , Language = "fr" } ) ;
questionDbContext . CategoryTranslations . Add ( new Db . CategoryTranslation ( ) { CategoryId = 3 , Title = "De construction" , Language = "fr" } ) ;
questionDbContext . CategoryTranslations . Add ( new Db . CategoryTranslation ( ) { CategoryId = 4 , Title = "Utilitaire" , Language = "fr" } ) ;
questionDbContext . CategoryTranslations . Add ( new Db . CategoryTranslation ( ) { CategoryId = 5 , Title = "Débris" , Language = "fr" } ) ;
questionDbContext . CategoryTranslations . Add ( new Db . CategoryTranslation ( ) { CategoryId = 1 , Title = "Inundación" , Language = "es" } ) ;
questionDbContext . CategoryTranslations . Add ( new Db . CategoryTranslation ( ) { CategoryId = 2 , Title = "Eléctrica" , Language = "es" } ) ;
questionDbContext . CategoryTranslations . Add ( new Db . CategoryTranslation ( ) { CategoryId = 3 , Title = "Estructural" , Language = "es" } ) ;
questionDbContext . CategoryTranslations . Add ( new Db . CategoryTranslation ( ) { CategoryId = 4 , Title = "Utilidad" , Language = "es" } ) ;
questionDbContext . CategoryTranslations . Add ( new Db . CategoryTranslation ( ) { CategoryId = 5 , Title = "Escombros" , Language = "es" } ) ;
2023-08-15 22:52:30 -05:00
questionDbContext . SaveChanges ( ) ;
}
2023-10-06 17:22:37 -05:00
if ( ! questionDbContext . Questions . Any ( ) )
{
var question1 = new Db . Question ( ) { QuestionTypeId = 1 , SurveyId = 1 , QuestionNumber = 1 , IsRequired = true , Comment = false , Key = true , CategoryId = 1 } ;
2023-10-11 18:24:50 -05:00
var question2 = new Db . Question ( ) { QuestionTypeId = 1 , SurveyId = 1 , QuestionNumber = 2 , IsRequired = false , Comment = true , Key = false , CategoryId = 2 } ;
2023-10-06 17:22:37 -05:00
var question3 = new Db . Question ( ) { QuestionTypeId = 1 , SurveyId = 2 , QuestionNumber = 1 , IsRequired = true , Comment = false , Key = true , CategoryId = 1 } ;
2023-10-11 18:24:50 -05:00
var question4 = new Db . Question ( ) { QuestionTypeId = 1 , SurveyId = 2 , QuestionNumber = 2 , IsRequired = false , Comment = true , Key = false , CategoryId = 2 } ;
2023-10-11 14:33:10 -05:00
var question5 = new Db . Question ( ) { QuestionTypeId = 1 , SurveyId = 3 , QuestionNumber = 1 , IsRequired = true , Comment = false , Key = true , CategoryId = 1 } ;
2023-10-11 18:24:50 -05:00
var question6 = new Db . Question ( ) { QuestionTypeId = 1 , SurveyId = 3 , QuestionNumber = 2 , IsRequired = false , Comment = true , Key = false , CategoryId = 2 } ;
var question7 = new Db . Question ( ) { QuestionTypeId = 1 , SurveyId = 3 , QuestionNumber = 1 , IsRequired = true , Comment = false , Key = true , CategoryId = 3 } ;
var question8 = new Db . Question ( ) { QuestionTypeId = 1 , SurveyId = 3 , QuestionNumber = 2 , IsRequired = false , Comment = true , Key = false , CategoryId = 4 } ;
var question9 = new Db . Question ( ) { QuestionTypeId = 1 , SurveyId = 3 , QuestionNumber = 1 , IsRequired = true , Comment = true , Key = true , CategoryId = 5 } ;
2023-10-11 14:33:10 -05:00
var question10 = new Db . Question ( ) { QuestionTypeId = 1 , SurveyId = 3 , QuestionNumber = 2 , IsRequired = false , Comment = false , Key = true , CategoryId = 1 } ;
2023-10-11 18:24:50 -05:00
var question11 = new Db . Question ( ) { QuestionTypeId = 1 , SurveyId = 3 , QuestionNumber = 1 , IsRequired = true , Comment = false , Key = false , CategoryId = 2 } ;
var question12 = new Db . Question ( ) { QuestionTypeId = 1 , SurveyId = 3 , QuestionNumber = 2 , IsRequired = false , Comment = true , Key = true , CategoryId = 3 } ;
var question13 = new Db . Question ( ) { QuestionTypeId = 1 , SurveyId = 3 , QuestionNumber = 1 , IsRequired = true , Comment = false , Key = true , CategoryId = 4 } ;
var question14 = new Db . Question ( ) { QuestionTypeId = 1 , SurveyId = 3 , QuestionNumber = 2 , IsRequired = false , Comment = true , Key = false , CategoryId = 5 } ;
2023-10-11 14:33:10 -05:00
var question15 = new Db . Question ( ) { QuestionTypeId = 1 , SurveyId = 3 , QuestionNumber = 1 , IsRequired = true , Comment = false , Key = false , CategoryId = 1 } ;
2023-10-11 18:24:50 -05:00
var question16 = new Db . Question ( ) { QuestionTypeId = 1 , SurveyId = 3 , QuestionNumber = 2 , IsRequired = false , Comment = true , Key = true , CategoryId = 2 } ;
var question17 = new Db . Question ( ) { QuestionTypeId = 1 , SurveyId = 3 , QuestionNumber = 1 , IsRequired = true , Comment = false , Key = false , CategoryId = 3 } ;
var question18 = new Db . Question ( ) { QuestionTypeId = 1 , SurveyId = 3 , QuestionNumber = 2 , IsRequired = false , Comment = true , Key = false , CategoryId = 4 } ;
var question19 = new Db . Question ( ) { QuestionTypeId = 1 , SurveyId = 3 , QuestionNumber = 1 , IsRequired = true , Comment = false , Key = true , CategoryId = 5 } ;
2023-10-11 14:33:10 -05:00
var question20 = new Db . Question ( ) { QuestionTypeId = 1 , SurveyId = 3 , QuestionNumber = 2 , IsRequired = false , Comment = true , Key = false , CategoryId = 1 } ;
2023-10-11 18:24:50 -05:00
var question21 = new Db . Question ( ) { QuestionTypeId = 1 , SurveyId = 3 , QuestionNumber = 1 , IsRequired = true , Comment = false , Key = true , CategoryId = 2 } ;
var question22 = new Db . Question ( ) { QuestionTypeId = 1 , SurveyId = 3 , QuestionNumber = 2 , IsRequired = false , Comment = true , Key = true , CategoryId = 3 } ;
2023-10-06 17:22:37 -05:00
questionDbContext . Questions . Add ( question1 ) ;
questionDbContext . Questions . Add ( question2 ) ;
questionDbContext . Questions . Add ( question3 ) ;
questionDbContext . Questions . Add ( question4 ) ;
2023-10-11 14:33:10 -05:00
questionDbContext . Questions . Add ( question5 ) ;
questionDbContext . Questions . Add ( question6 ) ;
questionDbContext . Questions . Add ( question7 ) ;
questionDbContext . Questions . Add ( question8 ) ;
questionDbContext . Questions . Add ( question9 ) ;
questionDbContext . Questions . Add ( question10 ) ;
questionDbContext . Questions . Add ( question11 ) ;
questionDbContext . Questions . Add ( question12 ) ;
questionDbContext . Questions . Add ( question13 ) ;
questionDbContext . Questions . Add ( question14 ) ;
questionDbContext . Questions . Add ( question15 ) ;
questionDbContext . Questions . Add ( question16 ) ;
questionDbContext . Questions . Add ( question17 ) ;
questionDbContext . Questions . Add ( question18 ) ;
questionDbContext . Questions . Add ( question19 ) ;
questionDbContext . Questions . Add ( question20 ) ;
questionDbContext . Questions . Add ( question21 ) ;
questionDbContext . Questions . Add ( question22 ) ;
2023-10-06 17:22:37 -05:00
questionDbContext . SaveChanges ( ) ;
}
if ( ! questionDbContext . QuestionsTranslations . Any ( ) )
{
questionDbContext . QuestionsTranslations . Add ( new Db . QuestionsTranslation ( ) { QuestionId = 1 , QuestionText = "Can You Open ?" , Language = "en" } ) ;
questionDbContext . QuestionsTranslations . Add ( new Db . QuestionsTranslation ( ) { QuestionId = 1 , QuestionText = "Peux-tu ouvrir ?" , Language = "fr" } ) ;
questionDbContext . QuestionsTranslations . Add ( new Db . QuestionsTranslation ( ) { QuestionId = 1 , QuestionText = "Puedes abrir ?" , Language = "es" } ) ;
questionDbContext . QuestionsTranslations . Add ( new Db . QuestionsTranslation ( ) { QuestionId = 2 , QuestionText = "Are the grounds flooded ?" , Language = "en" } ) ;
questionDbContext . QuestionsTranslations . Add ( new Db . QuestionsTranslation ( ) { QuestionId = 2 , QuestionText = "Les terrains sont-ils inondés ?" , Language = "fr" } ) ;
questionDbContext . QuestionsTranslations . Add ( new Db . QuestionsTranslation ( ) { QuestionId = 2 , QuestionText = "¿Están inundados los terrenos?" , Language = "es" } ) ;
questionDbContext . QuestionsTranslations . Add ( new Db . QuestionsTranslation ( ) { QuestionId = 3 , QuestionText = "Is the access blocked by flooding ?" , Language = "en" } ) ;
questionDbContext . QuestionsTranslations . Add ( new Db . QuestionsTranslation ( ) { QuestionId = 3 , QuestionText = "L'accès est-il bloqué par les inondations ?" , Language = "fr" } ) ;
questionDbContext . QuestionsTranslations . Add ( new Db . QuestionsTranslation ( ) { QuestionId = 3 , QuestionText = "¿El acceso está bloqueado por inundaciones?" , Language = "es" } ) ;
questionDbContext . QuestionsTranslations . Add ( new Db . QuestionsTranslation ( ) { QuestionId = 4 , QuestionText = "Are the grounds flooded ?" , Language = "en" } ) ;
questionDbContext . QuestionsTranslations . Add ( new Db . QuestionsTranslation ( ) { QuestionId = 4 , QuestionText = "Les terrains sont-ils inondés ?" , Language = "fr" } ) ;
questionDbContext . QuestionsTranslations . Add ( new Db . QuestionsTranslation ( ) { QuestionId = 4 , QuestionText = "¿Están inundados los terrenos?" , Language = "es" } ) ;
2023-10-11 14:33:10 -05:00
questionDbContext . QuestionsTranslations . Add ( new Db . QuestionsTranslation ( ) { QuestionId = 5 , QuestionText = "Can you open?" , Language = "en" } ) ;
questionDbContext . QuestionsTranslations . Add ( new Db . QuestionsTranslation ( ) { QuestionId = 6 , QuestionText = "Is debris blocking access?" , Language = "en" } ) ;
questionDbContext . QuestionsTranslations . Add ( new Db . QuestionsTranslation ( ) { QuestionId = 7 , QuestionText = "Are the grounds flooded?" , Language = "en" } ) ;
questionDbContext . QuestionsTranslations . Add ( new Db . QuestionsTranslation ( ) { QuestionId = 8 , QuestionText = "Is the access blocked by flooding?" , Language = "en" } ) ;
questionDbContext . QuestionsTranslations . Add ( new Db . QuestionsTranslation ( ) { QuestionId = 9 , QuestionText = "Are any utility wires down?" , Language = "en" } ) ;
questionDbContext . QuestionsTranslations . Add ( new Db . QuestionsTranslation ( ) { QuestionId = 10 , QuestionText = "Do you have damage to windows, doors, or walls?" , Language = "en" } ) ;
questionDbContext . QuestionsTranslations . Add ( new Db . QuestionsTranslation ( ) { QuestionId = 11 , QuestionText = "Do you have roof damage?" , Language = "en" } ) ;
questionDbContext . QuestionsTranslations . Add ( new Db . QuestionsTranslation ( ) { QuestionId = 12 , QuestionText = "Do you have major water intrusion?" , Language = "en" } ) ;
questionDbContext . QuestionsTranslations . Add ( new Db . QuestionsTranslation ( ) { QuestionId = 13 , QuestionText = "Are any portable classrooms damaged and unusable?" , Language = "en" } ) ;
questionDbContext . QuestionsTranslations . Add ( new Db . QuestionsTranslation ( ) { QuestionId = 14 , QuestionText = "Does your facility need to be secured/boarded?" , Language = "en" } ) ;
questionDbContext . QuestionsTranslations . Add ( new Db . QuestionsTranslation ( ) { QuestionId = 15 , QuestionText = "Are you without commercial power?" , Language = "en" } ) ;
questionDbContext . QuestionsTranslations . Add ( new Db . QuestionsTranslation ( ) { QuestionId = 16 , QuestionText = "Are you without water pressure?" , Language = "en" } ) ;
questionDbContext . QuestionsTranslations . Add ( new Db . QuestionsTranslation ( ) { QuestionId = 17 , QuestionText = "Are you without telephones?" , Language = "en" } ) ;
questionDbContext . QuestionsTranslations . Add ( new Db . QuestionsTranslation ( ) { QuestionId = 18 , QuestionText = "Are traffic signals damaged/missing?" , Language = "en" } ) ;
questionDbContext . QuestionsTranslations . Add ( new Db . QuestionsTranslation ( ) { QuestionId = 19 , QuestionText = "Are you without an operable fire alarm?" , Language = "en" } ) ;
questionDbContext . QuestionsTranslations . Add ( new Db . QuestionsTranslation ( ) { QuestionId = 20 , QuestionText = "Are you without an operable public address?" , Language = "en" } ) ;
questionDbContext . QuestionsTranslations . Add ( new Db . QuestionsTranslation ( ) { QuestionId = 21 , QuestionText = "Do you have major debris?" , Language = "en" } ) ;
questionDbContext . QuestionsTranslations . Add ( new Db . QuestionsTranslation ( ) { QuestionId = 22 , QuestionText = "Are there any problems or issues not addressed above that would impede you from opening? If yes, please explain below?" , Language = "en" } ) ;
questionDbContext . QuestionsTranslations . Add ( new Db . QuestionsTranslation ( ) { QuestionId = 5 , QuestionText = "Pouvez-vous ouvrir ?" , Language = "fr" } ) ;
questionDbContext . QuestionsTranslations . Add ( new Db . QuestionsTranslation ( ) { QuestionId = 6 , QuestionText = "Est-ce que des débris bloquent l'accès ?" , Language = "fr" } ) ;
questionDbContext . QuestionsTranslations . Add ( new Db . QuestionsTranslation ( ) { QuestionId = 7 , QuestionText = "Les terrains sont-ils inondés ?" , Language = "fr" } ) ;
questionDbContext . QuestionsTranslations . Add ( new Db . QuestionsTranslation ( ) { QuestionId = 8 , QuestionText = "L'accès est-il bloqué par des inondations ?" , Language = "fr" } ) ;
questionDbContext . QuestionsTranslations . Add ( new Db . QuestionsTranslation ( ) { QuestionId = 9 , QuestionText = "Des câbles d'utilité sont-ils tombés ?" , Language = "fr" } ) ;
questionDbContext . QuestionsTranslations . Add ( new Db . QuestionsTranslation ( ) { QuestionId = 10 , QuestionText = "Avez-vous des dommages aux fenêtres, portes ou murs ?" , Language = "fr" } ) ;
questionDbContext . QuestionsTranslations . Add ( new Db . QuestionsTranslation ( ) { QuestionId = 11 , QuestionText = "Avez-vous des dommages au toit ?" , Language = "fr" } ) ;
questionDbContext . QuestionsTranslations . Add ( new Db . QuestionsTranslation ( ) { QuestionId = 12 , QuestionText = "Avez-vous une intrusion d'eau majeure ?" , Language = "fr" } ) ;
questionDbContext . QuestionsTranslations . Add ( new Db . QuestionsTranslation ( ) { QuestionId = 13 , QuestionText = "Les salles de classe portables sont-elles endommagées et inutilisables ?" , Language = "fr" } ) ;
questionDbContext . QuestionsTranslations . Add ( new Db . QuestionsTranslation ( ) { QuestionId = 14 , QuestionText = "Votre établissement a-t-il besoin d'être sécurisé/protégé ?" , Language = "fr" } ) ;
questionDbContext . QuestionsTranslations . Add ( new Db . QuestionsTranslation ( ) { QuestionId = 15 , QuestionText = "Êtes-vous sans alimentation électrique commerciale ?" , Language = "fr" } ) ;
questionDbContext . QuestionsTranslations . Add ( new Db . QuestionsTranslation ( ) { QuestionId = 16 , QuestionText = "Êtes-vous sans pression d'eau ?" , Language = "fr" } ) ;
questionDbContext . QuestionsTranslations . Add ( new Db . QuestionsTranslation ( ) { QuestionId = 17 , QuestionText = "Êtes-vous sans téléphones ?" , Language = "fr" } ) ;
questionDbContext . QuestionsTranslations . Add ( new Db . QuestionsTranslation ( ) { QuestionId = 18 , QuestionText = "Les feux de circulation sont-ils endommagés/absents ?" , Language = "fr" } ) ;
questionDbContext . QuestionsTranslations . Add ( new Db . QuestionsTranslation ( ) { QuestionId = 19 , QuestionText = "N'avez-vous pas d'alarme incendie fonctionnelle ?" , Language = "fr" } ) ;
questionDbContext . QuestionsTranslations . Add ( new Db . QuestionsTranslation ( ) { QuestionId = 20 , QuestionText = "N'avez-vous pas de système de sonorisation opérationnel ?" , Language = "fr" } ) ;
questionDbContext . QuestionsTranslations . Add ( new Db . QuestionsTranslation ( ) { QuestionId = 21 , QuestionText = "Avez-vous une grande quantité de débris ?" , Language = "fr" } ) ;
questionDbContext . QuestionsTranslations . Add ( new Db . QuestionsTranslation ( ) { QuestionId = 22 , QuestionText = "Y a-t-il des problèmes ou des problèmes non abordés ci-dessus qui vous empêcheraient d'ouvrir ? Si oui, veuillez expliquer ci-dessous." , Language = "fr" } ) ;
questionDbContext . QuestionsTranslations . Add ( new Db . QuestionsTranslation ( ) { QuestionId = 5 , QuestionText = "¿Puedes abrir ?" , Language = "es" } ) ;
questionDbContext . QuestionsTranslations . Add ( new Db . QuestionsTranslation ( ) { QuestionId = 6 , QuestionText = "¿Los escombros bloquean el acceso?" , Language = "es" } ) ;
questionDbContext . QuestionsTranslations . Add ( new Db . QuestionsTranslation ( ) { QuestionId = 7 , QuestionText = "¿Están inundados los terrenos?" , Language = "es" } ) ;
questionDbContext . QuestionsTranslations . Add ( new Db . QuestionsTranslation ( ) { QuestionId = 8 , QuestionText = "¿El acceso está bloqueado por inundaciones?" , Language = "es" } ) ;
questionDbContext . QuestionsTranslations . Add ( new Db . QuestionsTranslation ( ) { QuestionId = 9 , QuestionText = "¿Hay cables de utilidad caídos?" , Language = "es" } ) ;
questionDbContext . QuestionsTranslations . Add ( new Db . QuestionsTranslation ( ) { QuestionId = 10 , QuestionText = "¿Tienes daños en ventanas, puertas o paredes?" , Language = "es" } ) ;
questionDbContext . QuestionsTranslations . Add ( new Db . QuestionsTranslation ( ) { QuestionId = 11 , QuestionText = "¿Tienes daños en el techo?" , Language = "es" } ) ;
questionDbContext . QuestionsTranslations . Add ( new Db . QuestionsTranslation ( ) { QuestionId = 12 , QuestionText = "¿Tienes una gran intrusión de agua?" , Language = "es" } ) ;
questionDbContext . QuestionsTranslations . Add ( new Db . QuestionsTranslation ( ) { QuestionId = 13 , QuestionText = "¿Hay aulas portátiles dañadas e inutilizables?" , Language = "es" } ) ;
questionDbContext . QuestionsTranslations . Add ( new Db . QuestionsTranslation ( ) { QuestionId = 14 , QuestionText = "¿Tu instalación necesita ser asegurada/tabicada?" , Language = "es" } ) ;
questionDbContext . QuestionsTranslations . Add ( new Db . QuestionsTranslation ( ) { QuestionId = 15 , QuestionText = "¿No tienes energía comercial?" , Language = "es" } ) ;
questionDbContext . QuestionsTranslations . Add ( new Db . QuestionsTranslation ( ) { QuestionId = 16 , QuestionText = "¿No tienes presión de agua?" , Language = "es" } ) ;
questionDbContext . QuestionsTranslations . Add ( new Db . QuestionsTranslation ( ) { QuestionId = 17 , QuestionText = "¿No tienes teléfonos?" , Language = "es" } ) ;
questionDbContext . QuestionsTranslations . Add ( new Db . QuestionsTranslation ( ) { QuestionId = 18 , QuestionText = "¿Los semáforos están dañados/faltan?" , Language = "es" } ) ;
questionDbContext . QuestionsTranslations . Add ( new Db . QuestionsTranslation ( ) { QuestionId = 19 , QuestionText = "¿No tienes una alarma de incendios operativa?" , Language = "es" } ) ;
questionDbContext . QuestionsTranslations . Add ( new Db . QuestionsTranslation ( ) { QuestionId = 20 , QuestionText = "¿No tienes un sistema de megafonía operativo?" , Language = "es" } ) ;
questionDbContext . QuestionsTranslations . Add ( new Db . QuestionsTranslation ( ) { QuestionId = 21 , QuestionText = "¿Tienes una gran cantidad de escombros?" , Language = "es" } ) ;
questionDbContext . QuestionsTranslations . Add ( new Db . QuestionsTranslation ( ) { QuestionId = 22 , QuestionText = "¿Hay algún problema o asunto no abordado anteriormente que le impida abrir? Si es así, por favor explíquelo a continuación." , Language = "es" } ) ;
2023-10-06 17:22:37 -05:00
questionDbContext . SaveChanges ( ) ;
}
2023-08-15 22:52:30 -05:00
}
2023-09-08 14:40:06 -05:00
public List < Models . CategoryTranslation > GetCategoryTranslations ( int id , string? language )
{
List < Models . CategoryTranslation > categoryTranslations = new List < Models . CategoryTranslation > ( ) ;
if ( string . IsNullOrEmpty ( language ) )
{
categoryTranslations = mapper . Map < List < Db . CategoryTranslation > , List < Models . CategoryTranslation > > (
questionDbContext . CategoryTranslations . AsNoTracking ( ) . Where ( a = > a . CategoryId = = id ) . ToList ( ) ) ;
}
else
{
categoryTranslations = mapper . Map < List < Db . CategoryTranslation > , List < Models . CategoryTranslation > > (
questionDbContext . CategoryTranslations . AsNoTracking ( ) . Where ( a = > a . CategoryId = = id & & a . Language = = language ) . ToList ( ) ) ;
}
return categoryTranslations ;
}
public object CreateCategoryMultiLanguageObject ( List < Models . CategoryTranslation > categoryTranslations )
{
object MultiLanguage = new object ( ) ;
Dictionary < string , string > dict = new Dictionary < string , string > ( ) ;
foreach ( Models . CategoryTranslation item in categoryTranslations )
{
dict . Add ( item . Language , item . Title ) ;
}
MultiLanguage = dict ;
return MultiLanguage ;
}
public List < Models . QuestionsTranslation > GetQuestionsTranslations ( int id , string? language )
{
List < Models . QuestionsTranslation > QuestionTranslations ;
if ( string . IsNullOrEmpty ( language ) )
{
QuestionTranslations = mapper . Map < List < Db . QuestionsTranslation > , List < Models . QuestionsTranslation > > (
questionDbContext . QuestionsTranslations . AsNoTracking ( ) . Where ( a = > a . QuestionId = = id ) . ToList ( ) ) ;
}
else
{
QuestionTranslations = mapper . Map < List < Db . QuestionsTranslation > , List < Models . QuestionsTranslation > > (
questionDbContext . QuestionsTranslations . AsNoTracking ( ) . Where ( a = > a . QuestionId = = id & & a . Language = = language ) . ToList ( ) ) ;
}
return QuestionTranslations ;
}
2023-09-13 00:28:24 -05:00
public Dictionary < string , string > CreateMultiLanguageObject ( List < Models . QuestionsTranslation > questions )
2023-09-08 14:40:06 -05:00
{
MultiLanguage MultiLanguage = new MultiLanguage ( ) ;
Dictionary < string , string > dict = new Dictionary < string , string > ( ) ;
foreach ( Models . QuestionsTranslation item in questions )
{
dict . Add ( item . Language , item . QuestionText ) ;
}
2023-09-13 00:28:24 -05:00
//MultiLanguage.questionText = dict;
return dict ;
2023-09-08 14:40:06 -05:00
}
2023-09-13 00:28:24 -05:00
public async Task < ( bool IsSuccess , IEnumerable < Models . MultiLanguage > Questions , string ErrorMessage ) > GetQuestionsAsync ( string language )
2023-08-15 22:52:30 -05:00
{
try
{
logger ? . LogInformation ( "Query Question" ) ;
var questions = await questionDbContext . Questions . Include ( "QuestionType" ) . AsNoTracking ( ) . ToListAsync ( ) ;
if ( questions ! = null )
{
//logger?.LogInformation($"{question} customer(s) found");
2023-09-13 00:28:24 -05:00
var result = mapper . Map < IEnumerable < Db . Question > , IEnumerable < Models . MultiLanguage > > ( questions ) ;
foreach ( var item in result )
2023-08-15 22:52:30 -05:00
{
2023-09-13 00:28:24 -05:00
item . Text = CreateMultiLanguageObject ( GetQuestionsTranslations ( item . Id , language ) ) ;
2023-08-15 22:52:30 -05:00
}
return ( true , result , null ) ;
}
return ( false , null , "Not found" ) ;
}
catch ( Exception ex )
{
logger ? . LogError ( ex . ToString ( ) ) ;
return ( false , null , ex . Message ) ;
}
}
2023-09-13 00:28:24 -05:00
public async Task < ( bool IsSuccess , Models . MultiLanguage Question , string ErrorMessage ) > GetQuestionAsync ( int id , string language )
2023-08-15 22:52:30 -05:00
{
try
{
logger ? . LogInformation ( "Query Question" ) ;
2023-09-08 14:40:06 -05:00
var question = await questionDbContext . Questions . Include ( "QuestionType" ) . AsNoTracking ( ) . FirstOrDefaultAsync ( q = > q . Id = = id ) ;
2023-08-15 22:52:30 -05:00
if ( question ! = null )
{
logger ? . LogInformation ( $"{question} customer(s) found" ) ;
2023-09-13 00:28:24 -05:00
var result = mapper . Map < Db . Question , Models . MultiLanguage > ( question ) ;
result . Text = CreateMultiLanguageObject ( GetQuestionsTranslations ( id , language ) ) ;
2023-08-15 22:52:30 -05:00
return ( true , result , null ) ;
}
return ( false , null , "Not found" ) ;
}
catch ( Exception ex )
{
logger ? . LogError ( ex . ToString ( ) ) ;
return ( false , null , ex . Message ) ;
}
}
2023-09-13 00:28:24 -05:00
public List < Models . MultiLanguage > GetSurveyQuestion ( List < Models . MultiLanguage > questions , string language )
2023-08-15 22:52:30 -05:00
{
2023-09-08 14:40:06 -05:00
foreach ( var item in questions )
2023-08-25 07:55:11 -05:00
{
2023-09-13 00:28:24 -05:00
item . Text = CreateMultiLanguageObject ( GetQuestionsTranslations ( item . Id , language ) ) ;
2023-08-15 22:52:30 -05:00
}
return questions ;
}
2023-09-08 14:40:06 -05:00
public async Task < ( bool IsSuccess , List < SurveyQuestions > SurveyQuestions , string ErrorMessage ) > GetSurveyQuestionAsync ( int SurveyId , string language )
2023-08-15 22:52:30 -05:00
{
try
{
logger ? . LogInformation ( "Query Question" ) ;
2023-08-25 07:55:11 -05:00
var questions = await questionDbContext . Questions . Include ( "QuestionType" ) . Where ( a = > a . SurveyId = = SurveyId ) . AsNoTracking ( ) . ToListAsync ( ) ;
2023-08-15 22:52:30 -05:00
if ( questions ! = null )
{
List < SurveyQuestions > surveyQuestionsList = new List < SurveyQuestions > ( ) ;
2023-08-25 07:55:11 -05:00
List < int > CategoryIds = questions . Select ( a = > a . CategoryId ) . Distinct ( ) . ToList ( ) ;
var questioncategories = await questionDbContext . QuestionCategories . Where ( a = > CategoryIds . Contains ( a . Id ) ) . ToListAsync ( ) ;
2023-08-15 22:52:30 -05:00
//logger?.LogInformation($"{question} customer(s) found");
foreach ( var item in questioncategories )
{
surveyQuestionsList . Add ( new SurveyQuestions ( )
{
CategoryId = item . Id ,
2023-09-08 14:40:06 -05:00
IconLibrary = item . IconLibrary ,
IconName = item . IconName ,
2023-10-13 12:21:33 -05:00
CategoryNames = CreateCategoryMultiLanguageObject ( GetCategoryTranslations ( item . Id , language ) ) ,
2023-09-13 00:28:24 -05:00
QuestionsText = GetSurveyQuestion ( mapper . Map < List < Db . Question > , List < Models . MultiLanguage > > ( questions . Where ( a = > a . CategoryId = = item . Id ) . ToList ( ) ) , language )
2023-08-15 22:52:30 -05:00
} ) ;
}
//var result = mapper.Map<IEnumerable<Db.Question>, IEnumerable<Models.Question>>(questions);
return ( true , surveyQuestionsList , null ) ;
}
return ( false , null , "Not found" ) ;
}
catch ( Exception ex )
{
logger ? . LogError ( ex . ToString ( ) ) ;
return ( false , null , ex . Message ) ;
}
}
2023-09-13 00:28:24 -05:00
public async Task < ( bool IsSuccess , Models . MultiLanguage Question , string ErrorMessage ) > PostQuestionAsync ( Models . Question Question )
2023-08-15 22:52:30 -05:00
{
try
{
logger ? . LogInformation ( "Query Question" ) ;
2023-11-14 15:13:23 -05:00
var result = InsertQuestion ( Question ) ;
2023-09-08 14:40:06 -05:00
return ( true , result , null ) ;
2023-08-15 22:52:30 -05:00
}
catch ( Exception ex )
{
logger ? . LogError ( ex . ToString ( ) ) ;
return ( false , null , ex . Message ) ;
}
}
2023-11-14 15:13:23 -05:00
private Models . MultiLanguage InsertQuestion ( Models . Question Question )
{
var dbquestion = mapper . Map < Models . Question , Db . Question > ( Question ) ;
var dbquestiontranslation = mapper . Map < List < Models . QuestionsTranslation > , List < Db . QuestionsTranslation > > ( Question . Questions ) ;
dbquestion . QuestionTypeId = questionDbContext . QuestionTypes . Where ( a = > a . TypeText = = Question . TypeText ) . Select ( a = > a . Id ) . FirstOrDefault ( ) ;
questionDbContext . Questions . Add ( dbquestion ) ;
2023-11-15 09:07:17 -05:00
questionDbContext . SaveChanges ( ) ;
2023-11-14 15:13:23 -05:00
dbquestiontranslation . ForEach ( i = > i . QuestionId = dbquestion . Id ) ;
questionDbContext . QuestionsTranslations . AddRange ( dbquestiontranslation ) ;
questionDbContext . SaveChanges ( ) ;
Question . Id = dbquestion . Id ;
var result = mapper . Map < Db . Question , Models . MultiLanguage > ( dbquestion ) ;
result . Text = CreateMultiLanguageObject ( GetQuestionsTranslations ( result . Id , "" ) ) ;
return result ;
}
public async Task < ( bool IsSuccess , IEnumerable < Models . MultiLanguage > Question , string ErrorMessage ) > PostQuestionsAsync ( List < Models . Question > Questions )
{
try
{
List < Models . MultiLanguage > results = new List < MultiLanguage > ( ) ;
logger ? . LogInformation ( "Query Question" ) ;
foreach ( Models . Question Question in Questions )
{
results . Add ( InsertQuestion ( Question ) ) ;
}
return ( true , results , null ) ;
}
catch ( Exception ex )
{
logger ? . LogError ( ex . ToString ( ) ) ;
return ( false , null , ex . Message ) ;
}
}
2023-09-13 00:28:24 -05:00
public async Task < ( bool IsSuccess , Models . MultiLanguage Question , string ErrorMessage ) > UpdateQuestionAsync ( Models . Question Question )
2023-08-15 22:52:30 -05:00
{
try
{
var dbquestion = mapper . Map < Models . Question , Db . Question > ( Question ) ;
var dbquestiontranslation = mapper . Map < List < Models . QuestionsTranslation > , List < Db . QuestionsTranslation > > ( Question . Questions ) ;
dbquestion . QuestionTypeId = questionDbContext . QuestionTypes . Where ( a = > a . TypeText = = Question . TypeText ) . Select ( a = > a . Id ) . FirstOrDefault ( ) ;
questionDbContext . Entry ( dbquestion ) . State = EntityState . Modified ;
var oldquestions = questionDbContext . QuestionsTranslations . Where ( a = > a . QuestionId = = dbquestion . Id ) . ToList ( ) ;
2023-08-25 07:55:11 -05:00
if ( oldquestions ! = null )
2023-08-15 22:52:30 -05:00
questionDbContext . QuestionsTranslations . RemoveRange ( oldquestions ) ;
dbquestiontranslation . ForEach ( i = > i . QuestionId = dbquestion . Id ) ;
questionDbContext . QuestionsTranslations . AddRange ( dbquestiontranslation ) ;
questionDbContext . SaveChanges ( ) ;
2023-09-13 00:28:24 -05:00
var result = mapper . Map < Db . Question , Models . MultiLanguage > ( dbquestion ) ;
result . Text = CreateMultiLanguageObject ( GetQuestionsTranslations ( result . Id , "" ) ) ;
2023-09-08 14:40:06 -05:00
return ( true , result , null ) ;
2023-08-15 22:52:30 -05:00
}
catch ( Exception ex )
{
logger ? . LogError ( ex . ToString ( ) ) ;
return ( false , null , ex . Message ) ;
}
}
2023-09-13 00:28:24 -05:00
public async Task < ( bool IsSuccess , Models . MultiLanguage Question , string ErrorMessage ) > DeleteQuestionAsync ( int id )
2023-08-15 22:52:30 -05:00
{
try
{
2023-09-08 14:40:06 -05:00
var question = await questionDbContext . Questions . Where ( x = > x . Id = = id ) . FirstOrDefaultAsync ( ) ;
2023-08-15 22:52:30 -05:00
if ( question ! = null )
{
2023-09-13 00:28:24 -05:00
var result = mapper . Map < Db . Question , Models . MultiLanguage > ( question ) ;
result . Text = CreateMultiLanguageObject ( GetQuestionsTranslations ( result . Id , "" ) ) ;
2023-08-15 22:52:30 -05:00
questionDbContext . Questions . Remove ( question ) ;
questionDbContext . SaveChanges ( ) ;
2023-09-08 14:40:06 -05:00
return ( true , result , $"QuestionID {id} deleted Successfuly" ) ;
2023-08-15 22:52:30 -05:00
}
else
{
2023-09-08 14:40:06 -05:00
logger ? . LogInformation ( $"QuestionID: {id} Not found" ) ;
2023-08-15 22:52:30 -05:00
return ( false , null , "Not Found" ) ;
}
}
catch ( Exception ex )
{
logger ? . LogError ( ex . ToString ( ) ) ;
return ( false , null , ex . Message ) ;
}
}
//Question Category Logic
2023-09-08 14:40:06 -05:00
public async Task < ( bool IsSuccess , IEnumerable < Models . MultiLanQuestionCategory > QuestionCategories , string ErrorMessage ) > GetQuestionCategoriesAsync ( string? language )
2023-08-15 22:52:30 -05:00
{
try
{
logger ? . LogInformation ( "Query Question" ) ;
var questionCategories = await questionDbContext . QuestionCategories . AsNoTracking ( ) . ToListAsync ( ) ;
if ( questionCategories ! = null )
{
//logger?.LogInformation($"{question} customer(s) found");
2023-09-08 14:40:06 -05:00
var result = mapper . Map < IEnumerable < Db . QuestionCategory > , IEnumerable < Models . MultiLanQuestionCategory > > ( questionCategories ) ;
foreach ( var category in result )
{
category . Titles = CreateCategoryMultiLanguageObject ( GetCategoryTranslations ( category . Id , language ) ) ;
}
2023-08-15 22:52:30 -05:00
return ( true , result , null ) ;
}
return ( false , null , "Not found" ) ;
}
catch ( Exception ex )
{
logger ? . LogError ( ex . ToString ( ) ) ;
return ( false , null , ex . Message ) ;
}
}
2023-09-08 14:40:06 -05:00
public async Task < ( bool IsSuccess , Models . MultiLanQuestionCategory QuestionCategory , string ErrorMessage ) > GetQuestionCategoryAsync ( int id , string? language )
2023-08-15 22:52:30 -05:00
{
try
{
logger ? . LogInformation ( "Query Question" ) ;
2023-09-08 14:40:06 -05:00
var questioncategory = await questionDbContext . QuestionCategories . AsNoTracking ( ) . FirstOrDefaultAsync ( q = > q . Id = = id ) ;
2023-08-15 22:52:30 -05:00
if ( questioncategory ! = null )
{
logger ? . LogInformation ( $"{questioncategory} customer(s) found" ) ;
2023-09-08 14:40:06 -05:00
var result = mapper . Map < Db . QuestionCategory , Models . MultiLanQuestionCategory > ( questioncategory ) ;
result . Titles = CreateCategoryMultiLanguageObject ( GetCategoryTranslations ( result . Id , language ) ) ;
2023-08-15 22:52:30 -05:00
return ( true , result , null ) ;
}
return ( false , null , "Not found" ) ;
}
catch ( Exception ex )
{
logger ? . LogError ( ex . ToString ( ) ) ;
return ( false , null , ex . Message ) ;
}
}
2023-09-08 14:40:06 -05:00
public async Task < ( bool IsSuccess , Models . MultiLanQuestionCategory QuestionCategory , string ErrorMessage ) > PostQuestionCategoryAsync ( Models . QuestionCategory QuestionCategory )
2023-08-15 22:52:30 -05:00
{
try
{
logger ? . LogInformation ( "Query Question" ) ;
var dbQuestionCategory = mapper . Map < Models . QuestionCategory , Db . QuestionCategory > ( QuestionCategory ) ;
2023-09-08 14:40:06 -05:00
var dbCategorytranslations = mapper . Map < List < Models . CategoryTranslation > , List < Db . CategoryTranslation > > ( QuestionCategory . Categories ) ;
2023-08-15 22:52:30 -05:00
// Question.QuestionType = GetQuestionType(Question.QuestionTypeId);
questionDbContext . QuestionCategories . Add ( dbQuestionCategory ) ;
questionDbContext . SaveChanges ( ) ;
2023-08-25 07:55:11 -05:00
QuestionCategory . Id = dbQuestionCategory . Id ;
2023-09-08 14:40:06 -05:00
dbCategorytranslations . ForEach ( i = > i . CategoryId = QuestionCategory . Id ) ;
questionDbContext . CategoryTranslations . AddRange ( dbCategorytranslations ) ;
questionDbContext . SaveChanges ( ) ;
var result = mapper . Map < Db . QuestionCategory , Models . MultiLanQuestionCategory > ( dbQuestionCategory ) ;
result . Titles = CreateCategoryMultiLanguageObject ( GetCategoryTranslations ( result . Id , "" ) ) ;
return ( true , result , null ) ;
2023-08-15 22:52:30 -05:00
}
catch ( Exception ex )
{
logger ? . LogError ( ex . ToString ( ) ) ;
return ( false , null , ex . Message ) ;
}
}
2023-09-08 14:40:06 -05:00
public async Task < ( bool IsSuccess , Models . MultiLanQuestionCategory QuestionCategory , string ErrorMessage ) > UpdateQuestionCategoryAsync ( Models . QuestionCategory QuestionCategory )
2023-08-15 22:52:30 -05:00
{
try
{
var dbQuestionCategory = mapper . Map < Models . QuestionCategory , Db . QuestionCategory > ( QuestionCategory ) ;
2023-09-08 14:40:06 -05:00
var dbCategorytranslations = mapper . Map < List < Models . CategoryTranslation > , List < Db . CategoryTranslation > > ( QuestionCategory . Categories ) ;
2023-08-15 22:52:30 -05:00
questionDbContext . Entry ( dbQuestionCategory ) . State = EntityState . Modified ;
2023-09-08 14:40:06 -05:00
QuestionCategory . Id = dbQuestionCategory . Id ;
var oldcategories = questionDbContext . CategoryTranslations . Where ( a = > a . CategoryId = = dbQuestionCategory . Id ) . ToList ( ) ;
if ( oldcategories ! = null )
questionDbContext . CategoryTranslations . RemoveRange ( oldcategories ) ;
dbCategorytranslations . ForEach ( i = > i . CategoryId = QuestionCategory . Id ) ;
questionDbContext . CategoryTranslations . AddRange ( dbCategorytranslations ) ;
2023-08-15 22:52:30 -05:00
questionDbContext . SaveChanges ( ) ;
2023-09-08 14:40:06 -05:00
var result = mapper . Map < Db . QuestionCategory , Models . MultiLanQuestionCategory > ( dbQuestionCategory ) ;
result . Titles = CreateCategoryMultiLanguageObject ( GetCategoryTranslations ( result . Id , "" ) ) ;
return ( true , result , null ) ;
2023-08-15 22:52:30 -05:00
}
catch ( Exception ex )
{
logger ? . LogError ( ex . ToString ( ) ) ;
return ( false , null , ex . Message ) ;
}
}
2023-09-08 14:40:06 -05:00
public async Task < ( bool IsSuccess , Models . MultiLanQuestionCategory QuestionCategory , string ErrorMessage ) > DeleteQuestionCategoryAsync ( int Id )
2023-08-15 22:52:30 -05:00
{
try
{
var questioncategory = await questionDbContext . QuestionCategories . Where ( x = > x . Id = = Id ) . FirstOrDefaultAsync ( ) ;
if ( questioncategory ! = null )
{
2023-09-08 14:40:06 -05:00
var result = mapper . Map < Db . QuestionCategory , Models . MultiLanQuestionCategory > ( questioncategory ) ;
result . Titles = CreateCategoryMultiLanguageObject ( GetCategoryTranslations ( result . Id , "" ) ) ;
2023-08-15 22:52:30 -05:00
var question = await questionDbContext . Questions . Where ( x = > x . Id = = Id ) . ToListAsync ( ) ;
questionDbContext . Questions . RemoveRange ( question ) ;
questionDbContext . QuestionCategories . Remove ( questioncategory ) ;
questionDbContext . SaveChanges ( ) ;
2023-09-08 14:40:06 -05:00
return ( true , result , $"QuestionID {Id} deleted Successfuly" ) ;
2023-08-15 22:52:30 -05:00
}
else
{
logger ? . LogInformation ( $"QuestionID: {Id} Not found" ) ;
return ( false , null , "Not Found" ) ;
}
}
catch ( Exception ex )
{
logger ? . LogError ( ex . ToString ( ) ) ;
return ( false , null , ex . Message ) ;
}
}
private bool QuestionExists ( int id )
{
return questionDbContext . Questions . AsNoTracking ( ) . Count ( e = > e . Id = = id ) > 0 ;
}
private QuestionType GetQuestionType ( int Id )
{
return questionDbContext . QuestionTypes . Where ( a = > a . Id = = Id ) . FirstOrDefault ( ) ;
}
public async Task < ( bool IsSuccess , QuestionType QuestionType , string ErrorMessage ) > GetQuestionTypeAsync ( int Id )
{
try
{
logger ? . LogInformation ( "Query Question" ) ;
var questiontype = await questionDbContext . QuestionTypes . FirstOrDefaultAsync ( q = > q . Id = = Id ) ;
if ( questiontype ! = null )
{
logger ? . LogInformation ( $"{questiontype} customer(s) found" ) ;
return ( true , questiontype , null ) ;
}
return ( false , null , "Not found" ) ;
}
catch ( Exception ex )
{
logger ? . LogError ( ex . ToString ( ) ) ;
return ( false , null , ex . Message ) ;
}
}
public async Task < ( bool IsSuccess , IEnumerable < QuestionType > QuestionTypes , string ErrorMessage ) > GetQuestionTypesAsync ( )
{
try
{
logger ? . LogInformation ( "Query Question" ) ;
var questionTypes = await questionDbContext . QuestionTypes . ToListAsync ( ) ;
if ( questionTypes ! = null )
{
//logger?.LogInformation($"{question} customer(s) found");
return ( true , questionTypes , null ) ;
}
return ( false , null , "Not found" ) ;
}
catch ( Exception ex )
{
logger ? . LogError ( ex . ToString ( ) ) ;
return ( false , null , ex . Message ) ;
}
}
}
}