diff --git a/DamageAssesmentApi/DamageAssesment.Api.Surveys/Models/Survey.cs b/DamageAssesmentApi/DamageAssesment.Api.Surveys/Models/Survey.cs index 25f5405..38fa72a 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Surveys/Models/Survey.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Surveys/Models/Survey.cs @@ -2,9 +2,16 @@ namespace DamageAssesment.Api.Surveys.Models { + public enum SurveyStatus + { + PENDING, + ACTIVE, + INACTIVE + } public class MultiLanSurvey : BaseSurvey { public object Titles { get; set; } + public string Status { get; set; } } public class Survey : BaseSurvey { diff --git a/DamageAssesmentApi/DamageAssesment.Api.Surveys/Providers/SurveysProvider.cs b/DamageAssesmentApi/DamageAssesment.Api.Surveys/Providers/SurveysProvider.cs index fe09798..b639131 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Surveys/Providers/SurveysProvider.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Surveys/Providers/SurveysProvider.cs @@ -26,9 +26,9 @@ namespace DamageAssesment.Api.Surveys.Providers { if (!surveyDbContext.Surveys.Any()) { - var survey1 = new Db.Survey { IsEnabled = true, StartDate = DateTime.Now, EndDate = DateTime.Now.AddDays(90), CreatedDate = DateTime.Now }; - var survey2 = new Db.Survey { IsEnabled = true, StartDate = DateTime.Now, EndDate = DateTime.Now.AddDays(90), CreatedDate = DateTime.Now }; - var survey3 = new Db.Survey { IsEnabled = true, StartDate = DateTime.Now, EndDate = DateTime.Now.AddDays(90), CreatedDate = DateTime.Now }; + var survey1 = new Db.Survey { IsEnabled = true, StartDate = DateTime.Now.AddDays(10), EndDate = DateTime.Now.AddDays(90), CreatedDate = DateTime.Now }; + var survey2 = new Db.Survey { IsEnabled = true, StartDate = DateTime.Now.AddDays(-10), EndDate = DateTime.Now.AddDays(90), CreatedDate = DateTime.Now.AddDays(-10) }; + var survey3 = new Db.Survey { IsEnabled = true, StartDate = DateTime.Now.AddDays(-100), EndDate = DateTime.Now.AddDays(-10), CreatedDate = DateTime.Now.AddDays(-100) }; surveyDbContext.Surveys.Add(survey1); surveyDbContext.Surveys.Add(survey2); @@ -85,7 +85,15 @@ namespace DamageAssesment.Api.Surveys.Providers MultiLanguage = dict; return MultiLanguage; } - + 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 + return SurveyStatus.INACTIVE.ToString(); + } // Method to get surveys asynchronously with multi-language support public async Task<(bool IsSuccess, IEnumerable Surveys, string ErrorMessage)> GetSurveysAsync(string language) { @@ -106,6 +114,7 @@ namespace DamageAssesment.Api.Surveys.Providers EndDate = s.EndDate, IsEnabled = s.IsEnabled, CreatedDate = s.CreatedDate, + Status= GetStatus(s.StartDate,s.EndDate), Titles = CreateMultiLanguageObject(GetSurveyTranslations(s.Id, null, language)) }; @@ -140,6 +149,7 @@ namespace DamageAssesment.Api.Surveys.Providers EndDate = survey.EndDate, IsEnabled = survey.IsEnabled, CreatedDate = survey.CreatedDate, + Status = GetStatus(survey.StartDate, survey.EndDate), Titles = CreateMultiLanguageObject(GetSurveyTranslations(survey.Id, null, language)) }; logger?.LogInformation($"Survey Id: {id} found"); @@ -173,6 +183,7 @@ namespace DamageAssesment.Api.Surveys.Providers } await surveyDbContext.SaveChangesAsync(); var result = mapper.Map(_survey); + result.Status = GetStatus(_survey.StartDate, _survey.EndDate); result.Titles = CreateMultiLanguageObject(GetSurveyTranslations(_survey.Id, survey.Titles, "")); return (true, result, "Successful"); } @@ -217,6 +228,7 @@ namespace DamageAssesment.Api.Surveys.Providers await surveyDbContext.SaveChangesAsync(); var result = mapper.Map(_survey); + result.Status = GetStatus(_survey.StartDate, _survey.EndDate); result.Titles = CreateMultiLanguageObject(GetSurveyTranslations(_survey.Id, survey.Titles, "")); return (true, result, "Successful"); } @@ -249,6 +261,7 @@ namespace DamageAssesment.Api.Surveys.Providers if (survey != null) { var result = mapper.Map(survey); + result.Status = GetStatus(survey.StartDate, survey.EndDate); result.Titles = CreateMultiLanguageObject(GetSurveyTranslations(survey.Id, null, "")); surveyDbContext.Surveys.Remove(survey); await surveyDbContext.SaveChangesAsync();