forked from MDCPS/DamageAssessment_Backend
		
	user access module with latest dev branch changes
This commit is contained in:
		| @ -1,16 +1,17 @@ | ||||
| using DamageAssesment.Api.Responses.Interfaces; | ||||
| using DamageAssesment.Api.Responses.Models; | ||||
| using Microsoft.AspNetCore.Authorization; | ||||
| using Microsoft.AspNetCore.Mvc; | ||||
| 
 | ||||
| namespace DamageAssesment.Api.Responses.Controllers | ||||
| { | ||||
|     [ApiController] | ||||
|     public class SurveyResponsesController : ControllerBase | ||||
|     public class ResponsesController : ControllerBase | ||||
|     { | ||||
|         private readonly ISurveysResponse surveyResponseProvider; | ||||
|         private readonly IExcelExportService excelExportService; | ||||
| 
 | ||||
|         public SurveyResponsesController(ISurveysResponse surveyResponseProvider, IExcelExportService excelExportService) | ||||
|         public ResponsesController(ISurveysResponse surveyResponseProvider, IExcelExportService excelExportService) | ||||
|         { | ||||
|             this.surveyResponseProvider = surveyResponseProvider; | ||||
|             this.excelExportService = excelExportService; | ||||
| @ -19,6 +20,7 @@ namespace DamageAssesment.Api.Responses.Controllers | ||||
|         /// GET request for retrieving survey responses. | ||||
|         /// </summary> | ||||
| 
 | ||||
|         [Authorize(Roles = "admin,survey,user,report")] | ||||
|         [Route("responses/{employeeid:int}")] | ||||
|         [Route("responses")] | ||||
|         [HttpGet] | ||||
| @ -38,6 +40,7 @@ namespace DamageAssesment.Api.Responses.Controllers | ||||
|         /// <summary> | ||||
|         /// GET request for retrieving survey responses by survey ID. | ||||
|         /// </summary> | ||||
|         [Authorize(Roles = "admin,survey,user,report")] | ||||
|         [Route("responses/bysurvey/{surveyid:int}/{employeeid:int}")] | ||||
|         [Route("responses/bysurvey/{surveyid:int}")] | ||||
|         [HttpGet] | ||||
| @ -56,6 +59,7 @@ namespace DamageAssesment.Api.Responses.Controllers | ||||
|         /// <param name="surveyid">The ID of the survey for which responses are to be retrieved.</param> | ||||
|         /// <param name="locationid">The ID of the location for which responses are to be retrieved.</param> | ||||
| 
 | ||||
|         [Authorize(Roles = "admin,survey,user,report")] | ||||
|         [Route("responses/{surveyid:int}/{locationid:int}/{employeeid:int}")] | ||||
|         [Route("responses/{surveyid:int}/{locationid:int}")] | ||||
|         [HttpGet] | ||||
| @ -75,6 +79,7 @@ namespace DamageAssesment.Api.Responses.Controllers | ||||
|         /// <param name="questionId">The ID of the question for which responses are to be retrieved.</param> | ||||
|         /// <param name="answer">The answer for which responses are to be retrieved.</param> | ||||
| 
 | ||||
|         [Authorize(Roles = "admin,survey,user,report")] | ||||
|         [Route("responses/byanswer/{surveyid:int}/{questionid:int}/{answer:alpha}/{employeeid:int}")] | ||||
|         [Route("responses/byanswer/{surveyid:int}/{questionid:int}/{answer:alpha}")] | ||||
|         [HttpGet] | ||||
| @ -93,6 +98,7 @@ namespace DamageAssesment.Api.Responses.Controllers | ||||
|         /// </summary> | ||||
|         /// <param name="surveyId">The ID of the survey for which answers are to be retrieved.</param> | ||||
| 
 | ||||
|         [Authorize(Roles = "admin,survey,user,report")] | ||||
|         [Route("responses/byregion/{surveyid:int}")] | ||||
|         [Route("responses/byregion/{surveyid:int}/{employeeid}")] | ||||
|         [HttpGet] | ||||
| @ -109,6 +115,7 @@ namespace DamageAssesment.Api.Responses.Controllers | ||||
|         /// GET request for retrieving survey responses by survey ID and maintenance center. | ||||
|         /// </summary> | ||||
|         /// <param name="surveyId">The ID of the survey for which responses are to be retrieved.</param> | ||||
|         [Authorize(Roles = "admin,survey,user,report")] | ||||
|         [Route("responses/bymaintenancecenter/{surveyid:int}/{employeeid:int}")] | ||||
|         [Route("responses/bymaintenancecenter/{surveyid:int}")] | ||||
|         [HttpGet] | ||||
| @ -126,6 +133,7 @@ namespace DamageAssesment.Api.Responses.Controllers | ||||
|         /// </summary> | ||||
|         /// <param name="responseId">The ID of the survey response to be retrieved.</param> | ||||
| 
 | ||||
|         [Authorize(Roles = "admin,survey,user,report")] | ||||
|         [HttpGet("responses/{id}")] | ||||
|         public async Task<ActionResult> GetSurveyResponseByIdAsync(int id) | ||||
|         { | ||||
| @ -142,6 +150,7 @@ namespace DamageAssesment.Api.Responses.Controllers | ||||
|         /// </summary> | ||||
|         /// <param name="surveyResponse">The survey response object to be created.</param> | ||||
| 
 | ||||
|         [Authorize(Roles = "admin,survey,user,report")] | ||||
|         [HttpPost("responses")] | ||||
|         public async Task<ActionResult> PostSurveysAsync(Models.SurveyResponse surveyResponse) | ||||
|         { | ||||
| @ -158,6 +167,7 @@ namespace DamageAssesment.Api.Responses.Controllers | ||||
|         /// <param name="Id">The ID of the survey response to be updated.</param> | ||||
|         /// <param name="surveyResponse">The updated survey response object.</param> | ||||
| 
 | ||||
|         [Authorize(Roles = "admin,survey,user,report")] | ||||
|         [HttpPut("responses/{id}")] | ||||
|         public async Task<ActionResult> PutSurveyResponseAsync(int id, Models.SurveyResponse surveyResponse) | ||||
|         { | ||||
| @ -175,6 +185,7 @@ namespace DamageAssesment.Api.Responses.Controllers | ||||
|         /// DELETE request for deleting an existing survey response. | ||||
|         /// </summary> | ||||
| 
 | ||||
|         [Authorize(Roles = "admin,survey,user,report")] | ||||
|         [HttpDelete("responses/{id}")] | ||||
|         public async Task<ActionResult> DeleteSurveyResponseAsync(int id) | ||||
|         { | ||||
| @ -190,6 +201,7 @@ namespace DamageAssesment.Api.Responses.Controllers | ||||
|         /// </summary> | ||||
|         /// <param name="request">The answers to be submitted for the survey.</param> | ||||
| 
 | ||||
|         [Authorize(Roles = "admin,survey,user,report")] | ||||
|         [HttpPost("responses/answers")] | ||||
|         public async Task<ActionResult> PostSurveyAnswersAsync(Request request) | ||||
|         { | ||||
| @ -203,6 +215,8 @@ namespace DamageAssesment.Api.Responses.Controllers | ||||
|         /// <summary> | ||||
|         /// Get All active surveys . | ||||
|         /// </summary> | ||||
| 
 | ||||
|         [Authorize(Roles = "admin,survey,user,report")] | ||||
|         [Route("responses/surveys/active")] | ||||
|         [Route("responses/surveys/active/{language:alpha}")] | ||||
|         [Route("responses/surveys/active/{employeeid:int}")] | ||||
| @ -220,6 +234,7 @@ namespace DamageAssesment.Api.Responses.Controllers | ||||
|         /// <summary> | ||||
|         /// Export all survey response data based on survey id. | ||||
|         /// </summary> | ||||
|         [Authorize(Roles = "admin,survey,user,report")] | ||||
|         [HttpGet] | ||||
|         [Route("responses/surveys/export/{surveyid}")] | ||||
|         public async Task<ActionResult> GetExcelSurveysAsync(int surveyid, string language, bool IsAdmin = false) | ||||
| @ -250,6 +265,7 @@ namespace DamageAssesment.Api.Responses.Controllers | ||||
|         /// <summary> | ||||
|         /// Get all historical surveys . | ||||
|         /// </summary> | ||||
|         [Authorize(Roles = "admin,survey,user,report")] | ||||
|         [Route("responses/surveys/historic")] | ||||
|         [Route("responses/surveys/historic/{language:alpha}")] | ||||
|         [Route("responses/surveys/historic/{employeeid:int}")] | ||||
| @ -4,9 +4,9 @@ namespace DamageAssesment.Api.Responses.Interfaces | ||||
| { | ||||
|     public interface IAnswerServiceProvider | ||||
|     { | ||||
|         Task<List<Answer>> getAnswersAsync(); | ||||
|         Task<List<Models.Answer>> GetAnswersByResponseIdAsync(int responseId); | ||||
|         Task<List<Answer>> getAnswersAsync(string token); | ||||
|         Task<List<Models.Answer>> GetAnswersByResponseIdAsync(int responseId, string token); | ||||
|  | ||||
|         Task<Models.Answer> PostAnswersAsync(Models.Answer answer); | ||||
|         Task<Models.Answer> PostAnswersAsync(Models.Answer answer, string token); | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -4,7 +4,7 @@ namespace DamageAssesment.Api.Responses.Interfaces | ||||
| { | ||||
|     public interface IAttachmentServiceProvider | ||||
|     { | ||||
|         Task<List<Attachment>> getAttachmentsAsync(); | ||||
|         Task<IEnumerable<Attachment>> PostAttachmentsAsync(Models.AttachmentInfo attachmentInfo); | ||||
|         Task<List<Attachment>> getAttachmentsAsync(string token); | ||||
|         Task<IEnumerable<Attachment>> PostAttachmentsAsync(Models.AttachmentInfo attachmentInfo, string token); | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -1,10 +1,10 @@ | ||||
| using DamageAssesment.Api.Responses.Models; | ||||
| using DamageAssesment.Api.Responses.Models; | ||||
|  | ||||
| namespace DamageAssesment.Api.Responses.Interfaces | ||||
| { | ||||
|     public interface IEmployeeServiceProvider | ||||
|     { | ||||
|         Task<List<Employee>> getEmployeesAsync(); | ||||
|         Task<Employee> getEmployeeAsync(int employeeId); | ||||
|         Task<List<Employee>> getEmployeesAsync(string token); | ||||
|         Task<Employee> getEmployeeAsync(int employeeId, string token); | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -1,9 +1,9 @@ | ||||
| using DamageAssesment.Api.Responses.Models; | ||||
| using DamageAssesment.Api.Responses.Models; | ||||
|  | ||||
| namespace DamageAssesment.Api.Responses.Interfaces | ||||
| { | ||||
|     public interface IHttpUtil | ||||
|     { | ||||
|         Task<string> SendAsync(HttpMethod method, string url, string JsonInput); | ||||
|         Task<string> SendAsync(HttpMethod method, string url, string JsonInput, string token); | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -4,6 +4,6 @@ namespace DamageAssesment.Api.Responses.Interfaces | ||||
| { | ||||
|     public interface ILocationServiceProvider | ||||
|     { | ||||
|         Task<List<Location>> getLocationsAsync(); | ||||
|         Task<List<Location>> getLocationsAsync(string token); | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -4,9 +4,9 @@ namespace DamageAssesment.Api.Responses.Interfaces | ||||
| { | ||||
|     public interface IQuestionServiceProvider | ||||
|     { | ||||
|         Task<List<Question>> getQuestionsAsync(string language); | ||||
|         Task<List<SurveyQuestions>> getSurveyQuestionsAsync(int surveyId); | ||||
|         Task<Question> getQuestionsAsync(int questionId); | ||||
|         Task<List<QuestionCategory>> GetQuestionCategoriesAsync(string? language); | ||||
|         Task<List<Question>> getQuestionsAsync(string language,string token); | ||||
|         Task<List<SurveyQuestions>> getSurveyQuestionsAsync(int surveyId, string token); | ||||
|         Task<Question> getQuestionsAsync(int questionId, string token); | ||||
|         Task<List<QuestionCategory>> GetQuestionCategoriesAsync(string? language, string token); | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -4,6 +4,6 @@ namespace DamageAssesment.Api.Responses.Interfaces | ||||
| { | ||||
|     public interface IRegionServiceProvider | ||||
|     { | ||||
|         Task<List<Region>> getRegionsAsync(); | ||||
|         Task<List<Region>> getRegionsAsync(string token); | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -4,7 +4,7 @@ namespace DamageAssesment.Api.Responses.Interfaces | ||||
| { | ||||
|     public interface ISurveyServiceProvider | ||||
|     { | ||||
|         Task<List<Survey>> getSurveysAsync(string language); | ||||
|         Task<Survey> getSurveyAsync(int surveyId); | ||||
|         Task<List<Survey>> getSurveysAsync(string language,string token); | ||||
|         Task<Survey> getSurveyAsync(int surveyId,string token); | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -11,6 +11,6 @@ namespace DamageAssesment.Api.Responses.Models | ||||
|         public string OfficePhoneNumber { get; set; } | ||||
|         public string Email { get; set; } | ||||
|         public bool IsActive { get; set; } | ||||
|         public string? PreferredLanguage { get; set; } | ||||
|         public string PreferredLanguage { get; set; } | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -5,6 +5,10 @@ using DamageAssesment.Api.Responses.Providers; | ||||
| using Microsoft.EntityFrameworkCore; | ||||
| using Polly; | ||||
| using System.Reflection; | ||||
| using Microsoft.OpenApi.Models; | ||||
| using Microsoft.AspNetCore.Authentication.JwtBearer; | ||||
| using Microsoft.IdentityModel.Tokens; | ||||
| using System.Text; | ||||
|  | ||||
| var builder = WebApplication.CreateBuilder(args); | ||||
| const int maxApiCallRetries = 3; | ||||
| @ -14,6 +18,24 @@ const int intervalForCircuitBraker = 5; //5 seconds | ||||
|  | ||||
|  | ||||
| // Add services to the container. | ||||
| var authkey = builder.Configuration.GetValue<string>("JwtSettings:securitykey"); | ||||
| builder.Services.AddAuthentication(item => | ||||
| { | ||||
|     item.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; | ||||
|     item.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; | ||||
| }).AddJwtBearer(item => | ||||
| { | ||||
|     item.RequireHttpsMetadata = true; | ||||
|     item.SaveToken = true; | ||||
|     item.TokenValidationParameters = new TokenValidationParameters() | ||||
|     { | ||||
|         ValidateIssuerSigningKey = true, | ||||
|         IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(authkey)), | ||||
|         ValidateIssuer = false, | ||||
|         ValidateAudience = false, | ||||
|         ClockSkew = TimeSpan.Zero | ||||
|     }; | ||||
| }); | ||||
|  | ||||
| builder.Services.AddControllers(); | ||||
| // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle | ||||
| @ -26,6 +48,7 @@ builder.Services.AddScoped<IQuestionServiceProvider, QuestionServiceProvider>(); | ||||
| builder.Services.AddScoped<IEmployeeServiceProvider, EmployeeServiceProvider>(); | ||||
| builder.Services.AddScoped<IAttachmentServiceProvider, AttachmentServiceProvider>(); | ||||
| builder.Services.AddScoped<ISurveyServiceProvider, SurveyServiceProvider>(); | ||||
| builder.Services.AddHttpContextAccessor(); | ||||
| builder.Services.AddScoped<IExcelExportService, ExcelExportService>(); | ||||
|  | ||||
| builder.Services.AddHttpClient<IHttpUtil, HttpUtil>(). | ||||
| @ -36,12 +59,40 @@ builder.Services.AddHttpClient<IHttpUtil, HttpUtil>(). | ||||
| builder.Services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies()); | ||||
| builder.Services.AddEndpointsApiExplorer(); | ||||
| //builder.Services.AddSwaggerGen(); | ||||
| builder.Services.AddSwaggerGen(c => | ||||
|  | ||||
| builder.Services.AddSwaggerGen(options => | ||||
| { | ||||
|     // Include XML comments from your assembly | ||||
|     var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; | ||||
|     var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); | ||||
|     c.IncludeXmlComments(xmlPath); | ||||
|     options.IncludeXmlComments(xmlPath); | ||||
|  | ||||
|     OpenApiSecurityScheme securityDefinition = new OpenApiSecurityScheme() | ||||
|     { | ||||
|         Name = "Bearer", | ||||
|         BearerFormat = "JWT", | ||||
|         Scheme = "bearer", | ||||
|         Description = "Specify the authorization token.", | ||||
|         In = ParameterLocation.Header, | ||||
|         Type = SecuritySchemeType.Http, | ||||
|     }; | ||||
|  | ||||
|     options.AddSecurityDefinition("jwt_auth", securityDefinition); | ||||
|  | ||||
|     // Make sure swagger UI requires a Bearer token specified | ||||
|     OpenApiSecurityScheme securityScheme = new OpenApiSecurityScheme() | ||||
|     { | ||||
|         Reference = new OpenApiReference() | ||||
|         { | ||||
|             Id = "jwt_auth", | ||||
|             Type = ReferenceType.SecurityScheme | ||||
|         } | ||||
|     }; | ||||
|     OpenApiSecurityRequirement securityRequirements = new OpenApiSecurityRequirement() | ||||
|     { | ||||
|         {securityScheme, new string[] { }}, | ||||
|     }; | ||||
|     options.AddSecurityRequirement(securityRequirements); | ||||
| }); | ||||
| builder.Services.AddDbContext<SurveyResponseDbContext>(option => | ||||
| { | ||||
| @ -56,6 +107,7 @@ if (app.Environment.IsDevelopment()) | ||||
|     app.UseSwaggerUI(); | ||||
| } | ||||
|  | ||||
| app.UseAuthentication(); | ||||
| app.UseAuthorization(); | ||||
|  | ||||
| app.MapControllers(); | ||||
|  | ||||
| @ -9,7 +9,7 @@ | ||||
|     } | ||||
|   }, | ||||
|   "profiles": { | ||||
|     "DamageAssesment.Api.SurveyResponses": { | ||||
|     "DamageAssesment.Api.Responses": { | ||||
|       "commandName": "Project", | ||||
|       "dotnetRunMessages": true, | ||||
|       "launchBrowser": true, | ||||
|  | ||||
| @ -2,6 +2,7 @@ | ||||
| using DamageAssesment.Api.Responses.Db; | ||||
| using DamageAssesment.Api.Responses.Interfaces; | ||||
| using DamageAssesment.Api.Responses.Models; | ||||
| using DamageAssesment.Api.Responses.Services; | ||||
| using Microsoft.EntityFrameworkCore; | ||||
| using Microsoft.EntityFrameworkCore.Metadata.Internal; | ||||
| using System.Reflection; | ||||
| @ -21,8 +22,10 @@ namespace DamageAssesment.Api.Responses.Providers | ||||
|         private readonly IQuestionServiceProvider questionServiceProvider; | ||||
|         private readonly ISurveyServiceProvider surveyServiceProvider; | ||||
|         private readonly IMapper mapper; | ||||
|         private readonly IHttpContextAccessor httpContextAccessor; | ||||
|         private string token; | ||||
|  | ||||
|         public SurveyResponsesProvider(SurveyResponseDbContext surveyResponseDbContext, ILogger<SurveyResponsesProvider> logger, IAnswerServiceProvider answerServiceProvider, IRegionServiceProvider regionServiceProvider, ILocationServiceProvider locationServiceProvider, IEmployeeServiceProvider employeeServiceProvider, IAttachmentServiceProvider attachmentServiceProvider, IQuestionServiceProvider questionServiceProvider, ISurveyServiceProvider surveyServiceProvider, IMapper mapper) | ||||
|         public SurveyResponsesProvider(SurveyResponseDbContext surveyResponseDbContext, ILogger<SurveyResponsesProvider> logger, IAnswerServiceProvider answerServiceProvider, IRegionServiceProvider regionServiceProvider, ILocationServiceProvider locationServiceProvider, IEmployeeServiceProvider employeeServiceProvider, IAttachmentServiceProvider attachmentServiceProvider, IQuestionServiceProvider questionServiceProvider, ISurveyServiceProvider surveyServiceProvider, IMapper mapper, IHttpContextAccessor httpContextAccessor) | ||||
|         { | ||||
|             this.surveyResponseDbContext = surveyResponseDbContext; | ||||
|             this.logger = logger; | ||||
| @ -33,8 +36,20 @@ namespace DamageAssesment.Api.Responses.Providers | ||||
|             this.attachmentServiceProvider = attachmentServiceProvider; | ||||
|             this.questionServiceProvider = questionServiceProvider; | ||||
|             this.surveyServiceProvider = surveyServiceProvider; | ||||
|             this.httpContextAccessor = httpContextAccessor; | ||||
|             this.mapper = mapper; | ||||
|             SeedData(); | ||||
|  | ||||
|             token = httpContextAccessor.HttpContext.Request.Headers.Authorization; | ||||
|             if (token != null) | ||||
|             { | ||||
|                 token = token.Replace("Bearer ", string.Empty); | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 token = ""; | ||||
|             } | ||||
|             // seedData(); | ||||
|         } | ||||
|  | ||||
|         public void SeedData() | ||||
| @ -120,7 +135,7 @@ namespace DamageAssesment.Api.Responses.Providers | ||||
|             { | ||||
|                 logger?.LogInformation("Querying to get SurveyResponse object from DB"); | ||||
|                 //get all the survey that already taken by the employee | ||||
|                 var surveys = await surveyServiceProvider.getSurveysAsync(language); | ||||
|                 var surveys = await surveyServiceProvider.getSurveysAsync(language,token); | ||||
|                 surveys = surveys.Where(s => s.IsEnabled == true && s.Status == SurveyStatus.ACTIVE.ToString()).ToList(); | ||||
|                 if (employeeid == null || employeeid == 0) | ||||
|                     return (true, surveys, null); | ||||
| @ -141,7 +156,7 @@ namespace DamageAssesment.Api.Responses.Providers | ||||
|             { | ||||
|                 logger?.LogInformation("Querying to get SurveyResponse object from DB"); | ||||
|  | ||||
|                 var surveys = await surveyServiceProvider.getSurveysAsync(language); | ||||
|                 var surveys = await surveyServiceProvider.getSurveysAsync(language, token); | ||||
|                 // returning only historic data: end date is less than current date. | ||||
|                 surveys = surveys.Where(s => s.Status == SurveyStatus.INACTIVE.ToString()).ToList(); | ||||
|                 if (employeeid == null || employeeid == 0) | ||||
| @ -166,7 +181,7 @@ namespace DamageAssesment.Api.Responses.Providers | ||||
|             try | ||||
|             { | ||||
|                 logger?.LogInformation("Querying to get Survey object from microservice"); | ||||
|                 var survey = await surveyServiceProvider.getSurveyAsync(surveyId); | ||||
|                 var survey = await surveyServiceProvider.getSurveyAsync(surveyId, token); | ||||
|  | ||||
|                 if (survey != null) | ||||
|                 { | ||||
| @ -197,7 +212,7 @@ namespace DamageAssesment.Api.Responses.Providers | ||||
|             try | ||||
|             { | ||||
|                 logger?.LogInformation("Querying to get Survey object from microservice"); | ||||
|                 var survey = await surveyServiceProvider.getSurveyAsync(surveyId); | ||||
|                 var survey = await surveyServiceProvider.getSurveyAsync(surveyId, token); | ||||
|  | ||||
|                 if (survey != null) | ||||
|                 { | ||||
| @ -228,7 +243,7 @@ namespace DamageAssesment.Api.Responses.Providers | ||||
|             try | ||||
|             { | ||||
|                 logger?.LogInformation("Querying to get Survey object from microservice"); | ||||
|                 var survey = await surveyServiceProvider.getSurveyAsync(surveyId); | ||||
|                 var survey = await surveyServiceProvider.getSurveyAsync(surveyId, token); | ||||
|  | ||||
|                 if (survey != null) | ||||
|                 { | ||||
| @ -259,8 +274,8 @@ namespace DamageAssesment.Api.Responses.Providers | ||||
|             try | ||||
|             { | ||||
|                 logger?.LogInformation("Querying to get Survey object from microservice"); | ||||
|                 var survey = await surveyServiceProvider.getSurveyAsync(surveyId); | ||||
|                 var question = await questionServiceProvider.getQuestionsAsync(questionId); | ||||
|                 var survey = await surveyServiceProvider.getSurveyAsync(surveyId, token); | ||||
|                 var question = await questionServiceProvider.getQuestionsAsync(questionId, token); | ||||
|                 bool IsCorrectAnswer = answer.ToLower().Equals("yes") || answer.ToLower().Equals("no") ? true : false; | ||||
|  | ||||
|  | ||||
| @ -421,7 +436,7 @@ namespace DamageAssesment.Api.Responses.Providers | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 var answersList = await answerServiceProvider.getAnswersAsync(); | ||||
|                 var answersList = await answerServiceProvider.getAnswersAsync(token); | ||||
|                 if (answersList == null || !answersList.Any()) | ||||
|                     return null; | ||||
|  | ||||
| @ -444,8 +459,8 @@ namespace DamageAssesment.Api.Responses.Providers | ||||
|                 if (surveyAnswers == null || !surveyAnswers.Any()) | ||||
|                     return null; | ||||
|  | ||||
|                 var regions = await regionServiceProvider.getRegionsAsync(); | ||||
|                 var locations = await locationServiceProvider.getLocationsAsync(); | ||||
|                 var regions = await regionServiceProvider.getRegionsAsync(token); | ||||
|                 var locations = await locationServiceProvider.getLocationsAsync(token); | ||||
|  | ||||
|                 if (regions == null || !regions.Any() || locations == null || !locations.Any()) | ||||
|                     return null; | ||||
| @ -507,11 +522,11 @@ namespace DamageAssesment.Api.Responses.Providers | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 var employee = await employeeServiceProvider.getEmployeeAsync(surveyResponse.EmployeeId); | ||||
|                 var answers = await answerServiceProvider.GetAnswersByResponseIdAsync(surveyResponse.Id); | ||||
|                 var allQuestions = await questionServiceProvider.getQuestionsAsync(null); | ||||
|                 var employee = await employeeServiceProvider.getEmployeeAsync(surveyResponse.EmployeeId, token); | ||||
|                 var answers = await answerServiceProvider.GetAnswersByResponseIdAsync(surveyResponse.Id, token); | ||||
|                 var allQuestions = await questionServiceProvider.getQuestionsAsync(null,token); | ||||
|                 var questions = allQuestions.Where(s => s.SurveyId == surveyResponse.SurveyId); | ||||
|                 var attachments = await attachmentServiceProvider.getAttachmentsAsync(); | ||||
|                 var attachments = await attachmentServiceProvider.getAttachmentsAsync(token); | ||||
|  | ||||
|                 var result = new | ||||
|                 { | ||||
| @ -556,85 +571,47 @@ namespace DamageAssesment.Api.Responses.Providers | ||||
|                 if (employeeid == 0) | ||||
|                 { | ||||
|                     surveyResonses = await surveyResponseDbContext.SurveyResponses.Where(x => x.SurveyId == surveyId).ToListAsync(); | ||||
|                     employees = await employeeServiceProvider.getEmployeesAsync(); | ||||
|                     employees = await employeeServiceProvider.getEmployeesAsync(token); | ||||
|                 } | ||||
|                 else | ||||
|                 { | ||||
|                     surveyResonses = await surveyResponseDbContext.SurveyResponses.Where(x => x.SurveyId == surveyId && x.EmployeeId == employeeid).ToListAsync(); | ||||
|                     employee = await employeeServiceProvider.getEmployeeAsync(employeeid); | ||||
|                     employee = await employeeServiceProvider.getEmployeeAsync(employeeid, token); | ||||
|                 } | ||||
|  | ||||
|                 var answers = await answerServiceProvider.getAnswersAsync(); | ||||
|                 var questions = await questionServiceProvider.getQuestionsAsync(null); | ||||
|                 var answers = await answerServiceProvider.getAnswersAsync(token); | ||||
|                 var questions = await questionServiceProvider.getQuestionsAsync(null, token); | ||||
|                 var surveyQuestions = from q in questions where q.SurveyId == surveyId select q; | ||||
|  | ||||
|                 //var surveyQuestions = await questionServiceProvider.getSurveyQuestionsAsync(surveyId); | ||||
|  | ||||
|                 var attachments = await attachmentServiceProvider.getAttachmentsAsync(); | ||||
|                 var attachments = await attachmentServiceProvider.getAttachmentsAsync(token); | ||||
|                 var result = from r in surveyResonses | ||||
|                              select new | ||||
|                              { | ||||
|                                  r.Id, | ||||
|                                  r.SurveyId, | ||||
|                                  r.LocationId, | ||||
|                                  r.EmployeeId, | ||||
|                                  r.ClientDevice, | ||||
|                                  r.KeyAnswerResult, | ||||
|                                  r.Longitute, | ||||
|                                  r.Latitude, | ||||
|                                  Employee = (from e in employees where e.Id == r.EmployeeId select new { e.Id, e.Name, e.BirthDate, e.Email, e.OfficePhoneNumber }).SingleOrDefault(), | ||||
|                                  answers = from ans in answers | ||||
|                                            where ans.SurveyResponseId == r.Id | ||||
|                                            select new | ||||
|                                            { | ||||
|                                                ans.Id, | ||||
|                                                ans.QuestionId, | ||||
|                                                ans.AnswerText, | ||||
|                                                ans.Comment, | ||||
|                                                Questions = (from q in surveyQuestions where q.Id == ans.QuestionId select new { q.Id, q.QuestionNumber, q.CategoryId, q.Text }).SingleOrDefault(), | ||||
|                                                Attachments = from att in attachments where att.AnswerId == ans.Id select new { att.Id, att.URI } | ||||
|  | ||||
|                 if (employeeid == 0) | ||||
|                 { | ||||
|                     var result = from r in surveyResonses | ||||
|                                  select new | ||||
|                                  { | ||||
|                                      r.Id, | ||||
|                                      r.SurveyId, | ||||
|                                      r.LocationId, | ||||
|                                      r.EmployeeId, | ||||
|                                      r.ClientDevice, | ||||
|                                      r.KeyAnswerResult, | ||||
|                                      r.Longitute, | ||||
|                                      r.Latitude, | ||||
|                                      Employee = (from e in employees where e.Id == r.EmployeeId select new { e.Id, e.Name, e.BirthDate, e.Email, e.OfficePhoneNumber }).SingleOrDefault(), | ||||
|                                      answers = from ans in answers | ||||
|                                                where ans.SurveyResponseId == r.Id | ||||
|                                                select new | ||||
|                                                { | ||||
|                                                    ans.Id, | ||||
|                                                    ans.QuestionId, | ||||
|                                                    ans.AnswerText, | ||||
|                                                    ans.Comment, | ||||
|                                                    Questions = (from q in surveyQuestions where q.Id == ans.QuestionId select new { q.Id, q.QuestionNumber, q.CategoryId, q.Text }).SingleOrDefault(), | ||||
|                                                    Attachments = from att in attachments where att.AnswerId == ans.Id select new { att.Id, att.URI } | ||||
|  | ||||
|                                                } | ||||
|                                  }; | ||||
|                     return result; | ||||
|                 } | ||||
|                 else | ||||
|                 { | ||||
|                     object _employee = new { }; | ||||
|                     if (employee != null) | ||||
|                     { | ||||
|                         _employee = new { employee.Id, employee.Name, employee.BirthDate, employee.Email, employee.OfficePhoneNumber }; | ||||
|                     } | ||||
|                     var result = from r in surveyResonses | ||||
|                                  select new | ||||
|                                  { | ||||
|                                      r.Id, | ||||
|                                      r.SurveyId, | ||||
|                                      r.LocationId, | ||||
|                                      r.EmployeeId, | ||||
|                                      r.ClientDevice, | ||||
|                                      r.KeyAnswerResult, | ||||
|                                      r.Longitute, | ||||
|                                      r.Latitude, | ||||
|                                      Employee = _employee, | ||||
|                                      answers = from ans in answers | ||||
|                                                where ans.SurveyResponseId == r.Id | ||||
|                                                select new | ||||
|                                                { | ||||
|                                                    ans.Id, | ||||
|                                                    ans.QuestionId, | ||||
|                                                    ans.AnswerText, | ||||
|                                                    ans.Comment, | ||||
|                                                    Questions = (from q in questions where q.Id == ans.QuestionId select new { q.Id, q.QuestionNumber, q.CategoryId, q.Text }).SingleOrDefault(), | ||||
|                                                    Attachments = from att in attachments where att.AnswerId == ans.Id select new { att.Id, att.URI } | ||||
|                                                } | ||||
|                                  }; | ||||
|  | ||||
|                     return result; | ||||
|                 } | ||||
|                                            } | ||||
|                              }; | ||||
|                 return result; | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
| @ -656,12 +633,12 @@ namespace DamageAssesment.Api.Responses.Providers | ||||
|                 if (employeeid == 0) | ||||
|                 { | ||||
|                     surveyResonses = await surveyResponseDbContext.SurveyResponses.ToListAsync(); | ||||
|                     employees = await employeeServiceProvider.getEmployeesAsync(); | ||||
|                     employees = await employeeServiceProvider.getEmployeesAsync(token); | ||||
|                 } | ||||
|                 else | ||||
|                 { | ||||
|                     surveyResonses = await surveyResponseDbContext.SurveyResponses.Where(x => x.EmployeeId == employeeid).ToListAsync(); | ||||
|                     employee = await employeeServiceProvider.getEmployeeAsync(employeeid); | ||||
|                     employee = await employeeServiceProvider.getEmployeeAsync(employeeid, token); | ||||
|  | ||||
|                     if (employee != null) | ||||
|                     { | ||||
| @ -670,9 +647,9 @@ namespace DamageAssesment.Api.Responses.Providers | ||||
|                 } | ||||
|  | ||||
|  | ||||
|                 var answers = await answerServiceProvider.getAnswersAsync(); | ||||
|                 var questions = await questionServiceProvider.getQuestionsAsync(null); | ||||
|                 var attachments = await attachmentServiceProvider.getAttachmentsAsync(); | ||||
|                 var answers = await answerServiceProvider.getAnswersAsync(token); | ||||
|                 var questions = await questionServiceProvider.getQuestionsAsync(null,token); | ||||
|                 var attachments = await attachmentServiceProvider.getAttachmentsAsync(token); | ||||
|  | ||||
|                 var result = from r in surveyResonses | ||||
|                              select new | ||||
| @ -699,8 +676,6 @@ namespace DamageAssesment.Api.Responses.Providers | ||||
|                                            } | ||||
|                              }; | ||||
|                 return result; | ||||
|  | ||||
|  | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
| @ -716,12 +691,12 @@ namespace DamageAssesment.Api.Responses.Providers | ||||
|                 if (string.IsNullOrEmpty(language)) language = "en"; | ||||
|                 List<Db.SurveyResponse> surveyResonses; | ||||
|                 surveyResonses = await surveyResponseDbContext.SurveyResponses.Where(a => a.SurveyId == surveyId).ToListAsync(); | ||||
|                 var answers = await answerServiceProvider.getAnswersAsync(); | ||||
|                 var Locations = await locationServiceProvider.getLocationsAsync(); | ||||
|                 var regions = await regionServiceProvider.getRegionsAsync(); | ||||
|                 var questions = await questionServiceProvider.getQuestionsAsync(language); | ||||
|                 var categories = await questionServiceProvider.GetQuestionCategoriesAsync(language); | ||||
|                 var attachments = await attachmentServiceProvider.getAttachmentsAsync(); | ||||
|                 var answers = await answerServiceProvider.getAnswersAsync(token); | ||||
|                 var Locations = await locationServiceProvider.getLocationsAsync(token); | ||||
|                 var regions = await regionServiceProvider.getRegionsAsync(token); | ||||
|                 var questions = await questionServiceProvider.getQuestionsAsync(language, token); | ||||
|                 var categories = await questionServiceProvider.GetQuestionCategoriesAsync(language, token); | ||||
|                 var attachments = await attachmentServiceProvider.getAttachmentsAsync(token); | ||||
|                 List<object> questionLists = new List<object>(); | ||||
|                 var allques = from res in surveyResonses | ||||
|                               join loc in Locations on res.LocationId equals loc.Id | ||||
| @ -853,8 +828,8 @@ namespace DamageAssesment.Api.Responses.Providers | ||||
|                 { | ||||
|                     surveyResponses = await surveyResponseDbContext.SurveyResponses.Where(x => x.SurveyId == surveyId && x.EmployeeId == employeeid).ToListAsync(); | ||||
|                 } | ||||
|                 var answers = await answerServiceProvider.getAnswersAsync(); | ||||
|                 var locations = await locationServiceProvider.getLocationsAsync(); | ||||
|                 var answers = await answerServiceProvider.getAnswersAsync(token); | ||||
|                 var locations = await locationServiceProvider.getLocationsAsync(token); | ||||
|                 var maintenanceCenters = locations.DistinctBy(m => m.MaintenanceCenter); | ||||
|  | ||||
|                 //get all the answers for the particular survey | ||||
| @ -920,12 +895,12 @@ namespace DamageAssesment.Api.Responses.Providers | ||||
|                 if (employeeid == 0) | ||||
|                 { | ||||
|                     surveyResonses = await surveyResponseDbContext.SurveyResponses.Where(x => x.SurveyId == surveyId && x.LocationId == locationId).ToListAsync(); | ||||
|                     employees = await employeeServiceProvider.getEmployeesAsync(); | ||||
|                     employees = await employeeServiceProvider.getEmployeesAsync(token); | ||||
|                 } | ||||
|                 else | ||||
|                 { | ||||
|                     surveyResonses = await surveyResponseDbContext.SurveyResponses.Where(x => x.SurveyId == surveyId && x.EmployeeId == employeeid && x.LocationId == locationId).ToListAsync(); | ||||
|                     employee = await employeeServiceProvider.getEmployeeAsync(employeeid); | ||||
|                     employee = await employeeServiceProvider.getEmployeeAsync(employeeid, token); | ||||
|  | ||||
|                     if (employee != null) | ||||
|                     { | ||||
| @ -933,10 +908,10 @@ namespace DamageAssesment.Api.Responses.Providers | ||||
|                     } | ||||
|                 } | ||||
|  | ||||
|                 var answers = await answerServiceProvider.getAnswersAsync(); | ||||
|                 var questions = await questionServiceProvider.getQuestionsAsync(null); | ||||
|                 var answers = await answerServiceProvider.getAnswersAsync(token); | ||||
|                 var questions = await questionServiceProvider.getQuestionsAsync(null,token); | ||||
|                 var surveyQuestions = from q in questions where q.SurveyId == surveyId select q; | ||||
|                 var attachments = await attachmentServiceProvider.getAttachmentsAsync(); | ||||
|                 var attachments = await attachmentServiceProvider.getAttachmentsAsync(token); | ||||
|  | ||||
|                 var result = from r in surveyResonses | ||||
|                              select new | ||||
| @ -949,7 +924,7 @@ namespace DamageAssesment.Api.Responses.Providers | ||||
|                                  r.KeyAnswerResult, | ||||
|                                  r.Longitute, | ||||
|                                  r.Latitude, | ||||
|                                  Employee = employeeid != 0 ? _employee : (from e in employees where r.EmployeeId == e.Id select new { e.Id, e.Name, e.BirthDate, e.Email, e.OfficePhoneNumber }).SingleOrDefault(), | ||||
|                                  Employee = (from e in employees where r.EmployeeId == e.Id select new { e.Id, e.Name, e.BirthDate, e.Email, e.OfficePhoneNumber }).SingleOrDefault(), | ||||
|                                  answers = from ans in answers | ||||
|                                            where ans.SurveyResponseId == r.Id | ||||
|  | ||||
| @ -964,7 +939,6 @@ namespace DamageAssesment.Api.Responses.Providers | ||||
|                                            } | ||||
|                              }; | ||||
|                 return result; | ||||
|  | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
| @ -987,12 +961,12 @@ namespace DamageAssesment.Api.Responses.Providers | ||||
|                 if (employeeid == 0) | ||||
|                 { | ||||
|                     surveyResponses = await surveyResponseDbContext.SurveyResponses.Where(x => x.SurveyId == survey.Id).ToListAsync(); | ||||
|                     employees = await employeeServiceProvider.getEmployeesAsync(); | ||||
|                     employees = await employeeServiceProvider.getEmployeesAsync(token); | ||||
|                 } | ||||
|                 else | ||||
|                 { | ||||
|                     surveyResponses = await surveyResponseDbContext.SurveyResponses.Where(x => x.SurveyId == survey.Id && x.EmployeeId == employeeid).ToListAsync(); | ||||
|                     employee = await employeeServiceProvider.getEmployeeAsync(employeeid); | ||||
|                     employee = await employeeServiceProvider.getEmployeeAsync(employeeid, token); | ||||
|  | ||||
|                     if (employee != null) | ||||
|                     { | ||||
| @ -1002,8 +976,8 @@ namespace DamageAssesment.Api.Responses.Providers | ||||
|  | ||||
|                 //var surveyResponses = await surveyResponseDbContext.Responses.Where(x => x.SurveyId == survey.Id).ToListAsync(); | ||||
|                 // var employees = await employeeServiceProvider.getEmployeesAsync(); | ||||
|                 var answers = await answerServiceProvider.getAnswersAsync(); | ||||
|                 var attachments = await attachmentServiceProvider.getAttachmentsAsync(); | ||||
|                 var answers = await answerServiceProvider.getAnswersAsync(token); | ||||
|                 var attachments = await attachmentServiceProvider.getAttachmentsAsync(token); | ||||
|  | ||||
|                 var result = from r in surveyResponses | ||||
|                              select new | ||||
| @ -1016,7 +990,7 @@ namespace DamageAssesment.Api.Responses.Providers | ||||
|                                  r.KeyAnswerResult, | ||||
|                                  r.Longitute, | ||||
|                                  r.Latitude, | ||||
|                                  Employee = employeeid != 0 ? _employee : (from e in employees where r.EmployeeId == e.Id select new { e.Id, e.Name, e.BirthDate, e.Email, e.OfficePhoneNumber }).SingleOrDefault(), | ||||
|                                  Employee = (from e in employees where r.EmployeeId == e.Id select new { e.Id, e.Name, e.BirthDate, e.Email, e.OfficePhoneNumber }).SingleOrDefault(), | ||||
|                                  answers = from ans in answers | ||||
|                                            where ans.SurveyResponseId == r.Id | ||||
|                                            && ans.QuestionId == question.Id | ||||
| @ -1046,12 +1020,12 @@ namespace DamageAssesment.Api.Responses.Providers | ||||
|         { | ||||
|             if (answerRequest != null) | ||||
|             { | ||||
|                 var answer = await answerServiceProvider.PostAnswersAsync(new Models.Answer { QuestionId = answerRequest.QuestionId, AnswerText = answerRequest.AnswerText, Comment = answerRequest.Comment, SurveyResponseId = surveyResponseId }); | ||||
|                 var answer = await answerServiceProvider.PostAnswersAsync(new Models.Answer { QuestionId = answerRequest.QuestionId, AnswerText = answerRequest.AnswerText, Comment = answerRequest.Comment, SurveyResponseId = surveyResponseId }, token); | ||||
|                 if (answer != null) | ||||
|                 { | ||||
|                     List<AnswerInfo> listAnswerInfo = new List<AnswerInfo>(); | ||||
|                     listAnswerInfo.Add(new AnswerInfo { AnswerId = answer.Id, postedFiles = answerRequest.PostedFiles }); | ||||
|                     var attachments = attachmentServiceProvider.PostAttachmentsAsync(new AttachmentInfo { ResponseId = surveyResponseId, Answers = listAnswerInfo }); | ||||
|                     var attachments = attachmentServiceProvider.PostAttachmentsAsync(new AttachmentInfo { ResponseId = surveyResponseId, Answers = listAnswerInfo }, token); | ||||
|  | ||||
|                     string message = $"Answer for question {answerRequest.QuestionId} saved to the database"; | ||||
|                     logger?.LogInformation(message); | ||||
| @ -1072,7 +1046,6 @@ namespace DamageAssesment.Api.Responses.Providers | ||||
|             } | ||||
|         } | ||||
|  | ||||
|  | ||||
|         public async Task<(bool IsSuccess, Models.SurveyResponse SurveyResponse, string ErrorMessage)> PostSurveyAnswersAsync(Models.Request request) | ||||
|         { | ||||
|             try | ||||
|  | ||||
| @ -1,5 +1,6 @@ | ||||
| using DamageAssesment.Api.Responses.Interfaces; | ||||
| using DamageAssesment.Api.Responses.Models; | ||||
| using Microsoft.Extensions.Primitives; | ||||
| using Newtonsoft.Json; | ||||
|  | ||||
|  | ||||
| @ -10,11 +11,11 @@ namespace DamageAssesment.Api.Responses.Services | ||||
|         public AnswerServiceProvider(IConfiguration configuration, IHttpUtil httpUtil, ILogger<AnswerServiceProvider> logger) : base(configuration, httpUtil, logger, configuration.GetValue<string>("RessourceSettings:Answer"), configuration.GetValue<string>("EndPointSettings:AnswerUrlBase")) | ||||
|         { | ||||
|         } | ||||
|         public async Task<List<Answer>> getAnswersAsync() | ||||
|         public async Task<List<Answer>> getAnswersAsync(string token) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null); | ||||
|                 var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null, token); | ||||
|                 var answers = JsonConvert.DeserializeObject<List<Answer>>(responseJsonString); | ||||
|  | ||||
|                 if (answers == null || !answers.Any()) | ||||
| @ -28,12 +29,12 @@ namespace DamageAssesment.Api.Responses.Services | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async Task<List<Answer>> GetAnswersByResponseIdAsync(int responseId) | ||||
|         public async Task<List<Answer>> GetAnswersByResponseIdAsync(int responseId, string token) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 url = urlBase + string.Format(configuration.GetValue<string>("RessourceSettings:AnswerByResponse"), responseId); | ||||
|                 var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null); | ||||
|                 var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null,token); | ||||
|                 var answers = JsonConvert.DeserializeObject<List<Answer>>(responseJsonString); | ||||
|  | ||||
|                 if (answers == null || !answers.Any()) | ||||
| @ -47,12 +48,12 @@ namespace DamageAssesment.Api.Responses.Services | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async Task<Answer> PostAnswersAsync(Answer answer) | ||||
|         public async Task<Answer> PostAnswersAsync(Answer answer, string token ) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 var requestJsonString = JsonConvert.SerializeObject(answer); | ||||
|                 var responseJsonString = await httpUtil.SendAsync(HttpMethod.Post, url, requestJsonString); | ||||
|                 var responseJsonString = await httpUtil.SendAsync(HttpMethod.Post, url, requestJsonString, token); | ||||
|                 var answers = JsonConvert.DeserializeObject<Answer>(responseJsonString); | ||||
|  | ||||
|                 if (answers == null) | ||||
|  | ||||
| @ -10,11 +10,11 @@ namespace DamageAssesment.Api.Responses.Services | ||||
|         { | ||||
|         } | ||||
|  | ||||
|         public async Task<List<Attachment>> getAttachmentsAsync() | ||||
|         public async Task<List<Attachment>> getAttachmentsAsync(string token) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null); | ||||
|                 var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null,token); | ||||
|                 var attachments = JsonConvert.DeserializeObject<List<Attachment>>(responseJsonString); | ||||
|  | ||||
|                 if (attachments == null || !attachments.Any()) | ||||
| @ -28,12 +28,12 @@ namespace DamageAssesment.Api.Responses.Services | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async Task<IEnumerable<Attachment>> PostAttachmentsAsync(AttachmentInfo attachmentInfo) | ||||
|         public async Task<IEnumerable<Attachment>> PostAttachmentsAsync(AttachmentInfo attachmentInfo, string token) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 var requestJsonString = JsonConvert.SerializeObject(attachmentInfo); | ||||
|                 var responseJsonString = await httpUtil.SendAsync(HttpMethod.Post, url, requestJsonString); | ||||
|                 var responseJsonString = await httpUtil.SendAsync(HttpMethod.Post, url, requestJsonString, token); | ||||
|                 var attachments = JsonConvert.DeserializeObject<IEnumerable<Attachment>>(responseJsonString); | ||||
|  | ||||
|                 if (attachments == null) | ||||
|  | ||||
| @ -1,4 +1,4 @@ | ||||
| using DamageAssesment.Api.Responses.Interfaces; | ||||
| using DamageAssesment.Api.Responses.Interfaces; | ||||
| using DamageAssesment.Api.Responses.Models; | ||||
| using Microsoft.AspNetCore.Mvc.Routing; | ||||
| using Newtonsoft.Json; | ||||
| @ -11,11 +11,11 @@ namespace DamageAssesment.Api.Responses.Services | ||||
|         { | ||||
|         } | ||||
|  | ||||
|         public async Task<List<Employee>> getEmployeesAsync() | ||||
|         public async Task<List<Employee>> getEmployeesAsync(string token) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null); | ||||
|                 var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null, token); | ||||
|                 var employees = JsonConvert.DeserializeObject<List<Employee>>(responseJsonString); | ||||
|  | ||||
|                 if (employees == null || !employees.Any()) | ||||
| @ -29,12 +29,12 @@ namespace DamageAssesment.Api.Responses.Services | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async Task<Employee> getEmployeeAsync(int employeeId) | ||||
|         public async Task<Employee> getEmployeeAsync(int employeeId, string token) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 url = urlBase + string.Format(configuration.GetValue<string>("RessourceSettings:EmployeeById"), employeeId);  | ||||
|                 var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null); | ||||
|                 url = urlBase + string.Format(configuration.GetValue<string>("RessourceSettings:EmployeeById"), employeeId); | ||||
|                 var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null, token); | ||||
|                 var employee = JsonConvert.DeserializeObject<Employee>(responseJsonString); | ||||
|  | ||||
|                 if (employee == null) | ||||
|  | ||||
| @ -1,4 +1,5 @@ | ||||
| using DamageAssesment.Api.Responses.Interfaces; | ||||
| using DamageAssesment.Api.Responses.Interfaces; | ||||
| using DamageAssesment.Api.Responses.Models; | ||||
| using System.Net.Http.Headers; | ||||
| using System.Text; | ||||
|  | ||||
| @ -14,20 +15,18 @@ namespace DamageAssesment.Api.Responses.Services | ||||
|             this.httpClient = httpClient; | ||||
|             this.logger = logger; | ||||
|         } | ||||
|         public async Task<string> SendAsync(HttpMethod method, string url, string JsonInput) | ||||
|         public async Task<string> SendAsync(HttpMethod method, string url, string JsonInput, string token) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 var request = new HttpRequestMessage(method, url); | ||||
|                 request.Headers.Accept.Clear(); | ||||
|                 request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); | ||||
|  | ||||
|                 //request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token); | ||||
|                 request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token); | ||||
|                 if (method == HttpMethod.Post) | ||||
|                 { | ||||
|                     request.Content = new StringContent(JsonInput, Encoding.UTF8, "application/json"); | ||||
|                 } | ||||
|  | ||||
|                 var response = await httpClient.SendAsync(request, CancellationToken.None); | ||||
|                 response.EnsureSuccessStatusCode(); | ||||
|                 var responseString = await response.Content.ReadAsStringAsync(); | ||||
|  | ||||
| @ -10,11 +10,11 @@ namespace DamageAssesment.Api.Responses.Services | ||||
|         { | ||||
|         } | ||||
|  | ||||
|         public async Task<List<Location>> getLocationsAsync() | ||||
|         public async Task<List<Location>> getLocationsAsync(string token) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null); | ||||
|                 var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null, token); | ||||
|                 var locations = JsonConvert.DeserializeObject<List<Location>>(responseJsonString); | ||||
|  | ||||
|                 if (locations == null || !locations.Any()) | ||||
|  | ||||
| @ -1,6 +1,7 @@ | ||||
| using DamageAssesment.Api.Responses.Interfaces; | ||||
| using DamageAssesment.Api.Responses.Models; | ||||
| using Newtonsoft.Json; | ||||
| using OfficeOpenXml.FormulaParsing.LexicalAnalysis; | ||||
|  | ||||
| namespace DamageAssesment.Api.Responses.Services | ||||
| { | ||||
| @ -10,13 +11,13 @@ namespace DamageAssesment.Api.Responses.Services | ||||
|         { | ||||
|         } | ||||
|  | ||||
|         public async Task<List<Question>> getQuestionsAsync(string language) | ||||
|         public async Task<List<Question>> getQuestionsAsync(string language,string token) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 if (!string.IsNullOrEmpty(language)) | ||||
|                     url = url + "/" + language; | ||||
|                 var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null); | ||||
|                 var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null,token); | ||||
|                 var questions = JsonConvert.DeserializeObject<List<Question>>(responseJsonString); | ||||
|  | ||||
|                 if (questions == null || !questions.Any()) | ||||
| @ -29,7 +30,7 @@ namespace DamageAssesment.Api.Responses.Services | ||||
|                 return new List<Question>(); | ||||
|             } | ||||
|         } | ||||
|         public async Task<List<QuestionCategory>> GetQuestionCategoriesAsync(string? language) | ||||
|         public async Task<List<QuestionCategory>> GetQuestionCategoriesAsync(string? language,string token) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
| @ -37,7 +38,7 @@ namespace DamageAssesment.Api.Responses.Services | ||||
|  | ||||
|                 if (!string.IsNullOrEmpty(language)) | ||||
|                     url = url + "/" + language; | ||||
|                 var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null); | ||||
|                 var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null, token); | ||||
|                 var questions = JsonConvert.DeserializeObject<List<QuestionCategory>>(responseJsonString); | ||||
|  | ||||
|                 if (questions == null || !questions.Any()) | ||||
| @ -50,13 +51,12 @@ namespace DamageAssesment.Api.Responses.Services | ||||
|                 return new List<QuestionCategory>(); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async Task<List<SurveyQuestions>> getSurveyQuestionsAsync(int surveyId) | ||||
|         public async Task<List<SurveyQuestions>> getSurveyQuestionsAsync(int surveyId, string token) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 url = urlBase + string.Format(configuration.GetValue<string>("RessourceSettings:SurveyQuestion"), surveyId); | ||||
|                 var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null); | ||||
|                 var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null, token); | ||||
|                 var questions = JsonConvert.DeserializeObject<List<SurveyQuestions>>(responseJsonString); | ||||
|  | ||||
|                 if (questions == null || !questions.Any()) | ||||
| @ -71,12 +71,12 @@ namespace DamageAssesment.Api.Responses.Services | ||||
|         } | ||||
|  | ||||
|  | ||||
|         public async Task<Question> getQuestionsAsync(int questionId) | ||||
|         public async Task<Question> getQuestionsAsync(int questionId, string token) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 url = urlBase + string.Format(configuration.GetValue<string>("RessourceSettings:QuestionById"), questionId); | ||||
|                 var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null); | ||||
|                 var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null, token); | ||||
|                 var question = JsonConvert.DeserializeObject<Question>(responseJsonString); | ||||
|  | ||||
|                 if (question == null) | ||||
|  | ||||
| @ -9,11 +9,11 @@ namespace DamageAssesment.Api.Responses.Services | ||||
|         public RegionServiceProvider(IConfiguration configuration, IHttpUtil httpUtil, ILogger<RegionServiceProvider> logger) : base(configuration, httpUtil, logger, configuration.GetValue<string>("RessourceSettings:Region"), configuration.GetValue<string>("EndPointSettings:LocationUrlBase")) | ||||
|         { | ||||
|         } | ||||
|         public async Task<List<Region>> getRegionsAsync() | ||||
|         public async Task<List<Region>> getRegionsAsync(string token) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null); | ||||
|                 var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null, token); | ||||
|                 var regions = JsonConvert.DeserializeObject<List<Region>>(responseJsonString); | ||||
|  | ||||
|                 if (regions == null || !regions.Any()) | ||||
|  | ||||
| @ -10,13 +10,13 @@ namespace DamageAssesment.Api.Responses.Services | ||||
|         { | ||||
|         } | ||||
|  | ||||
|         public async Task<List<Survey>> getSurveysAsync(string language) | ||||
|         public async Task<List<Survey>> getSurveysAsync(string language, string token) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 if (!string.IsNullOrEmpty(language)) | ||||
|                     url = url + "/" + language; | ||||
|                 var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null); | ||||
|                 var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null,token); | ||||
|                 var surveys = JsonConvert.DeserializeObject<List<Survey>>(responseJsonString); | ||||
|  | ||||
|                 if (surveys == null || !surveys.Any()) | ||||
| @ -30,12 +30,12 @@ namespace DamageAssesment.Api.Responses.Services | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async Task<Survey> getSurveyAsync(int surveyId) | ||||
|         public async Task<Survey> getSurveyAsync(int surveyId, string token) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 url = urlBase + string.Format(configuration.GetValue<string>("RessourceSettings:SurveyById"), surveyId); | ||||
|                 var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null); | ||||
|                 var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null, token); | ||||
|                 var survey = JsonConvert.DeserializeObject<Survey>(responseJsonString); | ||||
|  | ||||
|                 if (survey == null) | ||||
|  | ||||
		Reference in New Issue
	
	Block a user