forked from MDCPS/DamageAssessment_Backend
		
	fixed survey issue in response level, and added logic for start and end date as optional date
This commit is contained in:
		| @ -13,9 +13,9 @@ namespace DamageAssesment.Api.Surveys.Db | ||||
|  | ||||
|         public bool IsEnabled { get; set; } | ||||
|  | ||||
|         public DateTime StartDate { get; set; } | ||||
|         public DateTime? StartDate { get; set; } | ||||
|  | ||||
|         public DateTime EndDate { get; set; } | ||||
|         public DateTime? EndDate { get; set; } | ||||
|  | ||||
|         public DateTime CreatedDate { get; set; } = DateTime.Now; | ||||
|         /* | ||||
|  | ||||
| @ -21,8 +21,8 @@ namespace DamageAssesment.Api.Surveys.Models | ||||
|     { | ||||
|         public int Id { get; set; } | ||||
|         public bool IsEnabled { get; set; } | ||||
|         public DateTime StartDate { get; set; } | ||||
|         public DateTime EndDate { get; set; } | ||||
|         public DateTime CreatedDate { get; set; } | ||||
|         public DateTime? StartDate { get; set; } | ||||
|         public DateTime? EndDate { get; set; } | ||||
|         public DateTime? CreatedDate { get; set; } | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -44,7 +44,7 @@ namespace DamageAssesment.Api.Surveys.Providers | ||||
|                     surveyDbContext.SurveysTranslation.Add(new Db.SurveyTranslation { SurveyId = survey2.Id, Language = "en", Title = "Hurricane Andrew Aftermath Survey" }); | ||||
|                     surveyDbContext.SurveysTranslation.Add(new Db.SurveyTranslation { SurveyId = survey2.Id, Language = "es", Title = "Encuesta sobre las secuelas del huracán Andrew" }); | ||||
|                     surveyDbContext.SurveysTranslation.Add(new Db.SurveyTranslation { SurveyId = survey2.Id, Language = "fr", Title = "Enquête sur les conséquences de l'ouragan Andrew" }); | ||||
|                    | ||||
|  | ||||
|                     surveyDbContext.SurveysTranslation.Add(new Db.SurveyTranslation { SurveyId = survey3.Id, Language = "en", Title = "Hurricane Irma" }); | ||||
|                     surveyDbContext.SurveysTranslation.Add(new Db.SurveyTranslation { SurveyId = survey3.Id, Language = "es", Title = "Huracán Irma" }); | ||||
|                     surveyDbContext.SurveysTranslation.Add(new Db.SurveyTranslation { SurveyId = survey3.Id, Language = "fr", Title = "Ouragan Irma" }); | ||||
| @ -85,14 +85,21 @@ namespace DamageAssesment.Api.Surveys.Providers | ||||
|             MultiLanguage = dict; | ||||
|             return MultiLanguage; | ||||
|         } | ||||
|         public string GetStatus(DateTime StartDate,DateTime EndDate) | ||||
|         public string GetStatus(DateTime? StartDate, DateTime? EndDate) | ||||
|         { | ||||
|             if (StartDate > DateTime.Now) | ||||
|                 return SurveyStatus.PENDING.ToString(); | ||||
|             else if (StartDate <= DateTime.Now && EndDate > DateTime.Now) | ||||
|                 return SurveyStatus.ACTIVE.ToString(); | ||||
|             else | ||||
|             try | ||||
|             { | ||||
|                 if (StartDate > DateTime.Now) | ||||
|                     return SurveyStatus.PENDING.ToString(); | ||||
|                 else if (StartDate <= DateTime.Now && EndDate > DateTime.Now) | ||||
|                     return SurveyStatus.ACTIVE.ToString(); | ||||
|                 else | ||||
|                     return SurveyStatus.INACTIVE.ToString(); | ||||
|             } | ||||
|             catch | ||||
|             { | ||||
|                 return SurveyStatus.INACTIVE.ToString(); | ||||
|             } | ||||
|         } | ||||
|         // Method to get surveys asynchronously with multi-language support | ||||
|         public async Task<(bool IsSuccess, IEnumerable<Models.MultiLanSurvey> Surveys, string ErrorMessage)> GetSurveysAsync(string language) | ||||
| @ -101,7 +108,8 @@ namespace DamageAssesment.Api.Surveys.Providers | ||||
|             try | ||||
|             { | ||||
|                 logger?.LogInformation("Get all Surveys from DB"); | ||||
|                 var surveys = await surveyDbContext.Surveys.Where(s => s.IsEnabled == true).ToListAsync(); | ||||
|                 //checking is enabled in survey response  | ||||
|                 var surveys = await surveyDbContext.Surveys.ToListAsync();//Where(s => s.IsEnabled == true) | ||||
|  | ||||
|                 if (surveys != null) | ||||
|                 { | ||||
| @ -113,7 +121,7 @@ namespace DamageAssesment.Api.Surveys.Providers | ||||
|                                       EndDate = s.EndDate, | ||||
|                                       IsEnabled = s.IsEnabled, | ||||
|                                       CreatedDate = s.CreatedDate, | ||||
|                                       Status= GetStatus(s.StartDate,s.EndDate), | ||||
|                                       Status = GetStatus(s.StartDate, s.EndDate), | ||||
|                                       Titles = CreateMultiLanguageObject(GetSurveyTranslations(s.Id, null, language)) | ||||
|                                   }; | ||||
|  | ||||
| @ -135,7 +143,8 @@ namespace DamageAssesment.Api.Surveys.Providers | ||||
|             try | ||||
|             { | ||||
|                 logger?.LogInformation("Query Survey"); | ||||
|                 var survey = await surveyDbContext.Surveys.SingleOrDefaultAsync(s => s.Id == id && s.IsEnabled == true); | ||||
|                 // removed is enabled becuase we are using it in responses to get response | ||||
|                 var survey = await surveyDbContext.Surveys.SingleOrDefaultAsync(s => s.Id == id); | ||||
|  | ||||
|                 if (survey != null) | ||||
|                 { | ||||
| @ -216,12 +225,10 @@ namespace DamageAssesment.Api.Surveys.Providers | ||||
|                         _survey = mapper.Map<Models.Survey, Db.Survey>(survey); | ||||
|                         surveyDbContext.Surveys.Update(_survey); | ||||
|                         await surveyDbContext.SaveChangesAsync(); | ||||
|  | ||||
|                         List<Db.SurveyTranslation> listSurveyTranslation = new List<Db.SurveyTranslation>(); | ||||
|                         Random random = new Random(); | ||||
|                         foreach (var title in survey.Titles) | ||||
|                         { | ||||
|                             listSurveyTranslation.Add(new Db.SurveyTranslation { Id = random.Next(), SurveyId = _survey.Id, Language = title.Language, Title = title.Title }); | ||||
|                             listSurveyTranslation.Add(new Db.SurveyTranslation { SurveyId = _survey.Id, Language = title.Language, Title = title.Title }); | ||||
|                         } | ||||
|                         surveyDbContext.SurveysTranslation.AddRange(listSurveyTranslation); | ||||
|                         await surveyDbContext.SaveChangesAsync(); | ||||
|  | ||||
		Reference in New Issue
	
	Block a user