From 96ccb96bf1d0015ae1816e4a496cc18eba7f1587 Mon Sep 17 00:00:00 2001 From: Reginald Cherenfant Jasmin Date: Sun, 27 Aug 2023 11:55:58 -0400 Subject: [PATCH] Update to Async Attachement, Answer and Update Multiple Answers submission - backlog #288 --- .../AnswersServiceTest.cs | 20 +- .../Controllers/AnswersController.cs | 8 +- .../Interfaces/IAnswersProvider.cs | 4 +- .../Providers/AnswerProvider.cs | 13 +- .../AttachmentsServiceTest.cs | 16 +- .../Controllers/AttachmentsController.cs | 12 +- .../Response-1/Answer-1/Attachment_1.txt | 1 - .../Interfaces/IAttachmentsProvider.cs | 8 +- .../Providers/AttachmentsProvider.cs | 18 +- .../EmployeeServiceTest.cs | 12 +- .../MockData.cs | 8 +- .../LocationsServiceTest.cs | 4 +- .../Controllers/SurveyResponsesController.cs | 6 +- .../Db/SurveyResponseDbContext.cs | 8 + .../Interfaces/ISurveysResponse.cs | 2 +- .../Models/AnswerRequest.cs | 8 +- .../Models/Question.cs | 2 +- .../Models/QuestionRequest.cs | 10 - .../Models/Request.cs | 10 + .../Program.cs | 1 + .../Providers/AnswerServiceProvider.cs | 23 +- .../Providers/AttachmentServiceProvider.cs | 13 +- .../Providers/SurveyResponsesProvider.cs | 97 ++--- .../Bases/ServiceProviderBase.cs | 21 -- .../Controllers/UsersAccessController.cs | 97 ----- .../DamageAssesment.Api.UsersAccess.csproj | 19 - .../Db/Role.cs | 21 -- .../Db/Token.cs | 17 - .../Db/User.cs | 27 -- .../Db/UsersAccessDbContext.cs | 17 - .../Interfaces/IEmployeeServiceProvider.cs | 10 - .../Interfaces/IRoleProvider.cs | 12 - .../Interfaces/ITokenServiceProvider.cs | 11 - .../Interfaces/IUsersAccessProvider.cs | 16 - .../Models/Employee.cs | 21 -- .../Models/JwtSettings.cs | 9 - .../Models/Role.cs | 9 - .../Models/Token.cs | 10 - .../Models/TokenResponse.cs | 8 - .../Models/User.cs | 12 - .../Models/UserCredentials.cs | 5 - .../Profiles/UsersAccessProfile.cs | 14 - .../Program.cs | 77 ---- .../Properties/launchSettings.json | 31 -- .../Providers/EmployeeServiceProvider.cs | 58 --- .../Providers/TokenServiceProvider.cs | 57 --- .../Providers/UserAccessProvider.cs | 341 ------------------ .../appsettings.Development.json | 8 - .../appsettings.json | 15 - DamageAssesmentApi/DamageAssesment.sln | 6 - 50 files changed, 166 insertions(+), 1087 deletions(-) delete mode 100644 DamageAssesmentApi/DamageAssesment.Api.Attachments/DMS_Attachments/Active/Response-1/Answer-1/Attachment_1.txt delete mode 100644 DamageAssesmentApi/DamageAssesment.Api.SurveyResponses/Models/QuestionRequest.cs create mode 100644 DamageAssesmentApi/DamageAssesment.Api.SurveyResponses/Models/Request.cs delete mode 100644 DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Bases/ServiceProviderBase.cs delete mode 100644 DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Controllers/UsersAccessController.cs delete mode 100644 DamageAssesmentApi/DamageAssesment.Api.UsersAccess/DamageAssesment.Api.UsersAccess.csproj delete mode 100644 DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Db/Role.cs delete mode 100644 DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Db/Token.cs delete mode 100644 DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Db/User.cs delete mode 100644 DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Db/UsersAccessDbContext.cs delete mode 100644 DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Interfaces/IEmployeeServiceProvider.cs delete mode 100644 DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Interfaces/IRoleProvider.cs delete mode 100644 DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Interfaces/ITokenServiceProvider.cs delete mode 100644 DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Interfaces/IUsersAccessProvider.cs delete mode 100644 DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Models/Employee.cs delete mode 100644 DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Models/JwtSettings.cs delete mode 100644 DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Models/Role.cs delete mode 100644 DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Models/Token.cs delete mode 100644 DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Models/TokenResponse.cs delete mode 100644 DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Models/User.cs delete mode 100644 DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Models/UserCredentials.cs delete mode 100644 DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Profiles/UsersAccessProfile.cs delete mode 100644 DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Program.cs delete mode 100644 DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Properties/launchSettings.json delete mode 100644 DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Providers/EmployeeServiceProvider.cs delete mode 100644 DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Providers/TokenServiceProvider.cs delete mode 100644 DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Providers/UserAccessProvider.cs delete mode 100644 DamageAssesmentApi/DamageAssesment.Api.UsersAccess/appsettings.Development.json delete mode 100644 DamageAssesmentApi/DamageAssesment.Api.UsersAccess/appsettings.json diff --git a/DamageAssesmentApi/DamageAssesment.Api.Answers.Test/AnswersServiceTest.cs b/DamageAssesmentApi/DamageAssesment.Api.Answers.Test/AnswersServiceTest.cs index ad6ec72..0969153 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Answers.Test/AnswersServiceTest.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Answers.Test/AnswersServiceTest.cs @@ -95,10 +95,10 @@ namespace DamageAssesment.Api.Answers.Test var mockAnswerService = new Mock(); var mockResponse = await MockData.getOkResponse(1); var mockInputAnswer = await MockData.getInputAnswerData(); - mockAnswerService.Setup(service => service.PostAnswerAsync(mockInputAnswer)).Returns(mockResponse); + mockAnswerService.Setup(service => service.PostAnswerAsync(mockInputAnswer)).ReturnsAsync(mockResponse); var AnswerProvider = new AnswersController(mockAnswerService.Object); - var result = (OkObjectResult) AnswerProvider.CreateAnswer(mockInputAnswer); + var result = (OkObjectResult) await AnswerProvider.CreateAnswer(mockInputAnswer); Assert.Equal(200, result.StatusCode); } @@ -109,10 +109,10 @@ namespace DamageAssesment.Api.Answers.Test var mockAnswerService = new Mock(); var mockInputAnswer = await MockData.getInputAnswerData(); var mockResponse = await MockData.getBadRequestResponse(); - mockAnswerService.Setup(service => service.PostAnswerAsync(mockInputAnswer)).Returns(mockResponse); + mockAnswerService.Setup(service => service.PostAnswerAsync(mockInputAnswer)).ReturnsAsync(mockResponse); var AnswerProvider = new AnswersController(mockAnswerService.Object); - var result = (BadRequestObjectResult) AnswerProvider.CreateAnswer(mockInputAnswer); + var result = (BadRequestObjectResult) await AnswerProvider.CreateAnswer(mockInputAnswer); Assert.Equal(400, result.StatusCode); } @@ -123,10 +123,10 @@ namespace DamageAssesment.Api.Answers.Test var mockAnswerService = new Mock(); var mockResponse = await MockData.getOkResponse(1); var mockInputAnswer = await MockData.getInputAnswerData(); - mockAnswerService.Setup(service => service.UpdateAnswerAsync(mockInputAnswer)).Returns(mockResponse); + mockAnswerService.Setup(service => service.UpdateAnswerAsync(mockInputAnswer)).ReturnsAsync(mockResponse); var AnswerProvider = new AnswersController(mockAnswerService.Object); - var result = (OkObjectResult) AnswerProvider.UpdateAnswer(mockInputAnswer); + var result = (OkObjectResult) await AnswerProvider.UpdateAnswer(mockInputAnswer); Assert.Equal(200, result.StatusCode); } @@ -137,10 +137,10 @@ namespace DamageAssesment.Api.Answers.Test var mockAnswerService = new Mock(); var mockResponse = await MockData.getNotFoundResponse(); var mockInputAnswer = await MockData.getInputAnswerData(); - mockAnswerService.Setup(service => service.UpdateAnswerAsync(mockInputAnswer)).Returns(mockResponse); + mockAnswerService.Setup(service => service.UpdateAnswerAsync(mockInputAnswer)).ReturnsAsync(mockResponse); var AnswerProvider = new AnswersController(mockAnswerService.Object); - var result = (NotFoundObjectResult) AnswerProvider.UpdateAnswer(mockInputAnswer); + var result = (NotFoundObjectResult) await AnswerProvider.UpdateAnswer(mockInputAnswer); Assert.Equal(404, result.StatusCode); } @@ -151,10 +151,10 @@ namespace DamageAssesment.Api.Answers.Test var mockAnswerService = new Mock(); var mockResponse = await MockData.getBadRequestResponse(); var mockInputAnswer = await MockData.getInputAnswerData(); - mockAnswerService.Setup(service => service.UpdateAnswerAsync(mockInputAnswer)).Returns(mockResponse); + mockAnswerService.Setup(service => service.UpdateAnswerAsync(mockInputAnswer)).ReturnsAsync(mockResponse); var AnswerProvider = new AnswersController(mockAnswerService.Object); - var result = (BadRequestObjectResult) AnswerProvider.UpdateAnswer(mockInputAnswer); + var result = (BadRequestObjectResult) await AnswerProvider.UpdateAnswer(mockInputAnswer); Assert.Equal(400, result.StatusCode); } diff --git a/DamageAssesmentApi/DamageAssesment.Api.Answers/Controllers/AnswersController.cs b/DamageAssesmentApi/DamageAssesment.Api.Answers/Controllers/AnswersController.cs index 241b357..bbfc323 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Answers/Controllers/AnswersController.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Answers/Controllers/AnswersController.cs @@ -78,11 +78,11 @@ namespace DamageAssesment.Api.Answers.Controllers /// [HttpPut("Answers")] - public IActionResult UpdateAnswer(Models.Answer answer) + public async Task UpdateAnswer(Models.Answer answer) { if (answer != null) { - var result = this.answerProvider.UpdateAnswerAsync(answer); + var result = await this.answerProvider.UpdateAnswerAsync(answer); if (result.IsSuccess) { return Ok(result.Answer); @@ -99,11 +99,11 @@ namespace DamageAssesment.Api.Answers.Controllers /// [HttpPost("Answers")] - public IActionResult CreateAnswer(Models.Answer answer) + public async Task CreateAnswer(Models.Answer answer) { if (answer != null) { - var result = this.answerProvider.PostAnswerAsync(answer); + var result = await this.answerProvider.PostAnswerAsync(answer); if (result.IsSuccess) { return Ok(result.Answer); diff --git a/DamageAssesmentApi/DamageAssesment.Api.Answers/Interfaces/IAnswersProvider.cs b/DamageAssesmentApi/DamageAssesment.Api.Answers/Interfaces/IAnswersProvider.cs index d948124..fa76fcf 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Answers/Interfaces/IAnswersProvider.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Answers/Interfaces/IAnswersProvider.cs @@ -6,8 +6,8 @@ Task<(bool IsSuccess, IEnumerable Answers, string ErrorMessage)> GetAnswersByQuestionAsync(int questionId); Task<(bool IsSuccess, Models.Answer Answer, string ErrorMessage)> GetAnswerByIdAsync(int Id); Task<(bool IsSuccess, IEnumerable Answers, string ErrorMessage)> GetAnswersAsync(int responseId); - (bool IsSuccess, Models.Answer Answer, string ErrorMessage) PostAnswerAsync(Models.Answer Answer); - (bool IsSuccess, Models.Answer Answer, string ErrorMessage) UpdateAnswerAsync(Models.Answer Answer); + Task<(bool IsSuccess, Models.Answer Answer, string ErrorMessage)> PostAnswerAsync(Models.Answer Answer); + Task<(bool IsSuccess, Models.Answer Answer, string ErrorMessage)> UpdateAnswerAsync(Models.Answer Answer); Task<(bool IsSuccess, Models.Answer Answer, string ErrorMessage)> DeleteAnswerAsync(int Id); } } diff --git a/DamageAssesmentApi/DamageAssesment.Api.Answers/Providers/AnswerProvider.cs b/DamageAssesmentApi/DamageAssesment.Api.Answers/Providers/AnswerProvider.cs index e9720d1..37a80a7 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Answers/Providers/AnswerProvider.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Answers/Providers/AnswerProvider.cs @@ -108,7 +108,7 @@ namespace DamageAssesment.Api.Answers.Providers return (false, null, ex.Message); } } - public (bool IsSuccess, Models.Answer Answer, string ErrorMessage) PostAnswerAsync(Models.Answer Answer) + public async Task<(bool IsSuccess, Models.Answer Answer, string ErrorMessage)> PostAnswerAsync(Models.Answer Answer) { try { @@ -117,7 +117,7 @@ namespace DamageAssesment.Api.Answers.Providers { Db.Answer answer = mapper.Map(Answer); answerDbContext.Answers.Add(answer); - answerDbContext.SaveChanges(); + await answerDbContext.SaveChangesAsync(); var result = mapper.Map(answer); return (true, result, null); } @@ -129,7 +129,7 @@ namespace DamageAssesment.Api.Answers.Providers return (false, null, ex.Message); } } - public (bool IsSuccess, Models.Answer Answer, string ErrorMessage) UpdateAnswerAsync(Models.Answer Answer) + public async Task<(bool IsSuccess, Models.Answer Answer, string ErrorMessage)> UpdateAnswerAsync(Models.Answer Answer) { try { @@ -140,7 +140,7 @@ namespace DamageAssesment.Api.Answers.Providers { Db.Answer answer = mapper.Map(Answer); answerDbContext.Answers.Update(answer); - answerDbContext.SaveChanges(); + await answerDbContext.SaveChangesAsync(); return (true, mapper.Map(answer), "Successful"); } else @@ -154,7 +154,6 @@ namespace DamageAssesment.Api.Answers.Providers logger?.LogInformation($"{Answer} Bad Request"); return (false, null, "Bad request"); } - } catch (Exception ex) { @@ -201,10 +200,6 @@ namespace DamageAssesment.Api.Answers.Providers answerDbContext.Answers.Add(new Db.Answer() { Id = 6, AnswerText = "No", Comment = "No Comment", QuestionId = 3, SurveyResponseId = 2 }); answerDbContext.SaveChanges(); } - } - - - } } diff --git a/DamageAssesmentApi/DamageAssesment.Api.Attachments.Test/AttachmentsServiceTest.cs b/DamageAssesmentApi/DamageAssesment.Api.Attachments.Test/AttachmentsServiceTest.cs index 6b65c79..1b3ff31 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Attachments.Test/AttachmentsServiceTest.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Attachments.Test/AttachmentsServiceTest.cs @@ -77,10 +77,10 @@ namespace DamageAssesment.Api.Attachments.Test var mockResponse = await MockData.getOkResponse(); var AttachmentResponse = await MockData.GetAttachmentInfo(0); var mockInputAttachment = await MockData.getInputAttachmentData(); - mockAttachmentService.Setup(service => service.PostAttachmentAsync(mockInputAttachment)).Returns(mockResponse); + mockAttachmentService.Setup(service => service.PostAttachmentAsync(mockInputAttachment)).ReturnsAsync(mockResponse); var AttachmentProvider = new AttachmentsController(mockAttachmentService.Object, mockUploadService.Object); - var result = (NoContentResult) AttachmentProvider.UploadAttachmentAsync(AttachmentResponse); + var result = (NoContentResult) await AttachmentProvider.UploadAttachmentAsync(AttachmentResponse); Assert.Equal(204, result.StatusCode); } @@ -92,11 +92,11 @@ namespace DamageAssesment.Api.Attachments.Test var mockUploadService = new Mock(); var mockInputAttachment = await MockData.getInputAttachmentData(); var mockResponse = await MockData.getBadRequestResponse(); - mockAttachmentService.Setup(service => service.PostAttachmentAsync(mockInputAttachment)).Returns(mockResponse); + mockAttachmentService.Setup(service => service.PostAttachmentAsync(mockInputAttachment)).ReturnsAsync(mockResponse); var AttachmentProvider = new AttachmentsController(mockAttachmentService.Object, mockUploadService.Object); AttachmentInfo attachmentInfo=new AttachmentInfo(); - var result = (BadRequestObjectResult) AttachmentProvider.UploadAttachmentAsync(attachmentInfo); + var result = (BadRequestObjectResult) await AttachmentProvider.UploadAttachmentAsync(attachmentInfo); Assert.Equal(400, result.StatusCode); } @@ -109,10 +109,10 @@ namespace DamageAssesment.Api.Attachments.Test var mockResponse = await MockData.getOkResponse(); var AttachmentResponse = await MockData.GetAttachmentInfo(1); var mockInputAttachment = await MockData.getInputAttachmentData(); - mockAttachmentService.Setup(service => service.PostAttachmentAsync(mockInputAttachment)).Returns(mockResponse); + mockAttachmentService.Setup(service => service.PostAttachmentAsync(mockInputAttachment)).ReturnsAsync(mockResponse); var AttachmentProvider = new AttachmentsController(mockAttachmentService.Object, mockUploadService.Object); - var result = (NoContentResult) AttachmentProvider.UpdateAttachmentAsync(AttachmentResponse); + var result = (NoContentResult) await AttachmentProvider.UpdateAttachmentAsync(AttachmentResponse); Assert.Equal(204, result.StatusCode); } @@ -124,11 +124,11 @@ namespace DamageAssesment.Api.Attachments.Test var mockUploadService = new Mock(); var mockInputAttachment = await MockData.getInputAttachmentData(); var mockResponse = await MockData.getBadRequestResponse(); - mockAttachmentService.Setup(service => service.PostAttachmentAsync(mockInputAttachment)).Returns(mockResponse); + mockAttachmentService.Setup(service => service.PostAttachmentAsync(mockInputAttachment)).ReturnsAsync(mockResponse); var AttachmentProvider = new AttachmentsController(mockAttachmentService.Object, mockUploadService.Object); AttachmentInfo attachmentInfo = new AttachmentInfo(); - var result = (BadRequestObjectResult) AttachmentProvider.UpdateAttachmentAsync(attachmentInfo); + var result = (BadRequestObjectResult) await AttachmentProvider.UpdateAttachmentAsync(attachmentInfo); Assert.Equal(400, result.StatusCode); } diff --git a/DamageAssesmentApi/DamageAssesment.Api.Attachments/Controllers/AttachmentsController.cs b/DamageAssesmentApi/DamageAssesment.Api.Attachments/Controllers/AttachmentsController.cs index f4f0785..8050515 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Attachments/Controllers/AttachmentsController.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Attachments/Controllers/AttachmentsController.cs @@ -83,15 +83,15 @@ namespace DamageAssesment.Api.Attachments.Controllers /// [HttpPost("Attachments"), DisableRequestSizeLimit] - public IActionResult UploadAttachmentAsync(AttachmentInfo attachmentInfo) + public async Task UploadAttachmentAsync(AttachmentInfo attachmentInfo) { try { if (attachmentInfo.Answers.Count > 0) { - var Attachments = this.AttachmentProvider.GetAttachmentCounter(); + var Attachments = await this.AttachmentProvider.GetAttachmentCounter(); List attachments = UploadService.UploadAttachment(attachmentInfo.ResponseId, Attachments.counter, attachmentInfo.Answers); - var result = this.AttachmentProvider.PostAttachmentAsync(attachments); + var result = await this.AttachmentProvider.PostAttachmentAsync(attachments); if (result.IsSuccess) { return Ok(result.Attachments); @@ -110,17 +110,17 @@ namespace DamageAssesment.Api.Attachments.Controllers /// [HttpPut("Attachments"), DisableRequestSizeLimit] - public IActionResult UpdateAttachmentAsync(AttachmentInfo attachmentInfo) + public async Task UpdateAttachmentAsync(AttachmentInfo attachmentInfo) { try { if (attachmentInfo.Answers.Count > 0) { - var res = this.AttachmentProvider.GetAttachmentInfo(attachmentInfo.Answers); + var res = await this.AttachmentProvider.GetAttachmentInfo(attachmentInfo.Answers); if (res.IsSuccess) { List attachments = UploadService.UpdateAttachments(attachmentInfo.ResponseId, attachmentInfo.Answers, res.Attachments); - var result = this.AttachmentProvider.PutAttachmentAsync(attachments); + var result = await this.AttachmentProvider.PutAttachmentAsync(attachments); if (result.IsSuccess) { return Ok(result.Attachments); diff --git a/DamageAssesmentApi/DamageAssesment.Api.Attachments/DMS_Attachments/Active/Response-1/Answer-1/Attachment_1.txt b/DamageAssesmentApi/DamageAssesment.Api.Attachments/DMS_Attachments/Active/Response-1/Answer-1/Attachment_1.txt deleted file mode 100644 index eed7e79..0000000 --- a/DamageAssesmentApi/DamageAssesment.Api.Attachments/DMS_Attachments/Active/Response-1/Answer-1/Attachment_1.txt +++ /dev/null @@ -1 +0,0 @@ -sample \ No newline at end of file diff --git a/DamageAssesmentApi/DamageAssesment.Api.Attachments/Interfaces/IAttachmentsProvider.cs b/DamageAssesmentApi/DamageAssesment.Api.Attachments/Interfaces/IAttachmentsProvider.cs index 5af5c60..5e56dbb 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Attachments/Interfaces/IAttachmentsProvider.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Attachments/Interfaces/IAttachmentsProvider.cs @@ -6,12 +6,12 @@ namespace DamageAssesment.Api.Attachments.Interfaces { Task<(bool IsSuccess, IEnumerable Attachments, string ErrorMessage)> GetAttachmentsAsync(); Task<(bool IsSuccess, Models.Attachment Attachment, string ErrorMessage)> GetAttachmentByIdAsync(int Id); - (bool IsSuccess, IEnumerable Attachments, string ErrorMessage) PostAttachmentAsync(List Attachments); - (bool IsSuccess, IEnumerable Attachments, string ErrorMessage) PutAttachmentAsync(List Attachments); + Task<(bool IsSuccess, IEnumerable Attachments, string ErrorMessage)> PostAttachmentAsync(List Attachments); + Task<(bool IsSuccess, IEnumerable Attachments, string ErrorMessage)> PutAttachmentAsync(List Attachments); Task<(bool IsSuccess, Models.Attachment Attachment, string Path)> DeleteAttachmentAsync(int Id); Task<(bool IsSuccess, int counter, string Path)> DeleteAttachmentsAsync(int responseId, int answerId); Task<(bool IsSuccess, int counter, string Path)> DeleteBulkAttachmentsAsync(int responseId, List answerIds); - (bool IsSuccess, int counter, string message) GetAttachmentCounter(); - (bool IsSuccess, IEnumerable Attachments, string ErrorMessage) GetAttachmentInfo(List answers); + Task<(bool IsSuccess, int counter, string message)> GetAttachmentCounter(); + Task<(bool IsSuccess, IEnumerable Attachments, string ErrorMessage)> GetAttachmentInfo(List answers); } } diff --git a/DamageAssesmentApi/DamageAssesment.Api.Attachments/Providers/AttachmentsProvider.cs b/DamageAssesmentApi/DamageAssesment.Api.Attachments/Providers/AttachmentsProvider.cs index 46356db..c18cd05 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Attachments/Providers/AttachmentsProvider.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Attachments/Providers/AttachmentsProvider.cs @@ -65,14 +65,14 @@ namespace DamageAssesment.Api.Attachments.Providers return (false, null, ex.Message); } } - public (bool IsSuccess, IEnumerable Attachments, string ErrorMessage) PostAttachmentAsync(List Attachments) + public async Task<(bool IsSuccess, IEnumerable Attachments, string ErrorMessage)> PostAttachmentAsync(List Attachments) { try { logger?.LogInformation("Query Attachment"); List attachments = mapper.Map, List>(Attachments); AttachmentDbContext.Attachments.AddRange(attachments); - AttachmentDbContext.SaveChanges(); + await AttachmentDbContext.SaveChangesAsync(); var result = mapper.Map, IEnumerable>(attachments); return (true, result, null); } @@ -83,14 +83,14 @@ namespace DamageAssesment.Api.Attachments.Providers } } - public (bool IsSuccess, IEnumerable Attachments, string ErrorMessage) PutAttachmentAsync(List Attachments) + public async Task<(bool IsSuccess, IEnumerable Attachments, string ErrorMessage)> PutAttachmentAsync(List Attachments) { try { logger?.LogInformation("Query Attachment"); List attachments = mapper.Map, List>(Attachments); AttachmentDbContext.Attachments.UpdateRange(attachments); - AttachmentDbContext.SaveChanges(); + await AttachmentDbContext.SaveChangesAsync(); var result = mapper.Map, IEnumerable>(attachments); return (true, result, null); } @@ -110,7 +110,7 @@ namespace DamageAssesment.Api.Attachments.Providers if (Attachments.Count > 0) { AttachmentDbContext.Attachments.RemoveRange(Attachments); - AttachmentDbContext.SaveChanges(); + await AttachmentDbContext.SaveChangesAsync(); } return (true, AttachmentId, ""); } @@ -121,7 +121,7 @@ namespace DamageAssesment.Api.Attachments.Providers return (false, AttachmentId, ""); } } - public (bool IsSuccess,int counter,string message) GetAttachmentCounter() + public async Task<(bool IsSuccess,int counter,string message)> GetAttachmentCounter() { try { @@ -143,7 +143,7 @@ namespace DamageAssesment.Api.Attachments.Providers if (Attachments.Count > 0) { AttachmentDbContext.Attachments.RemoveRange(Attachments); - AttachmentDbContext.SaveChanges(); + await AttachmentDbContext.SaveChangesAsync(); } return (true, AttachmentId, ""); } @@ -154,7 +154,7 @@ namespace DamageAssesment.Api.Attachments.Providers return (false, AttachmentId, ""); } } - public (bool IsSuccess, IEnumerable Attachments, string ErrorMessage) GetAttachmentInfo(List answers) + public async Task<(bool IsSuccess, IEnumerable Attachments, string ErrorMessage)> GetAttachmentInfo(List answers) { try { @@ -183,7 +183,7 @@ namespace DamageAssesment.Api.Attachments.Providers } Attachment.IsDeleted = true; AttachmentDbContext.Attachments.Update(Attachment); - AttachmentDbContext.SaveChanges(); + await AttachmentDbContext.SaveChangesAsync(); return (true, mapper.Map(Attachment), $"Attachment {Id} is deleted"); } catch (Exception ex) diff --git a/DamageAssesmentApi/DamageAssesment.Api.Employees.Test/EmployeeServiceTest.cs b/DamageAssesmentApi/DamageAssesment.Api.Employees.Test/EmployeeServiceTest.cs index 7c45f0d..aa30faf 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Employees.Test/EmployeeServiceTest.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Employees.Test/EmployeeServiceTest.cs @@ -98,10 +98,10 @@ namespace DamageAssesment.Api.Employees.Test var mockEmployeeService = new Mock(); var mockResponse = await MockData.getOkResponse("Emp1"); var mockInputEmployee = await MockData.getInputEmployeeData(); - mockEmployeeService.Setup(service => service.UpdateEmployeeAsync(mockInputEmployee)).ReturnsAsync(mockResponse); + mockEmployeeService.Setup(service => service.UpdateEmployeeAsync("Emp1",mockInputEmployee)).ReturnsAsync(mockResponse); var EmployeeProvider = new EmployeesController(mockEmployeeService.Object); - var result = (OkObjectResult)await EmployeeProvider.UpdateEmployee(mockInputEmployee); + var result = (OkObjectResult)await EmployeeProvider.UpdateEmployee("Emp1",mockInputEmployee); Assert.Equal(200, result.StatusCode); } @@ -112,10 +112,10 @@ namespace DamageAssesment.Api.Employees.Test var mockEmployeeService = new Mock(); var mockResponse = await MockData.getNotFoundResponse(); var mockInputEmployee = await MockData.getInputEmployeeData(); - mockEmployeeService.Setup(service => service.UpdateEmployeeAsync(mockInputEmployee)).ReturnsAsync(mockResponse); + mockEmployeeService.Setup(service => service.UpdateEmployeeAsync("Emp1", mockInputEmployee)).ReturnsAsync(mockResponse); var EmployeeProvider = new EmployeesController(mockEmployeeService.Object); - var result = (NotFoundObjectResult)await EmployeeProvider.UpdateEmployee(mockInputEmployee); + var result = (NotFoundObjectResult)await EmployeeProvider.UpdateEmployee("Emp1", mockInputEmployee); Assert.Equal(404, result.StatusCode); } @@ -126,10 +126,10 @@ namespace DamageAssesment.Api.Employees.Test var mockEmployeeService = new Mock(); var mockResponse = await MockData.getBadRequestResponse(); var mockInputEmployee = await MockData.getInputEmployeeData(); - mockEmployeeService.Setup(service => service.UpdateEmployeeAsync(mockInputEmployee)).ReturnsAsync(mockResponse); + mockEmployeeService.Setup(service => service.UpdateEmployeeAsync("Emp1", mockInputEmployee)).ReturnsAsync(mockResponse); var EmployeeProvider = new EmployeesController(mockEmployeeService.Object); - var result = (BadRequestObjectResult)await EmployeeProvider.UpdateEmployee(mockInputEmployee); + var result = (BadRequestObjectResult)await EmployeeProvider.UpdateEmployee("Emp1", mockInputEmployee); Assert.Equal(400, result.StatusCode); } diff --git a/DamageAssesmentApi/DamageAssesment.Api.Employees.Test/MockData.cs b/DamageAssesmentApi/DamageAssesment.Api.Employees.Test/MockData.cs index cd5206e..91c8b84 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Employees.Test/MockData.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Employees.Test/MockData.cs @@ -33,19 +33,19 @@ namespace DamageAssesment.Api.Employees.Test return (false, null, "Bad Request"); } - public static async Task<(bool, Employees.Models.Employee, string)> getNotFoundResponse() + public static async Task<(bool, Models.Employee, string)> getNotFoundResponse() { return (false, null, "Not Found"); } - public static async Task<(bool, IEnumerable, string)> getNoContentResponse() + public static async Task<(bool, IEnumerable, string)> getNoContentResponse() { IEnumerable list = new List(); return (false, list, null); } - public static async Task getInputEmployeeData() + public static async Task getInputEmployeeData() { - return new Employees.Db.Employee { Id = "Emp1", Name = "ABC1", Email = "abc1@gmail.com", OfficePhoneNumber = "12345678", BirthDate = DateTime.Now.AddYears(-18), IsActive = true, PreferredLanguage = "en" }; + return new Models.Employee { Id = "Emp1", Name = "ABC1", Email = "abc1@gmail.com", OfficePhoneNumber = "12345678", BirthDate = DateTime.Now.AddYears(-18), IsActive = true, PreferredLanguage = "en" }; } diff --git a/DamageAssesmentApi/DamageAssesment.Api.Locations.Test/LocationsServiceTest.cs b/DamageAssesmentApi/DamageAssesment.Api.Locations.Test/LocationsServiceTest.cs index 270c638..2d15662 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Locations.Test/LocationsServiceTest.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Locations.Test/LocationsServiceTest.cs @@ -93,7 +93,7 @@ namespace DamageAssesment.Api.Locations.Test var mapper = new Mapper(configuration); var LocationsProvider = new LocationsProvider(dbContext, null, mapper); //Testmethode - Db.Location newLocation = new Db.Location() { Id = "Loc9", RegionId = "1", Name = "Test 1", MaintenanceCenter = "1", SchoolType = "US" }; + Models.Location newLocation = new Models.Location() { Id = "Loc9", RegionId = "1", Name = "Test 1", MaintenanceCenter = "1", SchoolType = "US" }; var Location = await LocationsProvider.PostLocationAsync(newLocation); Assert.True(Location.IsSuccess); @@ -113,7 +113,7 @@ namespace DamageAssesment.Api.Locations.Test var mapper = new Mapper(configuration); var LocationsProvider = new LocationsProvider(dbContext, null, mapper); //Testmethode - Db.Location updateLocation = new Db.Location() { Id = "Loc1", RegionId = "1", Name = "Tampa", MaintenanceCenter = "1", SchoolType = "NA" }; + Models.Location updateLocation = new Models.Location() { Id = "Loc1", RegionId = "1", Name = "Tampa", MaintenanceCenter = "1", SchoolType = "NA" }; var Location = await LocationsProvider.UpdateLocationAsync(updateLocation); var modified = dbContext.Locations.FirstOrDefault(a => a.Id == updateLocation.Id); Assert.True(Location.IsSuccess); diff --git a/DamageAssesmentApi/DamageAssesment.Api.SurveyResponses/Controllers/SurveyResponsesController.cs b/DamageAssesmentApi/DamageAssesment.Api.SurveyResponses/Controllers/SurveyResponsesController.cs index b3ff885..c650d1d 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.SurveyResponses/Controllers/SurveyResponsesController.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.SurveyResponses/Controllers/SurveyResponsesController.cs @@ -180,10 +180,10 @@ namespace DamageAssesment.Api.SurveyResponses.Controllers /// /// POST request for submitting survey with multiple answers. /// - /// The answers to be submitted for the survey. + /// The answers to be submitted for the survey. [HttpPost("SurveyResponses/Answers")] - public async Task PostSurveyAnswersAsync(AnswerRequest answers) + public async Task PostSurveyAnswersAsync(Request request) { /* var result = await this.surveyResponseProvider.PostSurveyAnswersAsync(surveyAnswers); if (result.IsSuccess) @@ -191,7 +191,7 @@ namespace DamageAssesment.Api.SurveyResponses.Controllers return Ok(result.SurveyResponse); } return BadRequest(result.ErrorMessage);*/ - var result = await this.surveyResponseProvider.PostSurveyAnswersAsync(answers); + var result = await this.surveyResponseProvider.PostSurveyAnswersAsync(request); if (result.IsSuccess) return Ok(result.SurveyResponse); diff --git a/DamageAssesmentApi/DamageAssesment.Api.SurveyResponses/Db/SurveyResponseDbContext.cs b/DamageAssesmentApi/DamageAssesment.Api.SurveyResponses/Db/SurveyResponseDbContext.cs index bb8a2a2..61726ad 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.SurveyResponses/Db/SurveyResponseDbContext.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.SurveyResponses/Db/SurveyResponseDbContext.cs @@ -10,5 +10,13 @@ namespace DamageAssesment.Api.SurveyResponses.Db { } + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + base.OnModelCreating(modelBuilder); + modelBuilder.Entity() + .Property(item => item.Id) + .ValueGeneratedOnAdd(); + } } } diff --git a/DamageAssesmentApi/DamageAssesment.Api.SurveyResponses/Interfaces/ISurveysResponse.cs b/DamageAssesmentApi/DamageAssesment.Api.SurveyResponses/Interfaces/ISurveysResponse.cs index 79ca1ad..5cdd198 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.SurveyResponses/Interfaces/ISurveysResponse.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.SurveyResponses/Interfaces/ISurveysResponse.cs @@ -17,7 +17,7 @@ namespace DamageAssesment.Api.SurveyResponses.Interfaces Task<(bool IsSuccess, dynamic SurveyResponses, string ErrorMessage)> GetSurveyResponsesByMaintenanceCenterAsync(int surveyId); Task<(bool IsSuccess, dynamic SurveyResponses, string ErrorMessage)> GetResponsesByAnswerAsync(int surveyId, int questionId, string answer); - Task<(bool IsSuccess, Models.SurveyResponse SurveyResponse, string ErrorMessage)> PostSurveyAnswersAsync(Models.AnswerRequest answers); + Task<(bool IsSuccess, Models.SurveyResponse SurveyResponse, string ErrorMessage)> PostSurveyAnswersAsync(Request request); } } diff --git a/DamageAssesmentApi/DamageAssesment.Api.SurveyResponses/Models/AnswerRequest.cs b/DamageAssesmentApi/DamageAssesment.Api.SurveyResponses/Models/AnswerRequest.cs index 68a217a..3d86488 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.SurveyResponses/Models/AnswerRequest.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.SurveyResponses/Models/AnswerRequest.cs @@ -2,9 +2,9 @@ { public class AnswerRequest { - public int SurveyId { get; set; } - public string LocationId { get; set; } - public string EmployeeId { get; set; } - public List Answers { get; set; } + public int QuestionId { get; set; } + public string AnswerText { get; set; } + public string Comment { get; set; } + public List PostedFiles { get; set; } = new List(); } } diff --git a/DamageAssesmentApi/DamageAssesment.Api.SurveyResponses/Models/Question.cs b/DamageAssesmentApi/DamageAssesment.Api.SurveyResponses/Models/Question.cs index 5dba504..ad18bf1 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.SurveyResponses/Models/Question.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.SurveyResponses/Models/Question.cs @@ -17,7 +17,7 @@ namespace DamageAssesment.Api.SurveyResponses.Models public bool Key { get; set; } public int? SurveyId { get; set; } - public string QuestionGroup { get; set; } + //public string QuestionGroup { get; set; } public int CategoryId { get; set; } // public int? Survey_SurveyID { get; set; } } diff --git a/DamageAssesmentApi/DamageAssesment.Api.SurveyResponses/Models/QuestionRequest.cs b/DamageAssesmentApi/DamageAssesment.Api.SurveyResponses/Models/QuestionRequest.cs deleted file mode 100644 index d0930ab..0000000 --- a/DamageAssesmentApi/DamageAssesment.Api.SurveyResponses/Models/QuestionRequest.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace DamageAssesment.Api.SurveyResponses.Models -{ - public class QuestionRequest - { - public int QuestionId { get; set; } - public string AnswerText { get; set; } - public string Comment { get; set; } - public List PostedFiles { get; set; } = new List(); - } -} diff --git a/DamageAssesmentApi/DamageAssesment.Api.SurveyResponses/Models/Request.cs b/DamageAssesmentApi/DamageAssesment.Api.SurveyResponses/Models/Request.cs new file mode 100644 index 0000000..53b3044 --- /dev/null +++ b/DamageAssesmentApi/DamageAssesment.Api.SurveyResponses/Models/Request.cs @@ -0,0 +1,10 @@ +namespace DamageAssesment.Api.SurveyResponses.Models +{ + public class Request + { + public int SurveyId { get; set; } + public string LocationId { get; set; } + public string EmployeeId { get; set; } + public List Answers { get; set; } + } +} diff --git a/DamageAssesmentApi/DamageAssesment.Api.SurveyResponses/Program.cs b/DamageAssesmentApi/DamageAssesment.Api.SurveyResponses/Program.cs index a4f585f..cf41624 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.SurveyResponses/Program.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.SurveyResponses/Program.cs @@ -4,6 +4,7 @@ using DamageAssesment.Api.SurveyResponses.Providers; using Microsoft.AspNetCore.DataProtection.XmlEncryption; using Microsoft.EntityFrameworkCore; using Polly; +using System.Net.Http; using System.Reflection; var builder = WebApplication.CreateBuilder(args); diff --git a/DamageAssesmentApi/DamageAssesment.Api.SurveyResponses/Providers/AnswerServiceProvider.cs b/DamageAssesmentApi/DamageAssesment.Api.SurveyResponses/Providers/AnswerServiceProvider.cs index 5796eff..cb638bc 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.SurveyResponses/Providers/AnswerServiceProvider.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.SurveyResponses/Providers/AnswerServiceProvider.cs @@ -7,6 +7,8 @@ using System.Data.Common; using System.Security.Cryptography; using System.Text.Json.Nodes; using System.Text; +using System.Net.Http.Headers; +using System; namespace DamageAssesment.Api.SurveyResponses.Providers { @@ -42,8 +44,8 @@ namespace DamageAssesment.Api.SurveyResponses.Providers try { httpClient.BaseAddress = new Uri(urlBase); - - var response = await httpClient.GetAsync("/api/AnswersByResponse/"+ responseId); + + var response = await httpClient.GetAsync("/api/AnswersByResponse/" + responseId); response.EnsureSuccessStatusCode(); var responseString = await response.Content.ReadAsStringAsync(); var answers = JsonConvert.DeserializeObject>(responseString); @@ -63,19 +65,26 @@ namespace DamageAssesment.Api.SurveyResponses.Providers { try { - httpClient.BaseAddress = new Uri(urlBase); + var url = urlBase + ressource; + var request = new HttpRequestMessage(HttpMethod.Post, url); + request.Headers.Accept.Clear(); + request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); + //request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token); + var jsonObject = JsonConvert.SerializeObject(answer); - var content = new StringContent(jsonObject.ToString(), Encoding.UTF8, "application/json"); - var response = await httpClient.PostAsync(ressource,content); + request.Content = new StringContent(jsonObject.ToString(), Encoding.UTF8, "application/json"); + var response = await httpClient.SendAsync(request, CancellationToken.None); response.EnsureSuccessStatusCode(); var responseString = await response.Content.ReadAsStringAsync(); var answers = JsonConvert.DeserializeObject(responseString); - if (answers == null) { + if (answers == null) + { logger?.LogError($"Answer cannot be added - Ref: AnswerServiceProvider.PostAnswersAsync()"); return null; - } + } else return answers; + } catch (Exception ex) { diff --git a/DamageAssesmentApi/DamageAssesment.Api.SurveyResponses/Providers/AttachmentServiceProvider.cs b/DamageAssesmentApi/DamageAssesment.Api.SurveyResponses/Providers/AttachmentServiceProvider.cs index 3e46c84..04f8121 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.SurveyResponses/Providers/AttachmentServiceProvider.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.SurveyResponses/Providers/AttachmentServiceProvider.cs @@ -4,6 +4,7 @@ using DamageAssesment.Api.SurveyResponses.Models; using Microsoft.Extensions.Logging; using Newtonsoft.Json; using System.Net.Http; +using System.Net.Http.Headers; using System.Runtime.Intrinsics.Arm; using System.Text; @@ -40,10 +41,16 @@ namespace DamageAssesment.Api.SurveyResponses.Providers { try { - httpClient.BaseAddress = new Uri(urlBase); + + var url = urlBase + ressource; + var request = new HttpRequestMessage(HttpMethod.Post, url); + request.Headers.Accept.Clear(); + request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); + //request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token); + var jsonObject = JsonConvert.SerializeObject(attachmentInfo); - var content = new StringContent(jsonObject.ToString(), Encoding.UTF8, "application/json"); - var response = await httpClient.PostAsync(ressource, content); + request.Content = new StringContent(jsonObject.ToString(), Encoding.UTF8, "application/json"); + var response = await httpClient.SendAsync(request, CancellationToken.None); response.EnsureSuccessStatusCode(); var responseString = await response.Content.ReadAsStringAsync(); var attachments = JsonConvert.DeserializeObject>(responseString); diff --git a/DamageAssesmentApi/DamageAssesment.Api.SurveyResponses/Providers/SurveyResponsesProvider.cs b/DamageAssesmentApi/DamageAssesment.Api.SurveyResponses/Providers/SurveyResponsesProvider.cs index 2615cfd..98c138d 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.SurveyResponses/Providers/SurveyResponsesProvider.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.SurveyResponses/Providers/SurveyResponsesProvider.cs @@ -4,7 +4,9 @@ using DamageAssesment.Api.SurveyResponses.Interfaces; using DamageAssesment.Api.SurveyResponses.Models; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Internal; +using Newtonsoft.Json; using System.Diagnostics; +using System.Text; using static Microsoft.EntityFrameworkCore.DbLoggerCategory; namespace DamageAssesment.Api.SurveyResponses.Providers @@ -251,7 +253,6 @@ namespace DamageAssesment.Api.SurveyResponses.Providers answers = new List(); return (true, answers, "Empty object returned"); } - } catch (Exception ex) { @@ -266,16 +267,16 @@ namespace DamageAssesment.Api.SurveyResponses.Providers { if (surveyResponse != null) { - var surveyResponses = await surveyResponseDbContext.SurveyResponses.ToListAsync(); - surveyResponse.Id = surveyResponses.Count + 1; - surveyResponseDbContext.SurveyResponses.Add(mapper.Map(surveyResponse)); - surveyResponseDbContext.SaveChanges(); + var _surveyResponse = mapper.Map(surveyResponse); + surveyResponseDbContext.SurveyResponses.Add(_surveyResponse); + await surveyResponseDbContext.SaveChangesAsync(); + surveyResponse.Id = _surveyResponse.Id; return (true, surveyResponse, "Request Successful"); } else { - logger?.LogInformation($"SurveyResponseID={surveyResponse.Id} cannot be added"); - return (false, null, "Survey cannot be added"); + logger?.LogInformation($"SurveyResponse cannot be added"); + return (false, null, "SurveyResponse cannot be added"); } } catch (Exception ex) @@ -299,7 +300,7 @@ namespace DamageAssesment.Api.SurveyResponses.Providers _SurveyResponse.SurveyId = SurveyResponse.SurveyId; _SurveyResponse.EmployeeId = SurveyResponse.EmployeeId; _SurveyResponse.LocationId = SurveyResponse.LocationId; - surveyResponseDbContext.SaveChanges(); + await surveyResponseDbContext.SaveChangesAsync(); return (true, mapper.Map(_SurveyResponse), "Successful"); } else @@ -331,7 +332,7 @@ namespace DamageAssesment.Api.SurveyResponses.Providers if (_SurveyResponse != null) { surveyResponseDbContext.Remove(_SurveyResponse); - surveyResponseDbContext.SaveChanges(); + await surveyResponseDbContext.SaveChangesAsync(); return (true, mapper.Map(_SurveyResponse), "Successful"); } else @@ -458,7 +459,7 @@ namespace DamageAssesment.Api.SurveyResponses.Providers ans.Id, ans.AnswerText, ans.Comment, - Questions = (from q in questions where q.Id == ans.QuestionId select new { q.Id, q.QuestionNumber, q.QuestionGroup, q.Questions }).SingleOrDefault(), + Questions = (from q in questions where q.Id == ans.QuestionId select new { q.Id, q.QuestionNumber, q.CategoryId, q.Questions }).SingleOrDefault(), Attachments = from att in attachments where att.AnswerId == ans.Id select new { att.Id, att.URI } } }; @@ -503,7 +504,7 @@ namespace DamageAssesment.Api.SurveyResponses.Providers ans.QuestionId, ans.AnswerText, ans.Comment, - Questions = (from q in surveyQuestions where q.Id == ans.QuestionId select new { q.Id, q.QuestionNumber, q.QuestionGroup, q.Questions }).SingleOrDefault(), + Questions = (from q in surveyQuestions where q.Id == ans.QuestionId select new { q.Id, q.QuestionNumber, q.CategoryId, q.Questions }).SingleOrDefault(), Attachments = from att in attachments where att.AnswerId == ans.Id select new { att.Id, att.URI } } @@ -546,7 +547,7 @@ namespace DamageAssesment.Api.SurveyResponses.Providers ans.QuestionId, ans.AnswerText, ans.Comment, - Questions = (from q in questions where q.Id == ans.QuestionId select new { q.Id, q.QuestionNumber, q.QuestionGroup, q.Questions }).SingleOrDefault(), + Questions = (from q in questions where q.Id == ans.QuestionId select new { q.Id, q.QuestionNumber, q.CategoryId, q.Questions }).SingleOrDefault(), Attachments = from att in attachments where att.AnswerId == ans.Id select new { att.Id, att.URI } } }; @@ -650,7 +651,7 @@ namespace DamageAssesment.Api.SurveyResponses.Providers ans.Id, ans.AnswerText, ans.Comment, - Questions = (from q in surveyQuestions where q.Id == ans.QuestionId select new { q.Id, q.QuestionNumber, q.QuestionGroup, q.Questions }).SingleOrDefault(), + Questions = (from q in surveyQuestions where q.Id == ans.QuestionId select new { q.Id, q.QuestionNumber, q.CategoryId, q.Questions }).SingleOrDefault(), Attachments = from att in attachments where att.AnswerId == ans.Id select new { att.Id, att.URI } } }; @@ -709,67 +710,75 @@ namespace DamageAssesment.Api.SurveyResponses.Providers } - bool ProcessAnswers(QuestionRequest questionRequest, int surveyResponseId) + async Task ProcessAnswers(AnswerRequest answerRequest, int surveyResponseId) { - if (questionRequest != null) + if (answerRequest != null) { - var answer = answerServiceProvider.PostAnswersAsync(new Answer {QuestionId = questionRequest.QuestionId, AnswerText = questionRequest.AnswerText, Comment = questionRequest.Comment, SurveyResponseId = surveyResponseId }); - if (answer != null) - { - List listAnswerInfo = new List(); - listAnswerInfo.Add(new AnswerInfo { AnswerId = answer.Id, postedFiles = questionRequest.PostedFiles }); - var attachments = attachmentServiceProvider.PostAttachmentsAsync(new AttachmentInfo { ResponseId = surveyResponseId, Answers = listAnswerInfo }); + var answer = await answerServiceProvider.PostAnswersAsync(new Models.Answer {QuestionId = answerRequest.QuestionId, AnswerText = answerRequest.AnswerText, Comment = answerRequest.Comment, SurveyResponseId = surveyResponseId }); + if (answer != null) + { + List listAnswerInfo = new List(); + listAnswerInfo.Add(new AnswerInfo { AnswerId = answer.Id, postedFiles = answerRequest.PostedFiles }); + var attachments = attachmentServiceProvider.PostAttachmentsAsync(new AttachmentInfo { ResponseId = surveyResponseId, Answers = listAnswerInfo }); - string message = $"Answer for question {questionRequest.QuestionId} saved to the database"; - logger?.LogInformation(message); - return (true); - } - else - { - string message = $"Answer for question {questionRequest.QuestionId} cannot be saved to the database"; - logger?.LogInformation(message); - return (false); - } + string message = $"Answer for question {answerRequest.QuestionId} saved to the database"; + logger?.LogInformation(message); + return (true); + } + else + { + string message = $"Answer for question {answerRequest.QuestionId} cannot be saved to the database"; + logger?.LogInformation(message); + return (false); + } } else { - var message = $"Answer for question {questionRequest.QuestionId} cannot be saved to the database - questionRequest object is null"; + var message = $"Answer for question {answerRequest.QuestionId} cannot be saved to the database - answerRequest object is null"; logger?.LogInformation(message); return (false); } } - public async Task<(bool IsSuccess, Models.SurveyResponse SurveyResponse, string ErrorMessage)> PostSurveyAnswersAsync(Models.AnswerRequest answers) + public async Task<(bool IsSuccess, Models.SurveyResponse SurveyResponse, string ErrorMessage)> PostSurveyAnswersAsync(Models.Request request) { try { - if (answers != null) + if (request != null) { - var response = await PostSurveyResponseAsync(new Models.SurveyResponse { Id = 0, SurveyId = answers.SurveyId, EmployeeId = answers.EmployeeId, LocationId = answers.LocationId }); + var response = await PostSurveyResponseAsync(new Models.SurveyResponse {SurveyId = request.SurveyId, EmployeeId = request.EmployeeId, LocationId = request.LocationId }); if (response.IsSuccess) { var surveyResponse = response.SurveyResponse; + var tasks = request.Answers.Select(x => ProcessAnswers(x,surveyResponse.Id)); - var answerTasks = new List(); //new List(); - - //var tasks = answers.Answers.Select(x => ProcessAnswers(x,surveyResponse.SurveyResponseID)); - foreach (QuestionRequest ans in answers.Answers) - { - ProcessAnswers(ans, surveyResponse.Id); + // foreach (AnswerRequest ans in request.Answers) + // { + // answer = new Models.Answer { QuestionId = ans.QuestionId, AnswerText = ans.AnswerText, Comment = ans.Comment, SurveyResponseId = surveyResponse.Id }; + + //var content = new StringContent(jsonObject.ToString(), Encoding.UTF8, "application/json"); + + //await Task.Delay(500); + // var rep = await answerServiceProvider.PostAnswersAsync(answer); + // var jsonObject = JsonConvert.SerializeObject(rep); + //x = x + jsonObject.ToString() + " "; + //i++; + // answer = new Models.Answer { QuestionId = ans.QuestionId, AnswerText = ans.AnswerText, Comment = ans.Comment, SurveyResponseId = surveyResponse.Id }; + // await answerServiceProvider.PostAnswersAsync(answer); + //ProcessAnswers(ans, surveyResponse.Id); //var stopwatch = new Stopwatch(); //stopwatch.Start(); // var task = Task.Run(() => ProcessAnswers(ans, surveyResponse.Id)); - //var task = await ProcessAnswers(ans, surveyResponse.Id); //answerTasks.Add(task); //stopwatch.Stop(); //answerTasks.Add(ProcessAnswers(ans, surveyResponse.Id)); - } - //await Task.WhenAll(answerTasks); + // } + await Task.WhenAll(tasks); return (true, surveyResponse, null); } else diff --git a/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Bases/ServiceProviderBase.cs b/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Bases/ServiceProviderBase.cs deleted file mode 100644 index 799f082..0000000 --- a/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Bases/ServiceProviderBase.cs +++ /dev/null @@ -1,21 +0,0 @@ -namespace DamageAssesment.Api.UsersAccess.Bases -{ - public class ServiceProviderBase - { - protected readonly IConfiguration configuration; - protected readonly HttpClient httpClient; - protected private readonly ILogger logger; - protected string ressource; - protected string urlBase; - - - public ServiceProviderBase(IConfiguration configuration, HttpClient httpClient, ILogger logger, string ressource, string urlBase) - { - this.configuration = configuration; - this.httpClient = httpClient; - this.logger = logger; - this.ressource = ressource; - this.urlBase = urlBase; - } - } -} diff --git a/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Controllers/UsersAccessController.cs b/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Controllers/UsersAccessController.cs deleted file mode 100644 index 5e16362..0000000 --- a/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Controllers/UsersAccessController.cs +++ /dev/null @@ -1,97 +0,0 @@ -using DamageAssesment.Api.UsersAccess.Interfaces; -using DamageAssesment.Api.UsersAccess.Models; -using Microsoft.AspNetCore.Mvc; - -namespace DamageAssesment.Api.UsersAccess.Controllers -{ - [Route("api")] - [ApiController] - public class UsersAccessController : ControllerBase - { - private IUsersAccessProvider userAccessProvider; - - public UsersAccessController(IUsersAccessProvider userAccessProvider) - { - this.userAccessProvider = userAccessProvider; - } - [HttpPost("authenticate")] - public async Task AuthenticateAsync(UserCredentials userCredentials) - { - var result = await userAccessProvider.AuthenticateAsync(userCredentials); - if (result.IsSuccess) - { - return Ok(result.TokenResponse); - } - return Unauthorized(result.ErrorMessage); - } - - [HttpPost("refreshToken")] - public async Task RefreshTokenAsync(TokenResponse tokenResponse) - { - var result = await userAccessProvider.RefreshTokenAsync(tokenResponse); - if (result.IsSuccess) - { - return Ok(result.TokenResponse); - } - return Unauthorized(result.ErrorMessage); - } - - [HttpGet("users")] - public async Task GetUsersAsync() - { - var result = await userAccessProvider.GetUsersAsync(); - if (result.IsSuccess) - { - return Ok(result.Users); - } - return NoContent(); - } - - [HttpGet("users/{Id}")] - public async Task GetUsersAsync(int Id) - { - var result = await userAccessProvider.GetUsersAsync(Id); - if (result.IsSuccess) - { - return Ok(result.User); - } - return NotFound(); - } - - [HttpPost("users")] - public async Task PostUserAsync(User user) - { - var result = await userAccessProvider.PostUserAsync(user); - if (result.IsSuccess) - { - return Ok(result.User); - } - return BadRequest(result.ErrorMessage); - } - - [HttpPut("users/{Id}")] - public async Task PutUserAsync(int Id, User user) - { - var result = await userAccessProvider.PutUserAsync(Id, user); - if (result.IsSuccess) - { - return Ok(result.User); - } - if (result.ErrorMessage == "Not Found") - return NotFound(result.ErrorMessage); - - return BadRequest(result.ErrorMessage); - } - - [HttpDelete("users/{Id}")] - public async Task DeleteSurveysAsync(int Id) - { - var result = await userAccessProvider.DeleteUserAsync(Id); - if (result.IsSuccess) - { - return Ok(result.User); - } - return NotFound(); - } - } -} diff --git a/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/DamageAssesment.Api.UsersAccess.csproj b/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/DamageAssesment.Api.UsersAccess.csproj deleted file mode 100644 index d56ba51..0000000 --- a/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/DamageAssesment.Api.UsersAccess.csproj +++ /dev/null @@ -1,19 +0,0 @@ - - - - net6.0 - enable - enable - - - - - - - - - - - - - diff --git a/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Db/Role.cs b/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Db/Role.cs deleted file mode 100644 index 93e522a..0000000 --- a/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Db/Role.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System.ComponentModel.DataAnnotations; -using System.ComponentModel.DataAnnotations.Schema; -using System.Text.Json.Serialization; - -namespace DamageAssesment.Api.UsersAccess.Db -{ - public class Role - { - [Key] - public int Id { get; set; } - - [StringLength(100)] - [Required] - public string Name { get; set; } - - // add a status field - - [StringLength(100)] - public string? Description { get; set; } - } -} diff --git a/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Db/Token.cs b/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Db/Token.cs deleted file mode 100644 index cfea1e2..0000000 --- a/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Db/Token.cs +++ /dev/null @@ -1,17 +0,0 @@ -using Microsoft.EntityFrameworkCore.Metadata.Internal; -using System.ComponentModel.DataAnnotations; -using System.ComponentModel.DataAnnotations.Schema; - -namespace DamageAssesment.Api.UsersAccess.Db -{ - public class Token - { - [Key] - public string Id { get; set; } - [Required] - [ForeignKey("User")] - public int UserId { get; set; } - public string? RefreshToken { get; set; } - public bool? IsActive { get; set; } - } -} diff --git a/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Db/User.cs b/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Db/User.cs deleted file mode 100644 index d5fc4ee..0000000 --- a/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Db/User.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System.ComponentModel.DataAnnotations; -using System.ComponentModel.DataAnnotations.Schema; -using System.Text.Json.Serialization; - -namespace DamageAssesment.Api.UsersAccess.Db -{ - public class User - { - [Key] - public int Id { get; set; } - - [ForeignKey("Employee")] - public string EmployeeId { get; set; } - - [ForeignKey("Role")] - [Required] - public int RoleId { get; set; } - [Required] - public bool? IsActive { get; set; } = true; - - [Required] - public DateTime? CreateDate { get; set; } = DateTime.Now; - - public DateTime? UpdateDate { get; set; } - - } -} diff --git a/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Db/UsersAccessDbContext.cs b/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Db/UsersAccessDbContext.cs deleted file mode 100644 index a46a10d..0000000 --- a/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Db/UsersAccessDbContext.cs +++ /dev/null @@ -1,17 +0,0 @@ -using Microsoft.EntityFrameworkCore; - -namespace DamageAssesment.Api.UsersAccess.Db -{ - public class UsersAccessDbContext:DbContext - { - public DbSet Users { get; set; } - public DbSet Roles { get; set; } - public DbSet Tokens { get; set; } - public UsersAccessDbContext(DbContextOptions options) : base(options) - { - - } - - - } -} diff --git a/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Interfaces/IEmployeeServiceProvider.cs b/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Interfaces/IEmployeeServiceProvider.cs deleted file mode 100644 index fc35b00..0000000 --- a/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Interfaces/IEmployeeServiceProvider.cs +++ /dev/null @@ -1,10 +0,0 @@ -using DamageAssesment.Api.UsersAccess.Models; - -namespace DamageAssesment.Api.UsersAccess.Interfaces -{ - public interface IEmployeeServiceProvider - { - Task> getEmployeesAsync(); - Task getEmployeeAsync(string employeeID); - } -} diff --git a/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Interfaces/IRoleProvider.cs b/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Interfaces/IRoleProvider.cs deleted file mode 100644 index 6ca0209..0000000 --- a/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Interfaces/IRoleProvider.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace DamageAssesment.Api.UsersAccess.Interfaces -{ - public interface IRoleProvider - { - Task<(bool IsSuccess, IEnumerable< Models.Role> Roles, string ErrorMessage)> GetRolesAsync(); - Task<(bool IsSuccess, Models.Role Roles, string ErrorMessage)> GetRolesAsync(int Id); - Task<(bool IsSuccess, Models.Role Role, string ErrorMessage)> PostRoleAsync(Models.Role Role); - Task<(bool IsSuccess, Models.Role Role, string ErrorMessage)> PutRoleAsync(int Id,Models.Role Role); - Task<(bool IsSuccess, Models.Role Role, string ErrorMessage)> DeleteRoleAsync(int Id); - - } -} diff --git a/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Interfaces/ITokenServiceProvider.cs b/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Interfaces/ITokenServiceProvider.cs deleted file mode 100644 index 58574b7..0000000 --- a/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Interfaces/ITokenServiceProvider.cs +++ /dev/null @@ -1,11 +0,0 @@ -using DamageAssesment.Api.UsersAccess.Models; -using System.Security.Claims; - -namespace DamageAssesment.Api.UsersAccess.Interfaces -{ - public interface ITokenServiceProvider - { - Task GenerateToken(User user); - Task TokenAuthenticate(User user, Claim[] claims); - } -} \ No newline at end of file diff --git a/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Interfaces/IUsersAccessProvider.cs b/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Interfaces/IUsersAccessProvider.cs deleted file mode 100644 index 7e39e11..0000000 --- a/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Interfaces/IUsersAccessProvider.cs +++ /dev/null @@ -1,16 +0,0 @@ -using DamageAssesment.Api.UsersAccess.Models; - -namespace DamageAssesment.Api.UsersAccess.Interfaces -{ - public interface IUsersAccessProvider - { - public Task<(bool IsSuccess, IEnumerable< Models.User> Users, string ErrorMessage)> GetUsersAsync(); - public Task<(bool IsSuccess, Models.User User, string ErrorMessage)> GetUsersAsync(int Id); - public Task<(bool IsSuccess, Models.User User, string ErrorMessage)> PostUserAsync(Models.User User); - public Task<(bool IsSuccess, Models.User User, string ErrorMessage)> PutUserAsync(int Id,Models.User User); - public Task<(bool IsSuccess, Models.User User, string ErrorMessage)> DeleteUserAsync(int Id); - public Task<(bool IsSuccess, IEnumerable Roles, string ErrorMessage)> GetRolesAsync(); - public Task<(bool IsSuccess, Models.TokenResponse TokenResponse, string ErrorMessage)> AuthenticateAsync(UserCredentials userCredentials); - public Task<(bool IsSuccess, Models.TokenResponse TokenResponse, string ErrorMessage)>RefreshTokenAsync(TokenResponse tokenResponse); - } -} diff --git a/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Models/Employee.cs b/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Models/Employee.cs deleted file mode 100644 index e14f27d..0000000 --- a/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Models/Employee.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System.ComponentModel.DataAnnotations; - -namespace DamageAssesment.Api.UsersAccess.Models -{ - public class Employee - { - public string Id { get; set; } - - [StringLength(50)] - public string Name { get; set; } - - public DateTime BirthDate { get; set; } - - [StringLength(50)] - public string OfficePhoneNumber { get; set; } - - [StringLength(50)] - public string Email { get; set; } - public bool IsActive { get; set; } - } -} diff --git a/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Models/JwtSettings.cs b/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Models/JwtSettings.cs deleted file mode 100644 index 3f9dadf..0000000 --- a/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Models/JwtSettings.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System.ComponentModel.DataAnnotations; -namespace DamageAssesment.Api.UsersAccess.Models -{ - - public class JwtSettings - { - public string securitykey { get; set; } - } -} \ No newline at end of file diff --git a/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Models/Role.cs b/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Models/Role.cs deleted file mode 100644 index 809e677..0000000 --- a/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Models/Role.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System.ComponentModel.DataAnnotations; -namespace DamageAssesment.Api.UsersAccess.Models -{ - public class Role { - public int Id { get; set; } - public string Name { get; set; } - public string? Description { get; set; } - } -} diff --git a/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Models/Token.cs b/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Models/Token.cs deleted file mode 100644 index 9c46d81..0000000 --- a/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Models/Token.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace DamageAssesment.Api.UsersAccess.Models -{ - public class Token - { - public string Id { get; set; } - public int UserId { get; set; } - public string? RefreshToken { get; set; } - public bool? IsActive { get; set; } - } -} diff --git a/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Models/TokenResponse.cs b/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Models/TokenResponse.cs deleted file mode 100644 index 4d0b6da..0000000 --- a/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Models/TokenResponse.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace DamageAssesment.Api.UsersAccess.Models -{ - public class TokenResponse - { - public string? jwttoken { get; set; } - public string? refreshtoken { get; set; } - } -} \ No newline at end of file diff --git a/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Models/User.cs b/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Models/User.cs deleted file mode 100644 index f3c9971..0000000 --- a/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Models/User.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace DamageAssesment.Api.UsersAccess.Models -{ - public class User - { - public int Id { get; set; } - public string EmployeeId { get; set; } - public int RoleId { get; set; } - public bool? IsActive { get; set; } - public DateTime? CreateDate { get; set; } - public DateTime? UpdateDate { get; set; } - } -} diff --git a/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Models/UserCredentials.cs b/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Models/UserCredentials.cs deleted file mode 100644 index a23a43b..0000000 --- a/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Models/UserCredentials.cs +++ /dev/null @@ -1,5 +0,0 @@ -public class UserCredentials -{ - public string? username { get; set; } - // public string? password { get; set; } -} \ No newline at end of file diff --git a/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Profiles/UsersAccessProfile.cs b/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Profiles/UsersAccessProfile.cs deleted file mode 100644 index bf744eb..0000000 --- a/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Profiles/UsersAccessProfile.cs +++ /dev/null @@ -1,14 +0,0 @@ -namespace DamageAssesment.Api.UsersAccess.Profiles -{ - public class UsersAccessProfile : AutoMapper.Profile - { - public UsersAccessProfile() - { - CreateMap(); - CreateMap(); - - CreateMap(); - CreateMap(); - } - } -} diff --git a/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Program.cs b/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Program.cs deleted file mode 100644 index a7fb1ac..0000000 --- a/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Program.cs +++ /dev/null @@ -1,77 +0,0 @@ -using DamageAssesment.Api.UsersAccess.Db; -using DamageAssesment.Api.UsersAccess.Interfaces; -using DamageAssesment.Api.UsersAccess.Providers; -using DamageAssesment.Api.UsersAccess.Models; -using Microsoft.AspNetCore.Authentication.JwtBearer; -using Microsoft.EntityFrameworkCore; -using Microsoft.IdentityModel.Tokens; -using System.Text; -using Polly; -using DamageAssesment.Api.SurveyResponses.Providers; - -const int maxApiCallRetries = 3; -const int intervalToRetry = 2; //2 seconds -const int maxRetryForCircuitBraker = 5; -const int intervalForCircuitBraker = 5; //5 seconds - -var builder = WebApplication.CreateBuilder(args); - -// Add services to the container. -var authkey = builder.Configuration.GetValue("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 - }; -}); - -var _jwtsettings = builder.Configuration.GetSection("JwtSettings"); -builder.Services.Configure(_jwtsettings); - - - -builder.Services.AddHttpClient(). - AddTransientHttpErrorPolicy(policy => policy.WaitAndRetryAsync(maxApiCallRetries, _ => TimeSpan.FromSeconds(intervalToRetry))). - AddTransientHttpErrorPolicy(policy => policy.CircuitBreakerAsync(maxRetryForCircuitBraker, TimeSpan.FromSeconds(intervalForCircuitBraker))); - -builder.Services.AddControllers(); -// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle -builder.Services.AddScoped(); -builder.Services.AddScoped(); -builder.Services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies()); -builder.Services.AddEndpointsApiExplorer(); -builder.Services.AddSwaggerGen(); -builder.Services.AddDbContext(option => -{ - option.UseInMemoryDatabase("UsersAccess"); -}); - - - - -var app = builder.Build(); - -// Configure the HTTP request pipeline. -if (app.Environment.IsDevelopment()) -{ - app.UseSwagger(); - app.UseSwaggerUI(); -} - -app.UseAuthentication(); -app.UseAuthorization(); - -app.MapControllers(); - -app.Run(); diff --git a/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Properties/launchSettings.json b/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Properties/launchSettings.json deleted file mode 100644 index 859e680..0000000 --- a/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Properties/launchSettings.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "$schema": "https://json.schemastore.org/launchsettings.json", - "iisSettings": { - "windowsAuthentication": false, - "anonymousAuthentication": true, - "iisExpress": { - "applicationUrl": "http://localhost:28382", - "sslPort": 0 - } - }, - "profiles": { - "DamageAssesment.Api.Users": { - "commandName": "Project", - "dotnetRunMessages": true, - "launchBrowser": true, - "launchUrl": "swagger", - "applicationUrl": "http://localhost:5027", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } - }, - "IIS Express": { - "commandName": "IISExpress", - "launchBrowser": true, - "launchUrl": "swagger", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } - } - } -} diff --git a/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Providers/EmployeeServiceProvider.cs b/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Providers/EmployeeServiceProvider.cs deleted file mode 100644 index ace59ee..0000000 --- a/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Providers/EmployeeServiceProvider.cs +++ /dev/null @@ -1,58 +0,0 @@ -using DamageAssesment.Api.UsersAccess.Bases; -using DamageAssesment.Api.UsersAccess.Interfaces; -using DamageAssesment.Api.UsersAccess.Models; -using Newtonsoft.Json; -using System.Reflection; - -namespace DamageAssesment.Api.SurveyResponses.Providers -{ - public class EmployeeServiceProvider :ServiceProviderBase, IEmployeeServiceProvider - { - public EmployeeServiceProvider(IConfiguration configuration, HttpClient httpClient, ILogger logger) : base(configuration, httpClient, logger, "/api/Employees", configuration.GetValue("EndPointSettings:EmployeeUrlBase")) - { - } - - public async Task> getEmployeesAsync() - { - try - { - httpClient.BaseAddress = new Uri(urlBase); - var response = await httpClient.GetAsync(ressource); - response.EnsureSuccessStatusCode(); - var responseString = await response.Content.ReadAsStringAsync(); - var employees = JsonConvert.DeserializeObject>(responseString); - - if (employees == null || !employees.Any()) - return null; - else return employees; - } - catch (Exception ex) - { - logger?.LogError($"Exception Found : {ex.Message} - Ref: EmployeeServiceProvider.getEmployeesAsync()"); - return null; - } - } - - public async Task getEmployeeAsync(string employeeID) - { - try - { - httpClient.BaseAddress = new Uri(urlBase); - //ressource = ressource + "/" + employeeID; - var response = await httpClient.GetAsync("/api/Employees/"+ employeeID); - response.EnsureSuccessStatusCode(); - var responseString = await response.Content.ReadAsStringAsync(); - var employee = JsonConvert.DeserializeObject(responseString); - - if (employee == null ) - return null; - else return employee; - } - catch (Exception ex) - { - logger?.LogError($"Exception Found : {ex.Message} - Ref: EmployeeServiceProvider.getEmployeeAsync()"); - return null; - } - } - } -} diff --git a/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Providers/TokenServiceProvider.cs b/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Providers/TokenServiceProvider.cs deleted file mode 100644 index a77d6bc..0000000 --- a/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Providers/TokenServiceProvider.cs +++ /dev/null @@ -1,57 +0,0 @@ -using System.IdentityModel.Tokens.Jwt; -using System.Security.Claims; -using System.Security.Cryptography; -using System.Text; -using DamageAssesment.Api.UsersAccess.Db; -using DamageAssesment.Api.UsersAccess.Interfaces; -using DamageAssesment.Api.UsersAccess.Models; -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Options; -using Microsoft.IdentityModel.Tokens; - -public class TokenServiceProvider : ITokenServiceProvider -{ - private readonly UsersAccessDbContext usersAccessDbContext; - private readonly JwtSettings jwtSettings; - public TokenServiceProvider(IOptions options,UsersAccessDbContext usersAccessDbContext) - { - this.usersAccessDbContext = usersAccessDbContext; - this.jwtSettings = options.Value; - } - public async Task GenerateToken(DamageAssesment.Api.UsersAccess.Models.User user) - { - var randomnumber = new byte[32]; - using (var ramdomnumbergenerator = RandomNumberGenerator.Create()) - { - ramdomnumbergenerator.GetBytes(randomnumber); - string refreshtoken = Convert.ToBase64String(randomnumber); - var token = await usersAccessDbContext.Tokens.FirstOrDefaultAsync(item => item.UserId == user.Id); - if (token != null) - { - token.RefreshToken = refreshtoken; - } - else - { - usersAccessDbContext.Tokens.Add(new DamageAssesment.Api.UsersAccess.Db.Token() - { - Id = new Random().Next().ToString(), - UserId = user.Id, - RefreshToken = refreshtoken, - IsActive = true - }); - } - await usersAccessDbContext.SaveChangesAsync(); - - return refreshtoken; - } - } - - public async Task TokenAuthenticate(DamageAssesment.Api.UsersAccess.Models.User user, Claim[] claims) - { - var token = new JwtSecurityToken(claims: claims, expires: DateTime.Now.AddSeconds(20), - signingCredentials: new SigningCredentials(new SymmetricSecurityKey(Encoding.UTF8.GetBytes(jwtSettings.securitykey)), SecurityAlgorithms.HmacSha256) - ); - var jwttoken = new JwtSecurityTokenHandler().WriteToken(token); - return new TokenResponse() { jwttoken = jwttoken, refreshtoken = await GenerateToken(user) }; - } -} \ No newline at end of file diff --git a/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Providers/UserAccessProvider.cs b/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Providers/UserAccessProvider.cs deleted file mode 100644 index 6188d92..0000000 --- a/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Providers/UserAccessProvider.cs +++ /dev/null @@ -1,341 +0,0 @@ -using AutoMapper; -using DamageAssesment.Api.UsersAccess.Db; -using DamageAssesment.Api.UsersAccess.Interfaces; -using DamageAssesment.Api.UsersAccess.Models; -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Options; -using Microsoft.IdentityModel.Tokens; -using System.Data; -using System.IdentityModel.Tokens.Jwt; -using System.Security.Claims; -using System.Text; - -namespace DamageAssesment.Api.UsersAccess.Providers -{ - public class UsersAccessProvider : IUsersAccessProvider - { - private readonly UsersAccessDbContext userAccessDbContext; - private readonly ILogger logger; - private readonly IMapper mapper; - private readonly IEmployeeServiceProvider employeeServiceProvider; - private readonly JwtSettings jwtSettings; - private readonly ITokenServiceProvider tokenServiceProvider; - - public UsersAccessProvider(IOptions options, ITokenServiceProvider tokenServiceProvider, UsersAccessDbContext userAccessDbContext, IEmployeeServiceProvider employeeServiceProvider, ILogger logger, IMapper mapper) - { - this.userAccessDbContext = userAccessDbContext; - this.employeeServiceProvider = employeeServiceProvider; - this.logger = logger; - this.mapper = mapper; - jwtSettings = options.Value; - this.tokenServiceProvider = tokenServiceProvider; - seedData(); - } - - private void seedData() - { - if (!userAccessDbContext.Users.Any()) - { - userAccessDbContext.Users.Add(new Db.User { Id = 1, EmployeeId = "Emp1", RoleId = 1 }); - userAccessDbContext.Users.Add(new Db.User { Id = 2, EmployeeId = "Emp2", RoleId = 2 }); - userAccessDbContext.Users.Add(new Db.User { Id = 3, EmployeeId = "Emp3", RoleId = 3 }); - userAccessDbContext.SaveChanges(); - } - - if (!userAccessDbContext.Roles.Any()) - { - userAccessDbContext.Roles.Add(new Db.Role { Id = 1, Name = "admin" }); - userAccessDbContext.Roles.Add(new Db.Role { Id = 2, Name = "user" }); - userAccessDbContext.Roles.Add(new Db.Role { Id = 3, Name = "survey" }); - userAccessDbContext.Roles.Add(new Db.Role { Id = 4, Name = "report" }); - userAccessDbContext.Roles.Add(new Db.Role { Id = 5, Name = "document" }); - userAccessDbContext.SaveChanges(); - } - } - - public async Task<(bool IsSuccess, IEnumerable Users, string ErrorMessage)> GetUsersAsync() - { - try - { - logger?.LogInformation("Gell all Users from DB"); - var users = await userAccessDbContext.Users.ToListAsync(); - if (users != null) - { - logger?.LogInformation($"{users.Count} Items(s) found"); - var result = mapper.Map, IEnumerable>(users); - return (true, result, null); - } - return (false, null, "Not found"); - } - catch (Exception ex) - { - logger?.LogError(ex.ToString()); - return (false, null, ex.Message); - } - } - - public async Task<(bool IsSuccess, Models.User User, string ErrorMessage)> GetUsersAsync(int Id) - { - try - { - logger?.LogInformation("Querying Users table"); - var user = await userAccessDbContext.Users.SingleOrDefaultAsync(s => s.Id == Id); - if (user != null) - { - logger?.LogInformation($"User Id: {Id} found"); - var result = mapper.Map(user); - return (true, result, null); - } - return (false, null, "Not found"); - } - catch (Exception ex) - { - logger?.LogError(ex.ToString()); - return (false, null, ex.Message); - } - } - - public async Task<(bool IsSuccess, Models.User User, string ErrorMessage)> PostUserAsync(Models.User user) - { - try - { - if (user != null) - { - var users = await userAccessDbContext.Users.ToListAsync(); - int count = users.Where(u => u.EmployeeId == user.EmployeeId).Count(); - if (count == 0) - { - user.Id = users.Count + 1; - userAccessDbContext.Users.Add(mapper.Map(user)); - await userAccessDbContext.SaveChangesAsync(); - return (true, user, "Successful"); - } - else - { - logger?.LogInformation($"Employee Id: {user.EmployeeId} is already exist"); - return (false, null, $"Employee Id: {user.EmployeeId} is already exist"); - } - } - else - { - logger?.LogInformation($"Employee Id: {user.EmployeeId} cannot be added"); - return (false, null, $"Employee Id: {user.EmployeeId} cannot be added"); - } - } - catch (Exception ex) - { - logger?.LogError(ex.ToString()); - return (false, null, ex.Message); - } - } - - public async Task<(bool IsSuccess, Models.User User, string ErrorMessage)> PutUserAsync(int Id, Models.User user) - { - try - { - if (user != null) - { - var _user = await userAccessDbContext.Users.Where(s => s.Id == Id).SingleOrDefaultAsync(); - - if (_user != null) - { - int count = userAccessDbContext.Users.Where(u => u.Id != user.Id && u.EmployeeId == user.EmployeeId).Count(); - if (count == 0) - { - _user.EmployeeId = user.EmployeeId; - _user.RoleId = user.RoleId; - _user.IsActive = user.IsActive; - _user.UpdateDate = DateTime.Now; - await userAccessDbContext.SaveChangesAsync(); - - - logger?.LogInformation($"Employee Id: {user.EmployeeId} updated successfuly"); - return (true, mapper.Map(_user), $"Employee Id: {_user.EmployeeId} updated successfuly"); - } - else - { - logger?.LogInformation($"Employee Id: {user.EmployeeId} is already exist"); - return (false, null, $"Employee Id: {user.EmployeeId} is already exist"); - } - } - else - { - logger?.LogInformation($"User Id : {Id} Not found"); - return (false, null, "Not Found"); - } - } - else - { - logger?.LogInformation($"User Id: {Id} Bad Request"); - return (false, null, "Bad request"); - } - } - catch (Exception ex) - { - logger?.LogError(ex.ToString()); - return (false, null, ex.Message); - } - } - - public async Task<(bool IsSuccess, Models.User User, string ErrorMessage)> DeleteUserAsync(int Id) - { - try - { - var user = await userAccessDbContext.Users.Where(x => x.Id == Id).SingleOrDefaultAsync(); - - if (user != null) - { - userAccessDbContext.Users.Remove(user); - await userAccessDbContext.SaveChangesAsync(); - logger?.LogInformation($"User Id: {Id} deleted Successfuly"); - return (true, mapper.Map(user), $"User Id: {Id} deleted Successfuly"); - } - else - { - logger?.LogInformation($"User Id : {Id} Not found"); - return (false, null, "Not Found"); - } - } - catch (Exception ex) - { - logger?.LogError(ex.ToString()); - return (false, null, ex.Message); - } - } - - public async Task<(bool IsSuccess, TokenResponse TokenResponse, string ErrorMessage)> AuthenticateAsync(UserCredentials userCredentials) - { - - if (userCredentials != null) - { - //implementation for dadeschools authentication - - var employee = await employeeServiceProvider.getEmployeeAsync(userCredentials.username); - - if (employee != null) - { - var result = await GetUsersAsync(); - - if (result.IsSuccess) - { - var user = result.Users.Where(x => x.IsActive == true && x.EmployeeId.ToLower().Equals(userCredentials.username.ToLower())).SingleOrDefault(); - - if (user != null) - { - - var r = await GetRolesAsync(); - var role = r.Roles.Where(x => x.Id == user.RoleId).SingleOrDefault(); - - var authClaims = new List { - new Claim(ClaimTypes.Name, user.EmployeeId), - new Claim(ClaimTypes.Role, role.Name), - new Claim(JwtRegisteredClaimNames.Jti,Guid.NewGuid().ToString()) - - }; - - /// Generate Token - var tokenhandler = new JwtSecurityTokenHandler(); - var tokenkey = Encoding.UTF8.GetBytes(jwtSettings.securitykey); - var tokendesc = new SecurityTokenDescriptor - { - Audience = "", - NotBefore = DateTime.Now, - Subject = new ClaimsIdentity(authClaims), - Expires = DateTime.Now.AddMinutes(30), - SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(tokenkey), SecurityAlgorithms.HmacSha256) - }; - var token = tokenhandler.CreateToken(tokendesc); - string finaltoken = tokenhandler.WriteToken(token); - - var response = new TokenResponse() { jwttoken = finaltoken, refreshtoken = await tokenServiceProvider.GenerateToken(user) }; - - - return (true, response, "Authentication success and token issued."); - - } - else - { - return (false, null, "user inactive or not exist."); - } - } - else - { - return (false, null, "users list empty."); - } - } - else - { - return (false, null, "Employee not exist."); - } - } - else - { - return (false, null, "Credentials are required to authenticate."); - - } - - } - public async Task<(bool IsSuccess, IEnumerable Roles, string ErrorMessage)> GetRolesAsync() - { - try - { - logger?.LogInformation("Gell all Roles from DB"); - var roles = await userAccessDbContext.Roles.ToListAsync(); - if (roles != null) - { - logger?.LogInformation($"{roles.Count} Items(s) found"); - var result = mapper.Map, IEnumerable>(roles); - return (true, result, null); - } - return (false, null, "Not found"); - } - catch (Exception ex) - { - logger?.LogError(ex.ToString()); - return (false, null, ex.Message); - } - } - - public async Task<(bool IsSuccess, Models.TokenResponse TokenResponse, string ErrorMessage)> RefreshTokenAsync(TokenResponse tokenResponse) - { - //Generate token - var tokenhandler = new JwtSecurityTokenHandler(); - var tokenkey = Encoding.UTF8.GetBytes(this.jwtSettings.securitykey); - SecurityToken securityToken; - var principal = tokenhandler.ValidateToken(tokenResponse.jwttoken, new TokenValidationParameters - { - ValidateIssuerSigningKey = true, - IssuerSigningKey = new SymmetricSecurityKey(tokenkey), - ValidateIssuer = false, - ValidateAudience = false, - - }, out securityToken); - - var token = securityToken as JwtSecurityToken; - if (token != null && !token.Header.Alg.Equals(SecurityAlgorithms.HmacSha256)) - { - return (false, null, "Unauthorized"); - } - var username = principal.Identity?.Name; - - var tokens = await userAccessDbContext.Tokens.ToListAsync(); - var users = await userAccessDbContext.Users.ToListAsync(); - - var user = (from u in users - join t in tokens - on u.Id equals t.UserId - where u.EmployeeId == username - && t.RefreshToken == tokenResponse.refreshtoken - select u).FirstOrDefault(); - - if (user == null) - return (false, null, "Invalid Token Response object provided"); - - var _user = mapper.Map(user); - var response = tokenServiceProvider.TokenAuthenticate(_user, principal.Claims.ToArray()).Result; - return (true, response, "Token authenticated and refreshed."); - } - - - } -} diff --git a/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/appsettings.Development.json b/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/appsettings.Development.json deleted file mode 100644 index 0c208ae..0000000 --- a/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/appsettings.Development.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft.AspNetCore": "Warning" - } - } -} diff --git a/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/appsettings.json b/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/appsettings.json deleted file mode 100644 index 4a1b1b5..0000000 --- a/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/appsettings.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "JwtSettings": { - "securitykey": "bWlhbWkgZGFkZSBzY2hvb2xzIHNlY3JldCBrZXk=" - }, - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft.AspNetCore": "Warning" - } - }, - "EndPointSettings": { - "EmployeeUrlBase": "http://localhost:5135" - }, - "AllowedHosts": "*" -} diff --git a/DamageAssesmentApi/DamageAssesment.sln b/DamageAssesmentApi/DamageAssesment.sln index 8deb2aa..101bcec 100644 --- a/DamageAssesmentApi/DamageAssesment.sln +++ b/DamageAssesmentApi/DamageAssesment.sln @@ -37,8 +37,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DamageAssesment.Api.Employe EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DamageAssesment.Api.Employees.Test", "DamageAssesment.Api.Employees.Test\DamageAssesment.Api.Employees.Test.csproj", "{D6BF9AE9-72FA-4726-A326-35A35D27FFB8}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DamageAssesment.Api.UsersAccess", "DamageAssesment.Api.UsersAccess\DamageAssesment.Api.UsersAccess.csproj", "{83177BB9-DD23-4A85-A000-D60F843D0835}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -101,10 +99,6 @@ Global {D6BF9AE9-72FA-4726-A326-35A35D27FFB8}.Debug|Any CPU.Build.0 = Debug|Any CPU {D6BF9AE9-72FA-4726-A326-35A35D27FFB8}.Release|Any CPU.ActiveCfg = Release|Any CPU {D6BF9AE9-72FA-4726-A326-35A35D27FFB8}.Release|Any CPU.Build.0 = Release|Any CPU - {83177BB9-DD23-4A85-A000-D60F843D0835}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {83177BB9-DD23-4A85-A000-D60F843D0835}.Debug|Any CPU.Build.0 = Debug|Any CPU - {83177BB9-DD23-4A85-A000-D60F843D0835}.Release|Any CPU.ActiveCfg = Release|Any CPU - {83177BB9-DD23-4A85-A000-D60F843D0835}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE