From 8e0a7df68bf0a809c43c1ea43b0615ee79c21f5a Mon Sep 17 00:00:00 2001 From: uppuv Date: Fri, 13 Oct 2023 13:21:33 -0400 Subject: [PATCH 1/2] added muilti language return format for question categories for question by survey --- .../appsettings.Development.json | 8 -------- .../appsettings.Development.json | 8 -------- .../appsettings.Development.json | 8 -------- .../appsettings.Development.json | 8 -------- .../appsettings.Development.json | 8 -------- .../Models/SurveyQuestion.cs | 1 + .../Providers/QuestionsProvider.cs | 1 + .../appsettings.Development.json | 8 -------- .../appsettings.Development.json | 8 -------- 9 files changed, 2 insertions(+), 56 deletions(-) delete mode 100644 DamageAssesmentApi/DamageAssesment.Api.Answers/appsettings.Development.json delete mode 100644 DamageAssesmentApi/DamageAssesment.Api.Attachments/appsettings.Development.json delete mode 100644 DamageAssesmentApi/DamageAssesment.Api.DocuLinks/appsettings.Development.json delete mode 100644 DamageAssesmentApi/DamageAssesment.Api.Employees/appsettings.Development.json delete mode 100644 DamageAssesmentApi/DamageAssesment.Api.Locations/appsettings.Development.json delete mode 100644 DamageAssesmentApi/DamageAssesment.Api.Questions/appsettings.Development.json delete mode 100644 DamageAssesmentApi/DamageAssesment.Api.Surveys/appsettings.Development.json diff --git a/DamageAssesmentApi/DamageAssesment.Api.Answers/appsettings.Development.json b/DamageAssesmentApi/DamageAssesment.Api.Answers/appsettings.Development.json deleted file mode 100644 index 0c208ae..0000000 --- a/DamageAssesmentApi/DamageAssesment.Api.Answers/appsettings.Development.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft.AspNetCore": "Warning" - } - } -} diff --git a/DamageAssesmentApi/DamageAssesment.Api.Attachments/appsettings.Development.json b/DamageAssesmentApi/DamageAssesment.Api.Attachments/appsettings.Development.json deleted file mode 100644 index 0c208ae..0000000 --- a/DamageAssesmentApi/DamageAssesment.Api.Attachments/appsettings.Development.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft.AspNetCore": "Warning" - } - } -} diff --git a/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/appsettings.Development.json b/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/appsettings.Development.json deleted file mode 100644 index 0c208ae..0000000 --- a/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/appsettings.Development.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft.AspNetCore": "Warning" - } - } -} diff --git a/DamageAssesmentApi/DamageAssesment.Api.Employees/appsettings.Development.json b/DamageAssesmentApi/DamageAssesment.Api.Employees/appsettings.Development.json deleted file mode 100644 index 0c208ae..0000000 --- a/DamageAssesmentApi/DamageAssesment.Api.Employees/appsettings.Development.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft.AspNetCore": "Warning" - } - } -} diff --git a/DamageAssesmentApi/DamageAssesment.Api.Locations/appsettings.Development.json b/DamageAssesmentApi/DamageAssesment.Api.Locations/appsettings.Development.json deleted file mode 100644 index 0c208ae..0000000 --- a/DamageAssesmentApi/DamageAssesment.Api.Locations/appsettings.Development.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft.AspNetCore": "Warning" - } - } -} diff --git a/DamageAssesmentApi/DamageAssesment.Api.Questions/Models/SurveyQuestion.cs b/DamageAssesmentApi/DamageAssesment.Api.Questions/Models/SurveyQuestion.cs index 8f4fd7b..b7ce8d1 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Questions/Models/SurveyQuestion.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Questions/Models/SurveyQuestion.cs @@ -5,6 +5,7 @@ public int CategoryId { get; set; } public string IconName { get; set; } public string IconLibrary { get; set; } + public object CategoryNames { get; set; } public List QuestionsText { get; set; } } } diff --git a/DamageAssesmentApi/DamageAssesment.Api.Questions/Providers/QuestionsProvider.cs b/DamageAssesmentApi/DamageAssesment.Api.Questions/Providers/QuestionsProvider.cs index d1e2d38..0122af7 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Questions/Providers/QuestionsProvider.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Questions/Providers/QuestionsProvider.cs @@ -313,6 +313,7 @@ namespace DamageAssesment.Api.Questions.Providers CategoryId = item.Id, IconLibrary = item.IconLibrary, IconName = item.IconName, + CategoryNames= CreateCategoryMultiLanguageObject(GetCategoryTranslations(item.Id, language)), QuestionsText = GetSurveyQuestion(mapper.Map, List>(questions.Where(a => a.CategoryId == item.Id).ToList()), language) }); } diff --git a/DamageAssesmentApi/DamageAssesment.Api.Questions/appsettings.Development.json b/DamageAssesmentApi/DamageAssesment.Api.Questions/appsettings.Development.json deleted file mode 100644 index 0c208ae..0000000 --- a/DamageAssesmentApi/DamageAssesment.Api.Questions/appsettings.Development.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft.AspNetCore": "Warning" - } - } -} diff --git a/DamageAssesmentApi/DamageAssesment.Api.Surveys/appsettings.Development.json b/DamageAssesmentApi/DamageAssesment.Api.Surveys/appsettings.Development.json deleted file mode 100644 index 0c208ae..0000000 --- a/DamageAssesmentApi/DamageAssesment.Api.Surveys/appsettings.Development.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft.AspNetCore": "Warning" - } - } -} From c77e0452c49763f0e4907060e10ebf961f6e6ddd Mon Sep 17 00:00:00 2001 From: uppuv Date: Mon, 16 Oct 2023 14:13:20 -0400 Subject: [PATCH 2/2] added logic to get active surveys from survey responses --- .../Controllers/SurveyResponsesController.cs | 8 +++-- .../Interfaces/ISurveysResponse.cs | 4 +-- .../Providers/SurveyResponsesProvider.cs | 31 +++++++++---------- .../Providers/SurveysProvider.cs | 3 +- 4 files changed, 24 insertions(+), 22 deletions(-) diff --git a/DamageAssesmentApi/DamageAssesment.Api.Responses/Controllers/SurveyResponsesController.cs b/DamageAssesmentApi/DamageAssesment.Api.Responses/Controllers/SurveyResponsesController.cs index d5f6192..55b7f5d 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Responses/Controllers/SurveyResponsesController.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Responses/Controllers/SurveyResponsesController.cs @@ -199,10 +199,12 @@ namespace DamageAssesment.Api.Responses.Controllers return BadRequest(result.ErrorMessage); } + [Route("responses/surveys/active")] + [Route("responses/surveys/active/{language:alpha}")] [Route("responses/surveys/active/{employeeid:int}")] [Route("responses/surveys/active/{employeeid:int}/{language:alpha}")] [HttpGet] - public async Task GetActiveSurveysAsync(int employeeid, string? language) + public async Task GetActiveSurveysAsync(int? employeeid, string? language) { var result = await this.surveyResponseProvider.GetActiveSurveysAsync(employeeid, language); if (result.IsSuccess) @@ -212,10 +214,12 @@ namespace DamageAssesment.Api.Responses.Controllers return NoContent(); } + [Route("responses/surveys/historic")] + [Route("responses/surveys/historic/{language:alpha}")] [Route("responses/surveys/historic/{employeeid:int}")] [Route("responses/surveys/historic/{employeeid:int}/{language:alpha}")] [HttpGet] - public async Task GetHistoricSurveysAsync(int employeeid, string? language) + public async Task GetHistoricSurveysAsync(int? employeeid, string? language) { var result = await this.surveyResponseProvider.GetHistoricSurveysAsync(employeeid, language); if (result.IsSuccess) diff --git a/DamageAssesmentApi/DamageAssesment.Api.Responses/Interfaces/ISurveysResponse.cs b/DamageAssesmentApi/DamageAssesment.Api.Responses/Interfaces/ISurveysResponse.cs index dea50eb..19893c8 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Responses/Interfaces/ISurveysResponse.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Responses/Interfaces/ISurveysResponse.cs @@ -9,8 +9,8 @@ namespace DamageAssesment.Api.Responses.Interfaces Task<(bool IsSuccess, Models.SurveyResponse SurveyResponse, string ErrorMessage)> PostSurveyResponseAsync(Models.SurveyResponse surveyResponse); // Task<(bool IsSuccess,dynamic surveyResponses, string ErrorMessage)> GetSurveyResponseAsync(int responseId); Task<(bool IsSuccess, dynamic surveyResponses, string ErrorMessage)> GetSurveyResponsesAsync(int employeeid); - Task<(bool IsSuccess, dynamic Surveys, string ErrorMessage)> GetActiveSurveysAsync(int employeeid, string language); - Task<(bool IsSuccess, dynamic Surveys, string ErrorMessage)> GetHistoricSurveysAsync(int employeeid, string language); + Task<(bool IsSuccess, dynamic Surveys, string ErrorMessage)> GetActiveSurveysAsync(int? employeeid, string language); + Task<(bool IsSuccess, dynamic Surveys, string ErrorMessage)> GetHistoricSurveysAsync(int? employeeid, string language); Task<(bool IsSuccess, Models.SurveyResponse SurveyResponse, string ErrorMessage)> PutSurveyResponseAsync(int Id, Models.SurveyResponse surveyResponse); Task<(bool IsSuccess, Models.SurveyResponse SurveyResponse, string ErrorMessage)> DeleteSurveyResponseAsync(int Id); Task<(bool IsSuccess, dynamic SurveyResponse, string ErrorMessage)> GetSurveyResponseByIdAsync(int responseId); diff --git a/DamageAssesmentApi/DamageAssesment.Api.Responses/Providers/SurveyResponsesProvider.cs b/DamageAssesmentApi/DamageAssesment.Api.Responses/Providers/SurveyResponsesProvider.cs index 5278c5c..0c6c817 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Responses/Providers/SurveyResponsesProvider.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Responses/Providers/SurveyResponsesProvider.cs @@ -111,25 +111,19 @@ namespace DamageAssesment.Api.Responses.Providers return (false, null, ex.Message); } } - - public async Task<(bool IsSuccess, dynamic Surveys, string ErrorMessage)> GetActiveSurveysAsync(int employeeid, string language) + + public async Task<(bool IsSuccess, dynamic Surveys, string ErrorMessage)> GetActiveSurveysAsync(int? employeeid, string language) { try { logger?.LogInformation("Querying to get SurveyResponse object from DB"); //get all the survey that already taken by the employee - var listOfsurveysId = await surveyResponseDbContext.SurveyResponses.Where(x => x.EmployeeId == employeeid).Select(y => y.SurveyId).ToListAsync(); var surveys = await surveyServiceProvider.getSurveysAsync(language); - - if (surveys != null) - { - surveys = surveys.Where(s => s.IsEnabled == true && s.StartDate <= DateTime.Now && s.EndDate >= DateTime.Now).ToList(); - } - - if (listOfsurveysId==null || listOfsurveysId.Count == 0) + surveys = surveys.Where(s => s.IsEnabled == true && s.StartDate <= DateTime.Now && s.EndDate >= DateTime.Now).ToList(); + if (employeeid == null || employeeid == 0) return (true, surveys, null); - - var activeSurveys = surveys.Where(s => s.IsEnabled == true && s.StartDate <= DateTime.Now && s.EndDate >= DateTime.Now && !listOfsurveysId.Contains(s.Id)); + List listOfsurveysId = await surveyResponseDbContext.SurveyResponses.Where(x => x.EmployeeId == employeeid.Value).Select(y => y.SurveyId).ToListAsync(); + var activeSurveys = surveys.Where(s => !listOfsurveysId.Contains(s.Id)); return (true, activeSurveys, null); } catch (Exception ex) @@ -139,21 +133,24 @@ namespace DamageAssesment.Api.Responses.Providers } } - public async Task<(bool IsSuccess, dynamic Surveys, string ErrorMessage)> GetHistoricSurveysAsync(int employeeid, string language) + public async Task<(bool IsSuccess, dynamic Surveys, string ErrorMessage)> GetHistoricSurveysAsync(int? employeeid, string language) { try { logger?.LogInformation("Querying to get SurveyResponse object from DB"); - //get all the survey that already taken by the employee - var surveyResponses = await surveyResponseDbContext.SurveyResponses.Where(x => x.EmployeeId == employeeid).ToListAsync(); - var surveys = await surveyServiceProvider.getSurveysAsync(language); + var surveys = await surveyServiceProvider.getSurveysAsync(language); + // returning only historic data: end date is less than current date. + surveys = surveys.Where(s => s.EndDate < DateTime.Now).ToList(); + if (employeeid == null || employeeid == 0) + return (true, surveys, null); + var surveyResponses = await surveyResponseDbContext.SurveyResponses.Where(x => x.EmployeeId == employeeid).ToListAsync(); var historicSurveys = from s in surveys from r in surveyResponses where s.Id == r.SurveyId select s; - return (true, historicSurveys, null); + } catch (Exception ex) { diff --git a/DamageAssesmentApi/DamageAssesment.Api.Surveys/Providers/SurveysProvider.cs b/DamageAssesmentApi/DamageAssesment.Api.Surveys/Providers/SurveysProvider.cs index 3332f6d..fe09798 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Surveys/Providers/SurveysProvider.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Surveys/Providers/SurveysProvider.cs @@ -93,7 +93,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) {