added status field in survey micro service
This commit is contained in:
parent
f9b7fad33b
commit
7b7e5c0ce8
@ -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
|
||||
{
|
||||
|
@ -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 = false, 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<Models.MultiLanSurvey> 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<Db.Survey, Models.MultiLanSurvey>(_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<Db.Survey, Models.MultiLanSurvey>(_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<Db.Survey, Models.MultiLanSurvey>(survey);
|
||||
result.Status = GetStatus(survey.StartDate, survey.EndDate);
|
||||
result.Titles = CreateMultiLanguageObject(GetSurveyTranslations(survey.Id, null, ""));
|
||||
surveyDbContext.Surveys.Remove(survey);
|
||||
await surveyDbContext.SaveChangesAsync();
|
||||
|
Loading…
Reference in New Issue
Block a user