forked from MDCPS/DamageAssessment_Backend
Compare commits
84 Commits
user-acces
...
Sql-userac
Author | SHA1 | Date | |
---|---|---|---|
9b22249a89 | |||
947ee16281 | |||
2a2418c85e | |||
9353d6ab2c | |||
5644762e00 | |||
1b638d9367 | |||
073fbac743 | |||
5eb9314e96 | |||
34b4adf0bf | |||
4b863687d3 | |||
735a5ee62c | |||
eb28885f00 | |||
6d3f5dd5b8 | |||
2baf4b9dad | |||
4f478585cf | |||
556dc5e4e7 | |||
01bfa9c4b5 | |||
6bdbcb8e57 | |||
2a73324ff7 | |||
9b8e8ffad2 | |||
dd5351665e | |||
ff4e8de3f3 | |||
c014739fc0 | |||
70d0043e25 | |||
ff3847ecae | |||
7baff934ab | |||
28de758da0 | |||
bb87f1c8e0 | |||
52869afc3f | |||
71b8031577 | |||
4936e3e6f1 | |||
30b8d1ff9f | |||
79beaf55fa | |||
8c12477763 | |||
cc9ce4dbe5 | |||
3cd0c5f39e | |||
334c327559 | |||
87fa29d9d4 | |||
2ab8f37489 | |||
500582020b | |||
ede178042f | |||
6575c2f219 | |||
69584e6c91 | |||
1cbd6893d8 | |||
79a3073bea | |||
bdde55b3e5 | |||
cd982d160a | |||
9b88029a09 | |||
3b9e13ad35 | |||
dca119758a | |||
8285588db9 | |||
fc166e65c9 | |||
ae6b306290 | |||
d3a751a6ad | |||
2182b9a6b3 | |||
e2bed66428 | |||
8624eeeb97 | |||
16d45d6632 | |||
c77e0452c4 | |||
6ad5bb1572 | |||
8e0a7df68b | |||
cb3c7f8f6a | |||
01ccd97528 | |||
26b360e0a9 | |||
360a58c026 | |||
26e79432e2 | |||
11c6fc0dc9 | |||
99633d8dda | |||
8e3f6674c6 | |||
885fdeb117 | |||
14956057cd | |||
fa3e3bbd99 | |||
340ba6fa6d | |||
46794057c4 | |||
71d4b524e7 | |||
c7a2dc5910 | |||
643bc0c76a | |||
d0023114a3 | |||
465bf4b081 | |||
e04bccfffd | |||
0544c7397d | |||
9c536a1c52 | |||
48be1a74c9 | |||
eb07c31ff6 |
BIN
.vs/Backend-API-Services/v17/.wsuo
Normal file
BIN
.vs/Backend-API-Services/v17/.wsuo
Normal file
Binary file not shown.
7
.vs/VSWorkspaceState.json
Normal file
7
.vs/VSWorkspaceState.json
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"ExpandedNodes": [
|
||||||
|
""
|
||||||
|
],
|
||||||
|
"SelectedNode": "\\DamageAssesment.sln",
|
||||||
|
"PreviewInSolutionExplorer": false
|
||||||
|
}
|
3
DamageAssesmentApi/.gitignore
vendored
3
DamageAssesmentApi/.gitignore
vendored
@ -395,4 +395,5 @@ FodyWeavers.xsd
|
|||||||
*.msp
|
*.msp
|
||||||
|
|
||||||
# JetBrains Rider
|
# JetBrains Rider
|
||||||
*.sln.iml
|
*.sln.iml
|
||||||
|
**/migrations/
|
@ -13,8 +13,16 @@
|
|||||||
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1" />
|
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.21" />
|
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.21" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.9" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.9" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.9">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.9" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.9" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.9" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
|
||||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.4" />
|
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.4" />
|
||||||
|
<PackageReference Include="Serilog.Extensions.Logging.File" Version="3.0.0" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ using System.ComponentModel.DataAnnotations.Schema;
|
|||||||
|
|
||||||
namespace DamageAssesment.Api.Answers.Db
|
namespace DamageAssesment.Api.Answers.Db
|
||||||
{
|
{
|
||||||
|
[Table("Answers")]
|
||||||
public class Answer
|
public class Answer
|
||||||
{
|
{
|
||||||
[Key]
|
[Key]
|
||||||
|
@ -1,13 +1,19 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
|
||||||
namespace DamageAssesment.Api.Answers.Db
|
namespace DamageAssesment.Api.Answers.Db
|
||||||
{
|
{
|
||||||
public class AnswerDbContext:DbContext
|
public class AnswerDbContext:DbContext
|
||||||
{
|
{
|
||||||
|
private IConfiguration _Configuration { get; set; }
|
||||||
public AnswerDbContext(DbContextOptions options):base(options)
|
public AnswerDbContext(DbContextOptions options,IConfiguration configuration):base(options)
|
||||||
{
|
{
|
||||||
|
_Configuration= configuration;
|
||||||
|
}
|
||||||
|
protected override void OnConfiguring(DbContextOptionsBuilder options)
|
||||||
|
{
|
||||||
|
// connect to sql server with connection string from app settings
|
||||||
|
options.UseSqlServer(_Configuration.GetConnectionString("AnswerConnection"));
|
||||||
}
|
}
|
||||||
public DbSet<Db.Answer> Answers { get; set; }
|
public DbSet<Db.Answer> Answers { get; set; }
|
||||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
|
@ -9,6 +9,10 @@ using System.Reflection;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
builder.Services.AddCors(p => p.AddPolicy("DamageAppCorsPolicy", build => {
|
||||||
|
build.WithOrigins("*").AllowAnyMethod().AllowAnyHeader().AllowAnyOrigin();
|
||||||
|
}));
|
||||||
|
|
||||||
var authkey = builder.Configuration.GetValue<string>("JwtSettings:securitykey");
|
var authkey = builder.Configuration.GetValue<string>("JwtSettings:securitykey");
|
||||||
builder.Services.AddAuthentication(item =>
|
builder.Services.AddAuthentication(item =>
|
||||||
{
|
{
|
||||||
@ -27,6 +31,11 @@ builder.Services.AddAuthentication(item =>
|
|||||||
ClockSkew = TimeSpan.Zero
|
ClockSkew = TimeSpan.Zero
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
builder.Services.AddLogging(builder =>
|
||||||
|
{
|
||||||
|
//builder.AddConsole(); // Optional: Add other providers if needed
|
||||||
|
builder.AddFile("logs/answers-{Date}.txt"); // Specify the file path and format
|
||||||
|
});
|
||||||
// Add services to the container.
|
// Add services to the container.
|
||||||
|
|
||||||
builder.Services.AddControllers();
|
builder.Services.AddControllers();
|
||||||
@ -73,7 +82,7 @@ builder.Services.AddScoped<IAnswersProvider, AnswersProvider>();
|
|||||||
builder.Services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies()); //4/30
|
builder.Services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies()); //4/30
|
||||||
builder.Services.AddDbContext<AnswerDbContext>(option =>
|
builder.Services.AddDbContext<AnswerDbContext>(option =>
|
||||||
{
|
{
|
||||||
option.UseInMemoryDatabase("Answers");
|
option.UseSqlServer("AnswerConnection");
|
||||||
});
|
});
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
@ -85,6 +94,7 @@ if (app.Environment.IsDevelopment())
|
|||||||
app.UseSwagger();
|
app.UseSwagger();
|
||||||
app.UseSwaggerUI();
|
app.UseSwaggerUI();
|
||||||
}
|
}
|
||||||
|
app.UseCors("DamageAppCorsPolicy");
|
||||||
app.UseAuthentication();
|
app.UseAuthentication();
|
||||||
app.UseAuthorization();
|
app.UseAuthorization();
|
||||||
|
|
||||||
|
@ -198,13 +198,12 @@ namespace DamageAssesment.Api.Answers.Providers
|
|||||||
{
|
{
|
||||||
if (!answerDbContext.Answers.Any())
|
if (!answerDbContext.Answers.Any())
|
||||||
{
|
{
|
||||||
answerDbContext.Answers.Add(new Db.Answer() { Id = 1, AnswerText = "Yes", Comment = "Comment test 4", QuestionId = 1, SurveyResponseId = 1 });
|
answerDbContext.Answers.Add(new Db.Answer() { AnswerText = "Yes", Comment = "", QuestionId = 1, SurveyResponseId = 1 });
|
||||||
answerDbContext.Answers.Add(new Db.Answer() { Id = 2, AnswerText = "No", Comment = "Comment test 5", QuestionId = 2, SurveyResponseId = 1 });
|
answerDbContext.Answers.Add(new Db.Answer() { AnswerText = "No", Comment = "myComment", QuestionId = 2, SurveyResponseId = 1 });
|
||||||
// Uncomment the lines below to add more initial data if needed
|
//answerDbContext.Answers.Add(new Db.Answer() { AnswerText = "No", Comment = "No Comment", QuestionId = 3, SurveyResponseId = 1 });
|
||||||
//answerDbContext.Answers.Add(new Db.Answer() { Id = 3, AnswerText = "No", Comment = "No Comment", QuestionId = 3, SurveyResponseId = 1 });
|
//answerDbContext.Answers.Add(new Db.Answer() { AnswerText = "Yes", Comment = "No Comment", QuestionId = 1, SurveyResponseId = 2 });
|
||||||
//answerDbContext.Answers.Add(new Db.Answer() { Id = 4, AnswerText = "Yes", Comment = "No Comment", QuestionId = 1, SurveyResponseId = 2 });
|
//answerDbContext.Answers.Add(new Db.Answer() { AnswerText = "No", Comment = "No Comment", QuestionId = 2, SurveyResponseId = 2 });
|
||||||
//answerDbContext.Answers.Add(new Db.Answer() { Id = 5, AnswerText = "No", Comment = "No Comment", QuestionId = 2, SurveyResponseId = 2 });
|
//answerDbContext.Answers.Add(new Db.Answer() { AnswerText = "No", Comment = "No Comment", QuestionId = 3, SurveyResponseId = 2 });
|
||||||
//answerDbContext.Answers.Add(new Db.Answer() { Id = 6, AnswerText = "No", Comment = "No Comment", QuestionId = 3, SurveyResponseId = 2 });
|
|
||||||
answerDbContext.SaveChanges();
|
answerDbContext.SaveChanges();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +0,0 @@
|
|||||||
{
|
|
||||||
"Logging": {
|
|
||||||
"LogLevel": {
|
|
||||||
"Default": "Information",
|
|
||||||
"Microsoft.AspNetCore": "Warning"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -8,5 +8,10 @@
|
|||||||
"Microsoft.AspNetCore": "Warning"
|
"Microsoft.AspNetCore": "Warning"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"AllowedHosts": "*"
|
"AllowedHosts": "*",
|
||||||
|
"ConnectionStrings": {
|
||||||
|
//"AnswerConnection": "Server=DESKTOP-OF5DPLQ\\SQLEXPRESS;Database=da_survey_dev;Trusted_Connection=True;TrustServerCertificate=True;"
|
||||||
|
"AnswerConnection": "Server=207.180.248.35;Database=da_survey_dev;User Id=sa;Password=YourStrongPassw0rd;TrustServerCertificate=True;"
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -79,8 +79,8 @@ namespace DamageAssesment.Api.Attachments.Test
|
|||||||
var mockInputAttachment = await MockData.getInputAttachmentData();
|
var mockInputAttachment = await MockData.getInputAttachmentData();
|
||||||
mockAttachmentService.Setup(service => service.PostAttachmentAsync(mockInputAttachment)).ReturnsAsync(mockResponse);
|
mockAttachmentService.Setup(service => service.PostAttachmentAsync(mockInputAttachment)).ReturnsAsync(mockResponse);
|
||||||
|
|
||||||
var AttachmentProvider = new AttachmentsController(mockAttachmentService.Object, mockUploadService.Object);
|
var AttachmentProvider = new AttachmentsController(mockAttachmentService.Object, mockUploadService.Object);
|
||||||
var result = (NoContentResult) await AttachmentProvider.UploadAttachmentAsync(AttachmentResponse);
|
var result = (NoContentResult)await AttachmentProvider.UploadAttachmentAsync(AttachmentResponse);
|
||||||
|
|
||||||
Assert.Equal(204, result.StatusCode);
|
Assert.Equal(204, result.StatusCode);
|
||||||
}
|
}
|
||||||
@ -95,8 +95,8 @@ namespace DamageAssesment.Api.Attachments.Test
|
|||||||
mockAttachmentService.Setup(service => service.PostAttachmentAsync(mockInputAttachment)).ReturnsAsync(mockResponse);
|
mockAttachmentService.Setup(service => service.PostAttachmentAsync(mockInputAttachment)).ReturnsAsync(mockResponse);
|
||||||
|
|
||||||
var AttachmentProvider = new AttachmentsController(mockAttachmentService.Object, mockUploadService.Object);
|
var AttachmentProvider = new AttachmentsController(mockAttachmentService.Object, mockUploadService.Object);
|
||||||
AttachmentInfo attachmentInfo=new AttachmentInfo();
|
AttachmentInfo attachmentInfo = new AttachmentInfo();
|
||||||
var result = (BadRequestObjectResult) await AttachmentProvider.UploadAttachmentAsync(attachmentInfo);
|
var result = (BadRequestObjectResult)await AttachmentProvider.UploadAttachmentAsync(attachmentInfo);
|
||||||
|
|
||||||
Assert.Equal(400, result.StatusCode);
|
Assert.Equal(400, result.StatusCode);
|
||||||
}
|
}
|
||||||
@ -112,7 +112,7 @@ namespace DamageAssesment.Api.Attachments.Test
|
|||||||
mockAttachmentService.Setup(service => service.PostAttachmentAsync(mockInputAttachment)).ReturnsAsync(mockResponse);
|
mockAttachmentService.Setup(service => service.PostAttachmentAsync(mockInputAttachment)).ReturnsAsync(mockResponse);
|
||||||
|
|
||||||
var AttachmentProvider = new AttachmentsController(mockAttachmentService.Object, mockUploadService.Object);
|
var AttachmentProvider = new AttachmentsController(mockAttachmentService.Object, mockUploadService.Object);
|
||||||
var result = (NoContentResult) await AttachmentProvider.UpdateAttachmentAsync(AttachmentResponse);
|
var result = (NoContentResult)await AttachmentProvider.UpdateAttachmentAsync(AttachmentResponse);
|
||||||
|
|
||||||
Assert.Equal(204, result.StatusCode);
|
Assert.Equal(204, result.StatusCode);
|
||||||
}
|
}
|
||||||
@ -128,7 +128,7 @@ namespace DamageAssesment.Api.Attachments.Test
|
|||||||
|
|
||||||
var AttachmentProvider = new AttachmentsController(mockAttachmentService.Object, mockUploadService.Object);
|
var AttachmentProvider = new AttachmentsController(mockAttachmentService.Object, mockUploadService.Object);
|
||||||
AttachmentInfo attachmentInfo = new AttachmentInfo();
|
AttachmentInfo attachmentInfo = new AttachmentInfo();
|
||||||
var result = (BadRequestObjectResult) await AttachmentProvider.UpdateAttachmentAsync(attachmentInfo);
|
var result = (BadRequestObjectResult)await AttachmentProvider.UpdateAttachmentAsync(attachmentInfo);
|
||||||
|
|
||||||
Assert.Equal(400, result.StatusCode);
|
Assert.Equal(400, result.StatusCode);
|
||||||
}
|
}
|
||||||
|
@ -13,11 +13,12 @@ namespace DamageAssesment.Api.Attachments.Controllers
|
|||||||
{
|
{
|
||||||
private IAttachmentsProvider AttachmentProvider;
|
private IAttachmentsProvider AttachmentProvider;
|
||||||
private IUploadService UploadService;
|
private IUploadService UploadService;
|
||||||
|
private IAzureBlobService azureBlobService;
|
||||||
|
|
||||||
public AttachmentsController(IAttachmentsProvider AttachmentsProvider, IUploadService uploadService)
|
public AttachmentsController(IAttachmentsProvider AttachmentsProvider, IUploadService UploadService)
|
||||||
{
|
{
|
||||||
this.AttachmentProvider = AttachmentsProvider;
|
this.AttachmentProvider = AttachmentsProvider;
|
||||||
this.UploadService = uploadService;
|
this.UploadService = UploadService;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get all attachments.
|
/// Get all attachments.
|
||||||
@ -91,7 +92,7 @@ namespace DamageAssesment.Api.Attachments.Controllers
|
|||||||
if (attachmentInfo.Answers.Count > 0)
|
if (attachmentInfo.Answers.Count > 0)
|
||||||
{
|
{
|
||||||
var Attachments = await this.AttachmentProvider.GetAttachmentCounter();
|
var Attachments = await this.AttachmentProvider.GetAttachmentCounter();
|
||||||
List<Models.Attachment> attachments = UploadService.UploadAttachment(attachmentInfo.ResponseId, Attachments.counter, attachmentInfo.Answers);
|
List<Models.Attachment> attachments = UploadService.UploadAttachment(attachmentInfo.ResponseId, Attachments.counter, attachmentInfo.Answers);
|
||||||
var result = await this.AttachmentProvider.PostAttachmentAsync(attachments);
|
var result = await this.AttachmentProvider.PostAttachmentAsync(attachments);
|
||||||
if (result.IsSuccess)
|
if (result.IsSuccess)
|
||||||
{
|
{
|
||||||
@ -120,7 +121,7 @@ namespace DamageAssesment.Api.Attachments.Controllers
|
|||||||
var res = await this.AttachmentProvider.GetAttachmentInfo(attachmentInfo.Answers);
|
var res = await this.AttachmentProvider.GetAttachmentInfo(attachmentInfo.Answers);
|
||||||
if (res.IsSuccess)
|
if (res.IsSuccess)
|
||||||
{
|
{
|
||||||
List<Models.Attachment> attachments = UploadService.UpdateAttachments(attachmentInfo.ResponseId, attachmentInfo.Answers, res.Attachments);
|
List<Models.Attachment> attachments = UploadService.UpdateAttachments(attachmentInfo.ResponseId, attachmentInfo.Answers, res.Attachments);
|
||||||
var result = await this.AttachmentProvider.PutAttachmentAsync(attachments);
|
var result = await this.AttachmentProvider.PutAttachmentAsync(attachments);
|
||||||
if (result.IsSuccess)
|
if (result.IsSuccess)
|
||||||
{
|
{
|
||||||
|
@ -14,9 +14,23 @@
|
|||||||
<PackageReference Include="Azure.Storage.Blobs" Version="12.16.0" />
|
<PackageReference Include="Azure.Storage.Blobs" Version="12.16.0" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.21" />
|
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.21" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Hosting" Version="2.2.7" />
|
<PackageReference Include="Microsoft.AspNetCore.Hosting" Version="2.2.7" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.5" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.9" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.5" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.5" />
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.Hosting" Version="2.1.1" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.9">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.9" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.9" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.9">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
|
||||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.4" />
|
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.4" />
|
||||||
|
<PackageReference Include="Serilog.Extensions.Logging.File" Version="3.0.0" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ using System.ComponentModel.DataAnnotations.Schema;
|
|||||||
|
|
||||||
namespace DamageAssesment.Api.Attachments.Db
|
namespace DamageAssesment.Api.Attachments.Db
|
||||||
{
|
{
|
||||||
|
[Table("AnswerAttachments")]
|
||||||
public class Attachment
|
public class Attachment
|
||||||
{
|
{
|
||||||
[Key]
|
[Key]
|
||||||
|
@ -1,11 +1,19 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
|
||||||
namespace DamageAssesment.Api.Attachments.Db
|
namespace DamageAssesment.Api.Attachments.Db
|
||||||
{
|
{
|
||||||
public class AttachmentsDbContext:DbContext
|
public class AttachmentsDbContext:DbContext
|
||||||
{
|
{
|
||||||
public AttachmentsDbContext(DbContextOptions options) : base(options)
|
private IConfiguration _Configuration { get; set; }
|
||||||
|
public AttachmentsDbContext(DbContextOptions options, IConfiguration configuration) : base(options)
|
||||||
{
|
{
|
||||||
|
_Configuration = configuration;
|
||||||
|
}
|
||||||
|
protected override void OnConfiguring(DbContextOptionsBuilder options)
|
||||||
|
{
|
||||||
|
// connect to sql server with connection string from app settings
|
||||||
|
options.UseSqlServer(_Configuration.GetConnectionString("AttachmentConnection"));
|
||||||
}
|
}
|
||||||
public DbSet<Db.Attachment> Attachments { get; set; }
|
public DbSet<Db.Attachment> Attachments { get; set; }
|
||||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
|
@ -1,10 +1,15 @@
|
|||||||
using Azure.Storage.Blobs.Models;
|
using Azure.Storage.Blobs.Models;
|
||||||
|
using DamageAssesment.Api.Attachments.Models;
|
||||||
|
|
||||||
namespace DamageAssesment.Api.Attachments.Interfaces
|
namespace DamageAssesment.Api.Attachments.Interfaces
|
||||||
{
|
{
|
||||||
public interface IAzureBlobService
|
public interface IAzureBlobService
|
||||||
{
|
{
|
||||||
Task<List<Azure.Response<BlobContentInfo>>> UploadFiles(List<IFormFile> files);
|
Task<List<Azure.Response<BlobContentInfo>>> UploadFiles(List<IFormFile> files);
|
||||||
void DeleteFile(string path);
|
Task<List<Attachment>> UploadAttachment(int responseId, int answerId, int counter, List<IFormFile> postedFile);
|
||||||
|
Task<List<Attachment>> UploadAttachment(int responseId, int counter, List<AnswerInfo> answers);
|
||||||
|
Task<List<Attachment>> UpdateAttachments(int responseId, List<AnswerInfo> answers, IEnumerable<Models.Attachment> attachments);
|
||||||
|
void Deletefile(string path);
|
||||||
|
void Movefile(string path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,13 +5,22 @@ using Microsoft.AspNetCore.Authentication.JwtBearer;
|
|||||||
using Microsoft.AspNetCore.Http.Features;
|
using Microsoft.AspNetCore.Http.Features;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Extensions.FileProviders;
|
using Microsoft.Extensions.FileProviders;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.IdentityModel.Tokens;
|
using Microsoft.IdentityModel.Tokens;
|
||||||
using Microsoft.OpenApi.Models;
|
using Microsoft.OpenApi.Models;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
builder.Services.AddCors(p => p.AddPolicy("DamageAppCorsPolicy", build => {
|
||||||
|
build.WithOrigins("*").AllowAnyMethod().AllowAnyHeader().AllowAnyOrigin();
|
||||||
|
}));
|
||||||
var authkey = builder.Configuration.GetValue<string>("JwtSettings:securitykey");
|
var authkey = builder.Configuration.GetValue<string>("JwtSettings:securitykey");
|
||||||
|
builder.Services.AddLogging(builder =>
|
||||||
|
{
|
||||||
|
//builder.AddConsole(); // Optional: Add other providers if needed
|
||||||
|
builder.AddFile("logs/attachments-{Date}.txt"); // Specify the file path and format
|
||||||
|
});
|
||||||
builder.Services.AddAuthentication(item =>
|
builder.Services.AddAuthentication(item =>
|
||||||
{
|
{
|
||||||
item.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
|
item.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
|
||||||
@ -78,7 +87,7 @@ builder.Services.AddScoped<IAzureBlobService,AzureBlobService>();
|
|||||||
builder.Services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies()); //4/30
|
builder.Services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies()); //4/30
|
||||||
builder.Services.AddDbContext<AttachmentsDbContext>(option =>
|
builder.Services.AddDbContext<AttachmentsDbContext>(option =>
|
||||||
{
|
{
|
||||||
option.UseInMemoryDatabase("Attachments");
|
option.UseSqlServer("AttachmentConnection");
|
||||||
});
|
});
|
||||||
builder.Services.Configure<FormOptions>(o =>
|
builder.Services.Configure<FormOptions>(o =>
|
||||||
{
|
{
|
||||||
@ -95,7 +104,7 @@ if (app.Environment.IsDevelopment())
|
|||||||
app.UseSwagger();
|
app.UseSwagger();
|
||||||
app.UseSwaggerUI();
|
app.UseSwaggerUI();
|
||||||
}
|
}
|
||||||
|
app.UseCors("DamageAppCorsPolicy");
|
||||||
app.UseAuthentication();
|
app.UseAuthentication();
|
||||||
app.UseAuthorization();
|
app.UseAuthorization();
|
||||||
app.UseHttpsRedirection();
|
app.UseHttpsRedirection();
|
||||||
|
@ -25,7 +25,7 @@ namespace DamageAssesment.Api.Attachments.Providers
|
|||||||
this.httpContextAccessor = httpContextAccessor;
|
this.httpContextAccessor = httpContextAccessor;
|
||||||
baseUrl = $"{httpContextAccessor.HttpContext.Request.Scheme}://{httpContextAccessor.HttpContext.Request.Host}";
|
baseUrl = $"{httpContextAccessor.HttpContext.Request.Scheme}://{httpContextAccessor.HttpContext.Request.Host}";
|
||||||
baseUrl = baseUrl + "/attachments/download";
|
baseUrl = baseUrl + "/attachments/download";
|
||||||
SeedData();
|
// SeedData();
|
||||||
}
|
}
|
||||||
public async Task<(bool IsSuccess, IEnumerable<Models.Attachment> Attachments, string ErrorMessage)> GetAttachmentsAsync()
|
public async Task<(bool IsSuccess, IEnumerable<Models.Attachment> Attachments, string ErrorMessage)> GetAttachmentsAsync()
|
||||||
{
|
{
|
||||||
|
@ -3,6 +3,9 @@ using Azure.Storage.Blobs;
|
|||||||
using Azure.Storage.Blobs.Models;
|
using Azure.Storage.Blobs.Models;
|
||||||
using Azure.Storage.Blobs.Specialized;
|
using Azure.Storage.Blobs.Specialized;
|
||||||
using DamageAssesment.Api.Attachments.Interfaces;
|
using DamageAssesment.Api.Attachments.Interfaces;
|
||||||
|
using DamageAssesment.Api.Attachments.Models;
|
||||||
|
using System.Diagnostics.Metrics;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
namespace DamageAssesment.Api.Attachments.Providers
|
namespace DamageAssesment.Api.Attachments.Providers
|
||||||
{
|
{
|
||||||
@ -10,11 +13,95 @@ namespace DamageAssesment.Api.Attachments.Providers
|
|||||||
{
|
{
|
||||||
BlobServiceClient _blobClient;
|
BlobServiceClient _blobClient;
|
||||||
BlobContainerClient _containerClient;
|
BlobContainerClient _containerClient;
|
||||||
string azureConnectionString = "<Primary Connection String>";
|
string azureConnectionString;
|
||||||
public AzureBlobService()
|
private string uploadpath = "";
|
||||||
|
private string Deletepath = "";
|
||||||
|
public AzureBlobService(IConfiguration configuration)
|
||||||
{
|
{
|
||||||
_blobClient = new BlobServiceClient(azureConnectionString);
|
uploadpath = configuration.GetValue<string>("Fileupload:folderpath");
|
||||||
_containerClient = _blobClient.GetBlobContainerClient("apiimages");
|
Deletepath = configuration.GetValue<string>("Fileupload:Deletepath");
|
||||||
|
_blobClient = new BlobServiceClient(configuration.GetValue<string>("Fileupload:BlobConnectionString"));
|
||||||
|
_containerClient = _blobClient.GetBlobContainerClient(configuration.GetValue<string>("Fileupload:BlobContainerName"));
|
||||||
|
}
|
||||||
|
public async Task<List<Attachment>> UploadAttachment(int responseId, int answerId, int counter, List<IFormFile> postedFile)
|
||||||
|
{
|
||||||
|
var pathToSave = Path.Combine(uploadpath, "Response-" + responseId);
|
||||||
|
String fullDirectoryPath = Path.Combine(pathToSave, "Answer-" + answerId);
|
||||||
|
List<Models.Attachment> attachments = new List<Models.Attachment>();
|
||||||
|
foreach (IFormFile item in postedFile)
|
||||||
|
{
|
||||||
|
|
||||||
|
counter++;
|
||||||
|
var UserfileName = Path.GetFileName(item.FileName);
|
||||||
|
var extension = System.IO.Path.GetExtension(UserfileName);
|
||||||
|
var fileName = String.Format("Attachment_{0}{1}", counter, extension);
|
||||||
|
var stream = item.OpenReadStream();
|
||||||
|
BlobClient client = _containerClient.GetBlobClient(fullDirectoryPath + "/" + fileName);
|
||||||
|
string dbPath = fullDirectoryPath + "/" + fileName;
|
||||||
|
var result = await client.UploadAsync(stream, true);
|
||||||
|
attachments.Add(new Models.Attachment { AnswerId = answerId, ResponseId = responseId, IsDeleted = false, FileName = UserfileName, URI = dbPath });
|
||||||
|
}
|
||||||
|
return attachments;
|
||||||
|
}
|
||||||
|
public async Task<List<Attachment>> UploadAttachment(int responseId, int counter, List<AnswerInfo> answers)
|
||||||
|
{
|
||||||
|
List<Models.Attachment> attachments = new List<Models.Attachment>();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
foreach (var item in answers)
|
||||||
|
{
|
||||||
|
int answerId = item.AnswerId;
|
||||||
|
var pathToSave = Path.Combine(uploadpath, "Response-" + responseId);
|
||||||
|
String fullDirectoryPath = Path.Combine(pathToSave, "Answer-" + answerId);
|
||||||
|
foreach (var file in item.postedFiles)
|
||||||
|
{
|
||||||
|
counter++;
|
||||||
|
|
||||||
|
var UserfileName = Path.GetFileName(file.FileName);
|
||||||
|
var fileName = String.Format("Attachment_{0}{1}", counter, file.FileExtension);
|
||||||
|
byte[] byteArray = Convert.FromBase64String(file.FileContent);
|
||||||
|
MemoryStream stream = new MemoryStream(byteArray);
|
||||||
|
BlobClient client = _containerClient.GetBlobClient(fullDirectoryPath + "/" + fileName);
|
||||||
|
string dbPath = fullDirectoryPath + "/" + fileName;
|
||||||
|
var result = await client.UploadAsync(stream, true);
|
||||||
|
attachments.Add(new Models.Attachment { AnswerId = answerId, ResponseId = responseId, IsDeleted = false, FileName = UserfileName, URI = dbPath });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return attachments;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return new List<Models.Attachment>();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
public async Task<List<Attachment>> UpdateAttachments(int responseId, List<AnswerInfo> answers, IEnumerable<Models.Attachment> attachments)
|
||||||
|
{
|
||||||
|
List<Models.Attachment> Dbattachments = new List<Models.Attachment>();
|
||||||
|
foreach (Models.Attachment searchFile in attachments)
|
||||||
|
{
|
||||||
|
Movefile(searchFile.URI);
|
||||||
|
}
|
||||||
|
foreach (var item in answers)
|
||||||
|
{
|
||||||
|
int answerId = item.AnswerId;
|
||||||
|
var pathToSave = Path.Combine(uploadpath, "Response-" + responseId);
|
||||||
|
String fullDirectoryPath = Path.Combine(pathToSave, "Answer-" + answerId);
|
||||||
|
foreach (var file in item.postedFiles)
|
||||||
|
{
|
||||||
|
Models.Attachment attachment = attachments.Where(a => a.Id == file.AttachmentId).FirstOrDefault();
|
||||||
|
var UserfileName = Path.GetFileName(file.FileName);
|
||||||
|
var fileName = String.Format("Attachment_{0}{1}", attachment?.Id, file.FileExtension);
|
||||||
|
byte[] byteArray = Convert.FromBase64String(file.FileContent);
|
||||||
|
MemoryStream stream = new MemoryStream(byteArray);
|
||||||
|
BlobClient client = _containerClient.GetBlobClient(fullDirectoryPath + "/" + fileName);
|
||||||
|
string dbPath = fullDirectoryPath + "/" + fileName;
|
||||||
|
var result = await client.UploadAsync(stream, true);
|
||||||
|
Dbattachments.Add(new Models.Attachment { Id = attachment.Id, AnswerId = answerId, ResponseId = responseId, IsDeleted = false, FileName = UserfileName, URI = dbPath });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Dbattachments;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<List<Azure.Response<BlobContentInfo>>> UploadFiles(List<IFormFile> files)
|
public async Task<List<Azure.Response<BlobContentInfo>>> UploadFiles(List<IFormFile> files)
|
||||||
@ -35,10 +122,52 @@ namespace DamageAssesment.Api.Attachments.Providers
|
|||||||
|
|
||||||
return azureResponse;
|
return azureResponse;
|
||||||
}
|
}
|
||||||
public void DeleteFile(string url)
|
public string getMovefilename(string movefilename)
|
||||||
{
|
{
|
||||||
var blob = _containerClient.GetBlockBlobClient(url);
|
var list = movefilename.Split('.');
|
||||||
blob.DeleteIfExists();
|
if (list.Length > 0)
|
||||||
|
list[list.Length - 1] = DateTime.Now.ToShortDateString().Replace("/", "_") + "_" + DateTime.Now.ToShortTimeString().Replace("/", "_") + "." + list[list.Length - 1];
|
||||||
|
return string.Join("_", list);
|
||||||
|
}
|
||||||
|
public void Movefile(string path)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (path != "")
|
||||||
|
{
|
||||||
|
string MovePath = getMovefilename(path.Replace(uploadpath, Deletepath));
|
||||||
|
// Get references to the source and destination blobs
|
||||||
|
BlobClient sourceBlobClient = _containerClient.GetBlobClient(path);
|
||||||
|
BlobClient destinationBlobClient = _containerClient.GetBlobClient(MovePath);
|
||||||
|
// Start the copy operation from the source to the destination
|
||||||
|
destinationBlobClient.StartCopyFromUri(sourceBlobClient.Uri);
|
||||||
|
|
||||||
|
// Check if the copy operation completed successfully
|
||||||
|
WaitForCopyToComplete(destinationBlobClient);
|
||||||
|
|
||||||
|
// Delete the source blob after a successful copy
|
||||||
|
sourceBlobClient.DeleteIfExists();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
static void WaitForCopyToComplete(BlobClient blobClient)
|
||||||
|
{
|
||||||
|
BlobProperties properties = blobClient.GetProperties();
|
||||||
|
|
||||||
|
while (properties.CopyStatus == CopyStatus.Pending)
|
||||||
|
{
|
||||||
|
Task.Delay(TimeSpan.FromSeconds(1));
|
||||||
|
properties = blobClient.GetProperties();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void Deletefile(string url)
|
||||||
|
{
|
||||||
|
BlobClient sourceBlobClient = _containerClient.GetBlobClient(url);
|
||||||
|
sourceBlobClient.DeleteIfExists();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,8 +0,0 @@
|
|||||||
{
|
|
||||||
"Logging": {
|
|
||||||
"LogLevel": {
|
|
||||||
"Default": "Information",
|
|
||||||
"Microsoft.AspNetCore": "Warning"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -11,6 +11,14 @@
|
|||||||
"AllowedHosts": "*",
|
"AllowedHosts": "*",
|
||||||
"Fileupload": {
|
"Fileupload": {
|
||||||
"folderpath": "DMS_Attachments/Active",
|
"folderpath": "DMS_Attachments/Active",
|
||||||
"Deletepath": "DMS_Attachments/Deleted"
|
"Deletepath": "DMS_Attachments/Deleted",
|
||||||
|
"BlobConnectionString": "DefaultEndpointsProtocol=https;AccountName=damagedoculink;AccountKey=blynpwrAQtthEneXC5f4vFewJ3tPV+QZUt1AX3nefZScPPjkr5hMoC18B9ni6/ZYdhRiERPQw+hB+AStonf+iw==;EndpointSuffix=core.windows.net",
|
||||||
|
"BlobContainerName": "doculinks"
|
||||||
|
},
|
||||||
|
"ConnectionStrings": {
|
||||||
|
//"AttachmentConnection": "Server=DESKTOP-OF5DPLQ\\SQLEXPRESS;Database=da_survey_dev;Trusted_Connection=True;TrustServerCertificate=True;"
|
||||||
|
"AttachmentConnection": "Server=207.180.248.35;Database=da_survey_dev;User Id=sa;Password=YourStrongPassw0rd;TrustServerCertificate=True;"
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -44,10 +44,10 @@ namespace DamageAssesment.Api.DocuLinks.Test
|
|||||||
var mockDocumentService = new Mock<IDoculinkProvider>();
|
var mockDocumentService = new Mock<IDoculinkProvider>();
|
||||||
var mockUploadService = new Mock<IUploadService>();
|
var mockUploadService = new Mock<IUploadService>();
|
||||||
var mockResponse = await MockData.getOkResponses();
|
var mockResponse = await MockData.getOkResponses();
|
||||||
mockDocumentService.Setup(service => service.GetdocumentsByLinkAsync("forms","en", null)).ReturnsAsync(mockResponse);
|
mockDocumentService.Setup(service => service.GetdocumentsByLinkAsync("forms", "en", null)).ReturnsAsync(mockResponse);
|
||||||
|
|
||||||
var DocumentProvider = new DoculinkController(mockDocumentService.Object, mockUploadService.Object);
|
var DocumentProvider = new DoculinkController(mockDocumentService.Object, mockUploadService.Object);
|
||||||
var result = (OkObjectResult)await DocumentProvider.GetDocumentsAsync("forms","en", null);
|
var result = (OkObjectResult)await DocumentProvider.GetDocumentsAsync("forms", "en", null);
|
||||||
|
|
||||||
Assert.Equal(200, result.StatusCode);
|
Assert.Equal(200, result.StatusCode);
|
||||||
}
|
}
|
||||||
@ -97,7 +97,7 @@ namespace DamageAssesment.Api.DocuLinks.Test
|
|||||||
var mockDocumentService = new Mock<IDoculinkProvider>();
|
var mockDocumentService = new Mock<IDoculinkProvider>();
|
||||||
var mockUploadService = new Mock<IUploadService>();
|
var mockUploadService = new Mock<IUploadService>();
|
||||||
var mockResponse = await MockData.getOkResponse(1);
|
var mockResponse = await MockData.getOkResponse(1);
|
||||||
mockDocumentService.Setup(service => service.GetDocumentAsync(1,"forms","en")).ReturnsAsync(mockResponse);
|
mockDocumentService.Setup(service => service.GetDocumentAsync(1, "forms", "en")).ReturnsAsync(mockResponse);
|
||||||
|
|
||||||
var DocumentProvider = new DoculinkController(mockDocumentService.Object, mockUploadService.Object);
|
var DocumentProvider = new DoculinkController(mockDocumentService.Object, mockUploadService.Object);
|
||||||
var result = (OkObjectResult)await DocumentProvider.GetDocumentAsync(1, "forms", "en");
|
var result = (OkObjectResult)await DocumentProvider.GetDocumentAsync(1, "forms", "en");
|
||||||
@ -154,9 +154,9 @@ namespace DamageAssesment.Api.DocuLinks.Test
|
|||||||
var mockResponse = await MockData.getOkResponse(1);
|
var mockResponse = await MockData.getOkResponse(1);
|
||||||
var mockInputDocument = await MockData.getInputDocumentData();
|
var mockInputDocument = await MockData.getInputDocumentData();
|
||||||
var DocumentResponse = await MockData.GetDocuLinksInfo(1);
|
var DocumentResponse = await MockData.GetDocuLinksInfo(1);
|
||||||
mockDocumentService.Setup(service => service.UpdateDocumentAsync(1,mockInputDocument)).ReturnsAsync(mockResponse);
|
mockDocumentService.Setup(service => service.UpdateDocumentAsync(1, mockInputDocument)).ReturnsAsync(mockResponse);
|
||||||
var DocumentProvider = new DoculinkController(mockDocumentService.Object, mockUploadService.Object);
|
var DocumentProvider = new DoculinkController(mockDocumentService.Object, mockUploadService.Object);
|
||||||
var result = (NotFoundResult)await DocumentProvider.UpdateDocument(1,DocumentResponse);
|
var result = (NotFoundResult)await DocumentProvider.UpdateDocument(1, DocumentResponse);
|
||||||
|
|
||||||
Assert.Equal(404, result.StatusCode);
|
Assert.Equal(404, result.StatusCode);
|
||||||
}
|
}
|
||||||
@ -168,9 +168,9 @@ namespace DamageAssesment.Api.DocuLinks.Test
|
|||||||
var mockUploadService = new Mock<IUploadService>();
|
var mockUploadService = new Mock<IUploadService>();
|
||||||
var mockResponse = await MockData.getBadRequestResponse();
|
var mockResponse = await MockData.getBadRequestResponse();
|
||||||
var mockInputDocument = await MockData.getInputDocumentData();
|
var mockInputDocument = await MockData.getInputDocumentData();
|
||||||
mockDocumentService.Setup(service => service.UpdateDocumentAsync(99,mockInputDocument)).ReturnsAsync(mockResponse);
|
mockDocumentService.Setup(service => service.UpdateDocumentAsync(99, mockInputDocument)).ReturnsAsync(mockResponse);
|
||||||
var DocumentProvider = new DoculinkController(mockDocumentService.Object, mockUploadService.Object);
|
var DocumentProvider = new DoculinkController(mockDocumentService.Object, mockUploadService.Object);
|
||||||
var result = (BadRequestObjectResult)await DocumentProvider.UpdateDocument(99,null);
|
var result = (BadRequestObjectResult)await DocumentProvider.UpdateDocument(99, null);
|
||||||
Assert.Equal(400, result.StatusCode);
|
Assert.Equal(400, result.StatusCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -257,7 +257,7 @@ namespace DamageAssesment.Api.DocuLinks.Test
|
|||||||
var mockDocumentService = new Mock<IDoculinkProvider>();
|
var mockDocumentService = new Mock<IDoculinkProvider>();
|
||||||
var mockUploadService = new Mock<IUploadService>();
|
var mockUploadService = new Mock<IUploadService>();
|
||||||
var mockResponse = await LinkTypeMockData.getOkResponse(1);
|
var mockResponse = await LinkTypeMockData.getOkResponse(1);
|
||||||
mockDocumentService.Setup(service => service.GetLinkTypeAsync(1,"en")).ReturnsAsync(mockResponse);
|
mockDocumentService.Setup(service => service.GetLinkTypeAsync(1, "en")).ReturnsAsync(mockResponse);
|
||||||
var DocumentProvider = new DoculinkController(mockDocumentService.Object, mockUploadService.Object);
|
var DocumentProvider = new DoculinkController(mockDocumentService.Object, mockUploadService.Object);
|
||||||
var result = (OkObjectResult)await DocumentProvider.GetLinkTypeAsync(1, "en");
|
var result = (OkObjectResult)await DocumentProvider.GetLinkTypeAsync(1, "en");
|
||||||
|
|
||||||
@ -312,9 +312,9 @@ namespace DamageAssesment.Api.DocuLinks.Test
|
|||||||
var mockUploadService = new Mock<IUploadService>();
|
var mockUploadService = new Mock<IUploadService>();
|
||||||
var mockResponse = await LinkTypeMockData.getOkResponse(1);
|
var mockResponse = await LinkTypeMockData.getOkResponse(1);
|
||||||
var mockInputDocument = await LinkTypeMockData.getInputLinkData(1);
|
var mockInputDocument = await LinkTypeMockData.getInputLinkData(1);
|
||||||
mockDocumentService.Setup(service => service.UpdateLinkTypeAsync(1,mockInputDocument)).ReturnsAsync(mockResponse);
|
mockDocumentService.Setup(service => service.UpdateLinkTypeAsync(1, mockInputDocument)).ReturnsAsync(mockResponse);
|
||||||
var DocumentProvider = new DoculinkController(mockDocumentService.Object, mockUploadService.Object);
|
var DocumentProvider = new DoculinkController(mockDocumentService.Object, mockUploadService.Object);
|
||||||
var result = (OkObjectResult)await DocumentProvider.UpdateLinkType(1,mockInputDocument);
|
var result = (OkObjectResult)await DocumentProvider.UpdateLinkType(1, mockInputDocument);
|
||||||
|
|
||||||
Assert.Equal(200, result.StatusCode);
|
Assert.Equal(200, result.StatusCode);
|
||||||
}
|
}
|
||||||
@ -326,9 +326,9 @@ namespace DamageAssesment.Api.DocuLinks.Test
|
|||||||
var mockUploadService = new Mock<IUploadService>();
|
var mockUploadService = new Mock<IUploadService>();
|
||||||
var mockResponse = await LinkTypeMockData.getNotFoundResponse();
|
var mockResponse = await LinkTypeMockData.getNotFoundResponse();
|
||||||
var mockInputDocument = await LinkTypeMockData.getInputLinkData(99);
|
var mockInputDocument = await LinkTypeMockData.getInputLinkData(99);
|
||||||
mockDocumentService.Setup(service => service.UpdateLinkTypeAsync(99,mockInputDocument)).ReturnsAsync(mockResponse);
|
mockDocumentService.Setup(service => service.UpdateLinkTypeAsync(99, mockInputDocument)).ReturnsAsync(mockResponse);
|
||||||
var DocumentProvider = new DoculinkController(mockDocumentService.Object, mockUploadService.Object);
|
var DocumentProvider = new DoculinkController(mockDocumentService.Object, mockUploadService.Object);
|
||||||
var result = (NotFoundObjectResult)await DocumentProvider.UpdateLinkType(99,mockInputDocument);
|
var result = (NotFoundObjectResult)await DocumentProvider.UpdateLinkType(99, mockInputDocument);
|
||||||
|
|
||||||
Assert.Equal(404, result.StatusCode);
|
Assert.Equal(404, result.StatusCode);
|
||||||
}
|
}
|
||||||
@ -340,7 +340,7 @@ namespace DamageAssesment.Api.DocuLinks.Test
|
|||||||
var mockUploadService = new Mock<IUploadService>();
|
var mockUploadService = new Mock<IUploadService>();
|
||||||
var mockResponse = await LinkTypeMockData.getBadRequestResponse();
|
var mockResponse = await LinkTypeMockData.getBadRequestResponse();
|
||||||
var mockInputDocument = await LinkTypeMockData.getInputLinkData(1);
|
var mockInputDocument = await LinkTypeMockData.getInputLinkData(1);
|
||||||
mockDocumentService.Setup(service => service.UpdateLinkTypeAsync(1,mockInputDocument)).ReturnsAsync(mockResponse);
|
mockDocumentService.Setup(service => service.UpdateLinkTypeAsync(1, mockInputDocument)).ReturnsAsync(mockResponse);
|
||||||
var DocumentProvider = new DoculinkController(mockDocumentService.Object, mockUploadService.Object);
|
var DocumentProvider = new DoculinkController(mockDocumentService.Object, mockUploadService.Object);
|
||||||
var result = (BadRequestObjectResult)await DocumentProvider.UpdateLinkType(1, mockInputDocument);
|
var result = (BadRequestObjectResult)await DocumentProvider.UpdateLinkType(1, mockInputDocument);
|
||||||
|
|
||||||
|
@ -14,19 +14,19 @@ namespace DamageAssesment.Api.DocuLinks.Test
|
|||||||
public static async Task<(bool, List<DocuLinks.Models.ResDoculink>, string)> getOkResponses()
|
public static async Task<(bool, List<DocuLinks.Models.ResDoculink>, string)> getOkResponses()
|
||||||
{
|
{
|
||||||
List<DocuLinks.Models.ResDoculink> list = new List<DocuLinks.Models.ResDoculink>();
|
List<DocuLinks.Models.ResDoculink> list = new List<DocuLinks.Models.ResDoculink>();
|
||||||
|
|
||||||
for (int i = 1; i < 4; i++)
|
for (int i = 1; i < 4; i++)
|
||||||
{
|
{
|
||||||
Dictionary<string, string> dicttitle = new Dictionary<string, string>();
|
Dictionary<string, string> dicttitle = new Dictionary<string, string>();
|
||||||
Dictionary<string, string> dictdesc = new Dictionary<string, string>();
|
Dictionary<string, string> dictdesc = new Dictionary<string, string>();
|
||||||
dicttitle.Add("en", "test"); dicttitle.Add("fr", "tester");
|
dicttitle.Add("en", "test"); dicttitle.Add("fr", "tester");
|
||||||
dictdesc.Add("en", "test"); dictdesc.Add("fr", "tester");
|
dictdesc.Add("en", "test"); dictdesc.Add("fr", "tester");
|
||||||
List<DoculinkTranslation> DocuLinksTranslations = new List<DoculinkTranslation>();
|
List<DoculinkTranslation> DocuLinksTranslations = new List<DoculinkTranslation>();
|
||||||
DocuLinksTranslations.Add(new DoculinkTranslation()
|
DocuLinksTranslations.Add(new DoculinkTranslation()
|
||||||
{
|
{
|
||||||
Language = "en",
|
Language = "en",
|
||||||
title = "tel"+i,
|
title = "tel" + i,
|
||||||
description = "Sample"+i
|
description = "Sample" + i
|
||||||
});
|
});
|
||||||
List<DoculinkAttachments> doclinksAttachments = new List<DoculinkAttachments>();
|
List<DoculinkAttachments> doclinksAttachments = new List<DoculinkAttachments>();
|
||||||
doclinksAttachments.Add(new DoculinkAttachments()
|
doclinksAttachments.Add(new DoculinkAttachments()
|
||||||
@ -41,10 +41,10 @@ namespace DamageAssesment.Api.DocuLinks.Test
|
|||||||
Id = i,
|
Id = i,
|
||||||
linkTypeId = i,
|
linkTypeId = i,
|
||||||
IsActive = true,
|
IsActive = true,
|
||||||
titles= dicttitle,
|
titles = dicttitle,
|
||||||
description=dictdesc,
|
description = dictdesc,
|
||||||
CustomOrder=i,
|
CustomOrder = i,
|
||||||
doclinksAttachments= doclinksAttachments
|
doclinksAttachments = doclinksAttachments
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// List<ResDoculinks> doculinks = list.GroupBy(a => a.linkTypeId).Select(a => new ResDoculinks() { linkTypeId = a.Key, doculinks = a.ToList() }).ToList();
|
// List<ResDoculinks> doculinks = list.GroupBy(a => a.linkTypeId).Select(a => new ResDoculinks() { linkTypeId = a.Key, doculinks = a.ToList() }).ToList();
|
||||||
@ -122,8 +122,8 @@ namespace DamageAssesment.Api.DocuLinks.Test
|
|||||||
{
|
{
|
||||||
|
|
||||||
List<FileModel> fileModels = new List<FileModel>();
|
List<FileModel> fileModels = new List<FileModel>();
|
||||||
fileModels.Add( new FileModel() { FileName = "Sample", FileContent = "c2FtcGxl", FileExtension = ".txt",IsAttachments=true,CustomOrder=1 });
|
fileModels.Add(new FileModel() { FileName = "Sample", FileContent = "c2FtcGxl", FileExtension = ".txt", IsAttachments = true, CustomOrder = 1 });
|
||||||
return new ReqDoculink() { Id=id, linkTypeId = 1, CustomOrder = 1, Files = fileModels };
|
return new ReqDoculink() { Id = id, linkTypeId = 1, CustomOrder = 1, Files = fileModels };
|
||||||
}
|
}
|
||||||
public static async Task<DocuLinks.Models.Doculink> getInputDocumentData()
|
public static async Task<DocuLinks.Models.Doculink> getInputDocumentData()
|
||||||
{
|
{
|
||||||
@ -133,7 +133,7 @@ namespace DamageAssesment.Api.DocuLinks.Test
|
|||||||
Language = "en",
|
Language = "en",
|
||||||
title = "tel",
|
title = "tel",
|
||||||
description = "Sample"
|
description = "Sample"
|
||||||
});
|
});
|
||||||
List<DoculinkAttachments> doclinksAttachments = new List<DoculinkAttachments>();
|
List<DoculinkAttachments> doclinksAttachments = new List<DoculinkAttachments>();
|
||||||
doclinksAttachments.Add(new DoculinkAttachments()
|
doclinksAttachments.Add(new DoculinkAttachments()
|
||||||
{
|
{
|
||||||
@ -148,9 +148,9 @@ namespace DamageAssesment.Api.DocuLinks.Test
|
|||||||
Id = 1,
|
Id = 1,
|
||||||
linkTypeId = 1,
|
linkTypeId = 1,
|
||||||
IsActive = true,
|
IsActive = true,
|
||||||
CustomOrder=1,
|
CustomOrder = 1,
|
||||||
documentsTranslations = DocuLinksTranslations,
|
documentsTranslations = DocuLinksTranslations,
|
||||||
doclinksAttachments= doclinksAttachments
|
doclinksAttachments = doclinksAttachments
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
public static async Task<List<DocuLinks.Models.Doculink>> getInputDocuLinksData()
|
public static async Task<List<DocuLinks.Models.Doculink>> getInputDocuLinksData()
|
||||||
|
@ -5,7 +5,6 @@ using DamageAssesment.Api.DocuLinks.Providers;
|
|||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using System.Data;
|
|
||||||
|
|
||||||
namespace DamageAssesment.Api.DocuLinks.Controllers
|
namespace DamageAssesment.Api.DocuLinks.Controllers
|
||||||
{
|
{
|
||||||
@ -14,6 +13,7 @@ namespace DamageAssesment.Api.DocuLinks.Controllers
|
|||||||
{
|
{
|
||||||
private readonly IDoculinkProvider documentsProvider;
|
private readonly IDoculinkProvider documentsProvider;
|
||||||
private readonly IUploadService uploadService;
|
private readonly IUploadService uploadService;
|
||||||
|
private readonly IAzureBlobService azureBlobService;
|
||||||
|
|
||||||
public DoculinkController(IDoculinkProvider documentsProvider, IUploadService uploadService)
|
public DoculinkController(IDoculinkProvider documentsProvider, IUploadService uploadService)
|
||||||
{
|
{
|
||||||
@ -42,10 +42,10 @@ namespace DamageAssesment.Api.DocuLinks.Controllers
|
|||||||
/// Get a Doculink type by id.
|
/// Get a Doculink type by id.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Authorize(Roles = "admin")]
|
[Authorize(Roles = "admin")]
|
||||||
|
[HttpGet]
|
||||||
[Route("doculinks/types/{id}")]
|
[Route("doculinks/types/{id}")]
|
||||||
[Route("doculinks/types/{id}/{language:alpha}")]
|
[Route("doculinks/types/{id}/{language:alpha}")]
|
||||||
[HttpGet]
|
public async Task<IActionResult> GetLinkTypeAsync(int id, string? language)
|
||||||
public async Task<IActionResult> GetLinkTypeAsync(int id,string? language)
|
|
||||||
{
|
{
|
||||||
var result = await this.documentsProvider.GetLinkTypeAsync(id, language);
|
var result = await this.documentsProvider.GetLinkTypeAsync(id, language);
|
||||||
if (result.IsSuccess)
|
if (result.IsSuccess)
|
||||||
@ -206,7 +206,6 @@ namespace DamageAssesment.Api.DocuLinks.Controllers
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get all active Doculink.
|
/// Get all active Doculink.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Authorize(Roles = "admin")]
|
|
||||||
[Route("doculinks/active")]
|
[Route("doculinks/active")]
|
||||||
[Route("doculinks/active/{linktype:alpha}")]
|
[Route("doculinks/active/{linktype:alpha}")]
|
||||||
[Route("doculinks/active/{linktype:alpha}/{language:alpha}")]
|
[Route("doculinks/active/{linktype:alpha}/{language:alpha}")]
|
||||||
@ -223,7 +222,6 @@ namespace DamageAssesment.Api.DocuLinks.Controllers
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get all active Doculink.
|
/// Get all active Doculink.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Authorize(Roles = "admin")]
|
|
||||||
[Route("doculinks/active/{linktypeid:int}")]
|
[Route("doculinks/active/{linktypeid:int}")]
|
||||||
[Route("doculinks/active/{linktypeid:int}/{language:alpha}")]
|
[Route("doculinks/active/{linktypeid:int}/{language:alpha}")]
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
@ -254,7 +252,7 @@ namespace DamageAssesment.Api.DocuLinks.Controllers
|
|||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Upload new document.
|
/// update existing doclink.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Authorize(Roles = "admin")]
|
[Authorize(Roles = "admin")]
|
||||||
[HttpPut]
|
[HttpPut]
|
||||||
@ -296,7 +294,7 @@ namespace DamageAssesment.Api.DocuLinks.Controllers
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create new doclink.
|
/// Create new doclink.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Authorize(Roles = "admin")]
|
// [Authorize(Roles = "admin")]
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
[Route("doculinks")]
|
[Route("doculinks")]
|
||||||
public async Task<IActionResult> CreateDocument(ReqDoculink documentInfo)
|
public async Task<IActionResult> CreateDocument(ReqDoculink documentInfo)
|
||||||
@ -322,7 +320,7 @@ namespace DamageAssesment.Api.DocuLinks.Controllers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Delete document by id.
|
/// Delete Doculink by id.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Authorize(Roles = "admin")]
|
[Authorize(Roles = "admin")]
|
||||||
[HttpDelete]
|
[HttpDelete]
|
||||||
|
@ -1 +0,0 @@
|
|||||||
sample
|
|
@ -1 +0,0 @@
|
|||||||
sample
|
|
@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1" />
|
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1" />
|
||||||
<PackageReference Include="Azure.Storage.Blobs" Version="12.16.0" />
|
<PackageReference Include="Azure.Storage.Blobs" Version="12.18.0" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.21" />
|
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.21" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Hosting" Version="2.2.7" />
|
<PackageReference Include="Microsoft.AspNetCore.Hosting" Version="2.2.7" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.9" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.9" />
|
||||||
@ -25,7 +25,10 @@
|
|||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
|
||||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.4" />
|
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.4" />
|
||||||
|
<PackageReference Include="Serilog.Extensions.Logging.File" Version="3.0.0" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ using System.ComponentModel.DataAnnotations.Schema;
|
|||||||
|
|
||||||
namespace DamageAssesment.Api.DocuLinks.Db
|
namespace DamageAssesment.Api.DocuLinks.Db
|
||||||
{
|
{
|
||||||
|
[Table("Doculinks")]
|
||||||
public class Doculink
|
public class Doculink
|
||||||
{
|
{
|
||||||
[Key]
|
[Key]
|
||||||
|
@ -3,6 +3,7 @@ using System.ComponentModel.DataAnnotations;
|
|||||||
|
|
||||||
namespace DamageAssesment.Api.DocuLinks.Db
|
namespace DamageAssesment.Api.DocuLinks.Db
|
||||||
{
|
{
|
||||||
|
[Table("DoculinkAttachments")]
|
||||||
public class DoculinkAttachments
|
public class DoculinkAttachments
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -7,8 +7,15 @@ namespace DamageAssesment.Api.DocuLinks.Db
|
|||||||
{
|
{
|
||||||
public class DoculinkDbContext : DbContext
|
public class DoculinkDbContext : DbContext
|
||||||
{
|
{
|
||||||
public DoculinkDbContext(DbContextOptions options) : base(options)
|
private IConfiguration _Configuration { get; set; }
|
||||||
|
public DoculinkDbContext(DbContextOptions options, IConfiguration configuration) : base(options)
|
||||||
{
|
{
|
||||||
|
_Configuration = configuration;
|
||||||
|
}
|
||||||
|
protected override void OnConfiguring(DbContextOptionsBuilder options)
|
||||||
|
{
|
||||||
|
// connect to sql server with connection string from app settings
|
||||||
|
options.UseSqlServer(_Configuration.GetConnectionString("DoculinkConnection"));
|
||||||
}
|
}
|
||||||
public DbSet<Db.Doculink> Documents { get; set; }
|
public DbSet<Db.Doculink> Documents { get; set; }
|
||||||
public DbSet<Db.LinkType> LinkTypes { get; set; }
|
public DbSet<Db.LinkType> LinkTypes { get; set; }
|
||||||
|
@ -3,6 +3,7 @@ using System.ComponentModel.DataAnnotations.Schema;
|
|||||||
|
|
||||||
namespace DamageAssesment.Api.DocuLinks.Db
|
namespace DamageAssesment.Api.DocuLinks.Db
|
||||||
{
|
{
|
||||||
|
[Table("DoculinkTrans")]
|
||||||
public class DoculinkTranslation
|
public class DoculinkTranslation
|
||||||
{
|
{
|
||||||
[Key]
|
[Key]
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
|
||||||
namespace DamageAssesment.Api.DocuLinks.Db
|
namespace DamageAssesment.Api.DocuLinks.Db
|
||||||
{
|
{
|
||||||
|
[Table("DoculinkTypes")]
|
||||||
public class LinkType
|
public class LinkType
|
||||||
{
|
{
|
||||||
[Key]
|
[Key]
|
||||||
|
@ -3,6 +3,7 @@ using System.ComponentModel.DataAnnotations;
|
|||||||
|
|
||||||
namespace DamageAssesment.Api.DocuLinks.Db
|
namespace DamageAssesment.Api.DocuLinks.Db
|
||||||
{
|
{
|
||||||
|
[Table("DoculinkTypeTrans")]
|
||||||
public class LinksTranslation
|
public class LinksTranslation
|
||||||
{
|
{
|
||||||
[Key]
|
[Key]
|
||||||
|
@ -1,10 +1,14 @@
|
|||||||
using Azure.Storage.Blobs.Models;
|
using Azure.Storage.Blobs.Models;
|
||||||
|
using DamageAssesment.Api.DocuLinks.Models;
|
||||||
|
|
||||||
namespace DamageAssesment.Api.DocuLinks.Interfaces
|
namespace DamageAssesment.Api.DocuLinks.Interfaces
|
||||||
{
|
{
|
||||||
public interface IAzureBlobService
|
public interface IAzureBlobService
|
||||||
{
|
{
|
||||||
Task<List<Azure.Response<BlobContentInfo>>> UploadFiles(List<IFormFile> files);
|
Task<List<Azure.Response<BlobContentInfo>>> UploadFiles(List<IFormFile> files);
|
||||||
|
Task<Models.Doculink> UploadDocument(int counter, ReqDoculink documentInfo);
|
||||||
|
Task<Models.Doculink> UpdateDocuments(int counter, Models.Doculink document, ReqDoculink documentInfo);
|
||||||
void DeleteFile(string path);
|
void DeleteFile(string path);
|
||||||
|
void Movefile(string path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,9 +9,16 @@ using System.Text;
|
|||||||
using Microsoft.OpenApi.Models;
|
using Microsoft.OpenApi.Models;
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
builder.Services.AddCors(p => p.AddPolicy("DamageAppCorsPolicy", build => {
|
||||||
|
build.WithOrigins("*").AllowAnyMethod().AllowAnyHeader().AllowAnyOrigin();
|
||||||
|
}));
|
||||||
// Add services to the container.
|
// Add services to the container.
|
||||||
var authkey = builder.Configuration.GetValue<string>("JwtSettings:securitykey");
|
var authkey = builder.Configuration.GetValue<string>("JwtSettings:securitykey");
|
||||||
|
builder.Services.AddLogging(builder =>
|
||||||
|
{
|
||||||
|
//builder.AddConsole(); // Optional: Add other providers if needed
|
||||||
|
builder.AddFile("logs/DocuLinks-{Date}.txt"); // Specify the file path and format
|
||||||
|
});
|
||||||
builder.Services.AddAuthentication(item =>
|
builder.Services.AddAuthentication(item =>
|
||||||
{
|
{
|
||||||
item.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
|
item.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
|
||||||
@ -76,7 +83,7 @@ builder.Services.AddScoped<IAzureBlobService, AzureBlobService>();
|
|||||||
builder.Services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies()); //4/30
|
builder.Services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies()); //4/30
|
||||||
builder.Services.AddDbContext<DoculinkDbContext>(option =>
|
builder.Services.AddDbContext<DoculinkDbContext>(option =>
|
||||||
{
|
{
|
||||||
option.UseInMemoryDatabase("DocumentConnection");
|
option.UseSqlServer("DoculinkConnection");
|
||||||
});
|
});
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
@ -86,7 +93,7 @@ if (app.Environment.IsDevelopment())
|
|||||||
app.UseSwagger();
|
app.UseSwagger();
|
||||||
app.UseSwaggerUI();
|
app.UseSwaggerUI();
|
||||||
}
|
}
|
||||||
|
app.UseCors("DamageAppCorsPolicy");
|
||||||
app.UseAuthentication();
|
app.UseAuthentication();
|
||||||
app.UseAuthorization();
|
app.UseAuthorization();
|
||||||
|
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
"commandName": "Project",
|
"commandName": "Project",
|
||||||
"launchBrowser": true,
|
"launchBrowser": true,
|
||||||
"launchUrl": "swagger",
|
"launchUrl": "swagger",
|
||||||
"applicationUrl": "http://localhost:5133",
|
|
||||||
"environmentVariables": {
|
"environmentVariables": {
|
||||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
},
|
},
|
||||||
|
@ -1,8 +1,17 @@
|
|||||||
|
|
||||||
|
using Azure;
|
||||||
using Azure.Storage.Blobs;
|
using Azure.Storage.Blobs;
|
||||||
using Azure.Storage.Blobs.Models;
|
using Azure.Storage.Blobs.Models;
|
||||||
using Azure.Storage.Blobs.Specialized;
|
using Azure.Storage.Blobs.Specialized;
|
||||||
using DamageAssesment.Api.DocuLinks.Interfaces;
|
using DamageAssesment.Api.DocuLinks.Interfaces;
|
||||||
|
using DamageAssesment.Api.DocuLinks.Models;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Filters;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.VisualBasic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.IO;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace DamageAssesment.Api.DocuLinks.Providers
|
namespace DamageAssesment.Api.DocuLinks.Providers
|
||||||
{
|
{
|
||||||
@ -10,11 +19,111 @@ namespace DamageAssesment.Api.DocuLinks.Providers
|
|||||||
{
|
{
|
||||||
BlobServiceClient _blobClient;
|
BlobServiceClient _blobClient;
|
||||||
BlobContainerClient _containerClient;
|
BlobContainerClient _containerClient;
|
||||||
string azureConnectionString = "<Primary Connection String>";
|
string azureConnectionString;
|
||||||
public AzureBlobService()
|
private string uploadpath = "";
|
||||||
|
private string Deletepath = "";
|
||||||
|
public AzureBlobService(IConfiguration configuration)
|
||||||
{
|
{
|
||||||
_blobClient = new BlobServiceClient(azureConnectionString);
|
uploadpath = configuration.GetValue<string>("Fileupload:folderpath");
|
||||||
_containerClient = _blobClient.GetBlobContainerClient("apiimages");
|
Deletepath = configuration.GetValue<string>("Fileupload:Deletepath");
|
||||||
|
_blobClient = new BlobServiceClient(configuration.GetValue<string>("Fileupload:BlobConnectionString"));
|
||||||
|
_containerClient = _blobClient.GetBlobContainerClient(configuration.GetValue<string>("Fileupload:BlobContainerName"));
|
||||||
|
}
|
||||||
|
public async Task<Models.Doculink> UploadDocument(int counter, ReqDoculink documentInfo)
|
||||||
|
{
|
||||||
|
Models.Doculink Documents = new Models.Doculink();
|
||||||
|
List <Models.DoculinkAttachments> attachments = new List<Models.DoculinkAttachments>();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string path = "", UserfileName = "";
|
||||||
|
if (documentInfo.Files != null)
|
||||||
|
{
|
||||||
|
|
||||||
|
int counter1 = 1;
|
||||||
|
foreach (var item in documentInfo.Files)
|
||||||
|
{
|
||||||
|
if (item.IsAttachments)
|
||||||
|
{
|
||||||
|
UserfileName = Path.GetFileName(item.FileName);
|
||||||
|
var fileName = String.Format("Document_{0}_{1}{2}", counter, counter1, item.FileExtension);
|
||||||
|
byte[] byteArray = Convert.FromBase64String(item.FileContent);
|
||||||
|
MemoryStream stream = new MemoryStream(byteArray);
|
||||||
|
BlobClient client = _containerClient.GetBlobClient(uploadpath + "/" + fileName);
|
||||||
|
var result = await client.UploadAsync(stream, true);
|
||||||
|
path = uploadpath + "/" + fileName;
|
||||||
|
counter1++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
path = item.url;
|
||||||
|
attachments.Add(new Models.DoculinkAttachments { docName = UserfileName, Path = path, IsAttachments = item.IsAttachments, CustomOrder = item.CustomOrder });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Documents = new Models.Doculink()
|
||||||
|
{
|
||||||
|
linkTypeId = documentInfo.linkTypeId,
|
||||||
|
documentsTranslations = documentInfo.documentsTranslations,
|
||||||
|
doclinksAttachments = attachments,
|
||||||
|
IsDeleted = false,
|
||||||
|
CustomOrder = documentInfo.CustomOrder,
|
||||||
|
IsActive = true
|
||||||
|
};
|
||||||
|
|
||||||
|
return Documents;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return new Models.Doculink();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<Models.Doculink> UpdateDocuments(int counter, Models.Doculink document, ReqDoculink documentInfo)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
foreach (var item in document.doclinksAttachments)
|
||||||
|
{
|
||||||
|
Movefile(item.Path);
|
||||||
|
}
|
||||||
|
string path = "", UserfileName = "";
|
||||||
|
List<Models.DoculinkAttachments> attachments = new List<Models.DoculinkAttachments>();
|
||||||
|
int counter1 = 1;
|
||||||
|
foreach (var item in documentInfo.Files)
|
||||||
|
{
|
||||||
|
if (item.IsAttachments)
|
||||||
|
{
|
||||||
|
UserfileName = Path.GetFileName(item.FileName);
|
||||||
|
var fileName = String.Format("Document_{0}_{1}{2)", document.Id, counter1, item.FileExtension);
|
||||||
|
byte[] byteArray = Encoding.UTF8.GetBytes(item.FileContent);
|
||||||
|
MemoryStream stream = new MemoryStream(byteArray);
|
||||||
|
BlobClient client = _containerClient.GetBlobClient(uploadpath + "/" + fileName);
|
||||||
|
path = uploadpath + "/" + fileName;
|
||||||
|
var result = await client.UploadAsync(stream, true);
|
||||||
|
counter1++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
path = item.url;
|
||||||
|
attachments.Add(new Models.DoculinkAttachments { docName = UserfileName, Path = path, IsAttachments = item.IsAttachments, CustomOrder = item.CustomOrder });
|
||||||
|
}
|
||||||
|
Models.Doculink Documents = new Models.Doculink()
|
||||||
|
{
|
||||||
|
Id = documentInfo.Id,
|
||||||
|
linkTypeId = documentInfo.linkTypeId,
|
||||||
|
documentsTranslations = documentInfo.documentsTranslations,
|
||||||
|
IsActive = true,
|
||||||
|
IsDeleted = false,
|
||||||
|
CustomOrder = documentInfo.CustomOrder,
|
||||||
|
doclinksAttachments = attachments
|
||||||
|
};
|
||||||
|
|
||||||
|
return Documents;
|
||||||
|
}
|
||||||
|
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return new Models.Doculink();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<List<Azure.Response<BlobContentInfo>>> UploadFiles(List<IFormFile> files)
|
public async Task<List<Azure.Response<BlobContentInfo>>> UploadFiles(List<IFormFile> files)
|
||||||
@ -35,10 +144,52 @@ namespace DamageAssesment.Api.DocuLinks.Providers
|
|||||||
|
|
||||||
return azureResponse;
|
return azureResponse;
|
||||||
}
|
}
|
||||||
|
public string getMovefilename(string movefilename)
|
||||||
|
{
|
||||||
|
var list = movefilename.Split('.');
|
||||||
|
if (list.Length > 0)
|
||||||
|
list[list.Length - 1] = DateTime.Now.ToShortDateString().Replace("/", "_") +"_"+ DateTime.Now.ToShortTimeString().Replace("/", "_")+"." + list[list.Length - 1];
|
||||||
|
return string.Join("_", list);
|
||||||
|
}
|
||||||
|
public void Movefile(string path)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (path != "")
|
||||||
|
{
|
||||||
|
string MovePath = getMovefilename(path.Replace(uploadpath, Deletepath));
|
||||||
|
// Get references to the source and destination blobs
|
||||||
|
BlobClient sourceBlobClient = _containerClient.GetBlobClient(path);
|
||||||
|
BlobClient destinationBlobClient = _containerClient.GetBlobClient(MovePath);
|
||||||
|
// Start the copy operation from the source to the destination
|
||||||
|
destinationBlobClient.StartCopyFromUri(sourceBlobClient.Uri);
|
||||||
|
|
||||||
|
// Check if the copy operation completed successfully
|
||||||
|
WaitForCopyToComplete(destinationBlobClient);
|
||||||
|
|
||||||
|
// Delete the source blob after a successful copy
|
||||||
|
sourceBlobClient.DeleteIfExists();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(Exception ex)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
static void WaitForCopyToComplete(BlobClient blobClient)
|
||||||
|
{
|
||||||
|
BlobProperties properties = blobClient.GetProperties();
|
||||||
|
|
||||||
|
while (properties.CopyStatus == CopyStatus.Pending)
|
||||||
|
{
|
||||||
|
Task.Delay(TimeSpan.FromSeconds(1));
|
||||||
|
properties = blobClient.GetProperties();
|
||||||
|
}
|
||||||
|
}
|
||||||
public void DeleteFile(string url)
|
public void DeleteFile(string url)
|
||||||
{
|
{
|
||||||
var blob = _containerClient.GetBlockBlobClient(url);
|
BlobClient sourceBlobClient = _containerClient.GetBlobClient(url);
|
||||||
blob.DeleteIfExists();
|
sourceBlobClient.DeleteIfExists();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -24,11 +24,12 @@ namespace DamageAssesment.Api.DocuLinks.Providers
|
|||||||
private DoculinkDbContext DocumentDbContext;
|
private DoculinkDbContext DocumentDbContext;
|
||||||
private ILogger<DoculinkProvider> logger;
|
private ILogger<DoculinkProvider> logger;
|
||||||
private IUploadService uploadservice;
|
private IUploadService uploadservice;
|
||||||
|
private IAzureBlobService azureBlobService;
|
||||||
private IMapper mapper;
|
private IMapper mapper;
|
||||||
private readonly IHttpContextAccessor httpContextAccessor;
|
private readonly IHttpContextAccessor httpContextAccessor;
|
||||||
private string baseUrl;
|
private string baseUrl;
|
||||||
|
|
||||||
public DoculinkProvider(DoculinkDbContext DocumentDbContext, ILogger<DoculinkProvider> logger, IMapper mapper, IUploadService uploadservice, IHttpContextAccessor httpContextAccessor)
|
public DoculinkProvider(DoculinkDbContext DocumentDbContext, ILogger<DoculinkProvider> logger, IMapper mapper, IUploadService uploadservice, IAzureBlobService azureBlobService, IHttpContextAccessor httpContextAccessor)
|
||||||
{
|
{
|
||||||
this.DocumentDbContext = DocumentDbContext;
|
this.DocumentDbContext = DocumentDbContext;
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
@ -37,12 +38,13 @@ namespace DamageAssesment.Api.DocuLinks.Providers
|
|||||||
this.httpContextAccessor = httpContextAccessor;
|
this.httpContextAccessor = httpContextAccessor;
|
||||||
baseUrl = $"{httpContextAccessor.HttpContext.Request.Scheme}://{httpContextAccessor.HttpContext.Request.Host}";
|
baseUrl = $"{httpContextAccessor.HttpContext.Request.Scheme}://{httpContextAccessor.HttpContext.Request.Host}";
|
||||||
baseUrl = baseUrl + "/doculinks/download";
|
baseUrl = baseUrl + "/doculinks/download";
|
||||||
SeedData();
|
this.azureBlobService = azureBlobService;
|
||||||
|
//SeedData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void SeedData()
|
private async Task SeedDataAsync()
|
||||||
{
|
{
|
||||||
if (!DocumentDbContext.LinkTypes.Any())
|
if (!DocumentDbContext.LinkTypes.Any())
|
||||||
{
|
{
|
||||||
|
@ -116,15 +116,16 @@ namespace DamageAssesment.Api.DocuLinks.Providers
|
|||||||
|
|
||||||
string path = "", UserfileName = "";
|
string path = "", UserfileName = "";
|
||||||
List<Models.DoculinkAttachments> attachments = new List<Models.DoculinkAttachments>();
|
List<Models.DoculinkAttachments> attachments = new List<Models.DoculinkAttachments>();
|
||||||
|
int counter1 = 1;
|
||||||
foreach (var item in documentInfo.Files)
|
foreach (var item in documentInfo.Files)
|
||||||
{
|
{
|
||||||
counter++;
|
|
||||||
if (item.IsAttachments)
|
if (item.IsAttachments)
|
||||||
{
|
{
|
||||||
UserfileName = Path.GetFileName(item.FileName+item.FileExtension);
|
UserfileName = Path.GetFileName(item.FileName+item.FileExtension);
|
||||||
var fileName = String.Format("Document_{0}{1}", counter, item.FileExtension);
|
var fileName = String.Format("Document_{0}{1}", counter1, item.FileExtension);
|
||||||
path = Path.Combine(fullDirectoryPath, fileName);
|
path = Path.Combine(fullDirectoryPath, fileName);
|
||||||
File.WriteAllBytes(path, Convert.FromBase64String(item.FileContent));
|
File.WriteAllBytes(path, Convert.FromBase64String(item.FileContent));
|
||||||
|
counter1++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
path = item.url;
|
path = item.url;
|
||||||
|
@ -1,8 +0,0 @@
|
|||||||
{
|
|
||||||
"Logging": {
|
|
||||||
"LogLevel": {
|
|
||||||
"Default": "Information",
|
|
||||||
"Microsoft.AspNetCore": "Warning"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,4 +1,7 @@
|
|||||||
{
|
{
|
||||||
|
"JwtSettings": {
|
||||||
|
"securitykey": "bWlhbWkgZGFkZSBzY2hvb2xzIHNlY3JldCBrZXk="
|
||||||
|
},
|
||||||
"Logging": {
|
"Logging": {
|
||||||
"LogLevel": {
|
"LogLevel": {
|
||||||
"Default": "Information",
|
"Default": "Information",
|
||||||
@ -6,12 +9,15 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"AllowedHosts": "*",
|
"AllowedHosts": "*",
|
||||||
"JwtSettings": {
|
"ConnectionStrings": {
|
||||||
"securitykey": "bWlhbWkgZGFkZSBzY2hvb2xzIHNlY3JldCBrZXk="
|
//"DoculinkConnection": "Server=DESKTOP-OF5DPLQ\\SQLEXPRESS;Database=da_survey_dev;Trusted_Connection=True;TrustServerCertificate=True;"
|
||||||
|
"DoculinkConnection": "Server=207.180.248.35;Database=da_survey_dev;User Id=sa;Password=YourStrongPassw0rd;TrustServerCertificate=True;"
|
||||||
|
|
||||||
},
|
},
|
||||||
"Fileupload": {
|
"Fileupload": {
|
||||||
"folderpath": "DASA_Documents/Active",
|
"folderpath": "DASA_Documents/Active",
|
||||||
"Deletepath": "DASA_Documents/Deleted"
|
"Deletepath": "DASA_Documents/Deleted",
|
||||||
|
"BlobConnectionString": "DefaultEndpointsProtocol=https;AccountName=damagedoculink;AccountKey=blynpwrAQtthEneXC5f4vFewJ3tPV+QZUt1AX3nefZScPPjkr5hMoC18B9ni6/ZYdhRiERPQw+hB+AStonf+iw==;EndpointSuffix=core.windows.net",
|
||||||
|
"BlobContainerName": "doculinks"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,9 +12,22 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1" />
|
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.21" />
|
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.21" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.5" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.9" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.5" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.5" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.9">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.9" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.9" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.9">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
|
||||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.4" />
|
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.4" />
|
||||||
|
<PackageReference Include="Serilog.Extensions.Logging.File" Version="3.0.0" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
|
||||||
namespace DamageAssesment.Api.Employees.Db
|
namespace DamageAssesment.Api.Employees.Db
|
||||||
{
|
{
|
||||||
|
[Table("Employees")]
|
||||||
public class Employee
|
public class Employee
|
||||||
{
|
{
|
||||||
[Key]
|
[Key]
|
||||||
|
@ -4,18 +4,23 @@ namespace DamageAssesment.Api.Employees.Db
|
|||||||
{
|
{
|
||||||
public class EmployeeDbContext: DbContext
|
public class EmployeeDbContext: DbContext
|
||||||
{
|
{
|
||||||
public DbSet<Db.Employee> Employees { get; set; }
|
private IConfiguration _Configuration { get; set; }
|
||||||
public EmployeeDbContext(DbContextOptions options) : base(options)
|
public EmployeeDbContext(DbContextOptions options, IConfiguration configuration) : base(options)
|
||||||
{
|
{
|
||||||
|
_Configuration = configuration;
|
||||||
|
}
|
||||||
|
protected override void OnConfiguring(DbContextOptionsBuilder options)
|
||||||
|
{
|
||||||
|
// connect to sql server with connection string from app settings
|
||||||
|
options.UseSqlServer(_Configuration.GetConnectionString("EmployeeConnection"));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
base.OnModelCreating(modelBuilder);
|
base.OnModelCreating(modelBuilder);
|
||||||
|
|
||||||
modelBuilder.Entity<Employee>()
|
modelBuilder.Entity<Employee>()
|
||||||
.Property(item => item.Id)
|
.Property(item => item.Id)
|
||||||
.ValueGeneratedOnAdd();
|
.ValueGeneratedOnAdd();
|
||||||
}
|
}
|
||||||
|
public DbSet<Db.Employee> Employees { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,9 +9,16 @@ using System.Reflection;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
builder.Services.AddCors(p => p.AddPolicy("DamageAppCorsPolicy", build => {
|
||||||
|
build.WithOrigins("*").AllowAnyMethod().AllowAnyHeader().AllowAnyOrigin();
|
||||||
|
}));
|
||||||
// Add services to the container.
|
// Add services to the container.
|
||||||
var authkey = builder.Configuration.GetValue<string>("JwtSettings:securitykey");
|
var authkey = builder.Configuration.GetValue<string>("JwtSettings:securitykey");
|
||||||
|
builder.Services.AddLogging(builder =>
|
||||||
|
{
|
||||||
|
//builder.AddConsole(); // Optional: Add other providers if needed
|
||||||
|
builder.AddFile("logs/Employees-{Date}.txt"); // Specify the file path and format
|
||||||
|
});
|
||||||
builder.Services.AddAuthentication(item =>
|
builder.Services.AddAuthentication(item =>
|
||||||
{
|
{
|
||||||
item.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
|
item.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
|
||||||
@ -75,7 +82,7 @@ builder.Services.AddScoped<IEmployeesProvider, EmployeesProvider>();
|
|||||||
builder.Services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies()); //4/30
|
builder.Services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies()); //4/30
|
||||||
builder.Services.AddDbContext<EmployeeDbContext>(option =>
|
builder.Services.AddDbContext<EmployeeDbContext>(option =>
|
||||||
{
|
{
|
||||||
option.UseInMemoryDatabase("Employees");
|
option.UseSqlServer("EmployeeConnection");
|
||||||
});
|
});
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
@ -93,7 +100,7 @@ if (app.Environment.IsDevelopment())
|
|||||||
employeesProvider.SeedData();
|
employeesProvider.SeedData();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
app.UseCors("DamageAppCorsPolicy");
|
||||||
app.UseAuthentication();
|
app.UseAuthentication();
|
||||||
app.UseAuthorization();
|
app.UseAuthorization();
|
||||||
|
|
||||||
|
@ -1,8 +0,0 @@
|
|||||||
{
|
|
||||||
"Logging": {
|
|
||||||
"LogLevel": {
|
|
||||||
"Default": "Information",
|
|
||||||
"Microsoft.AspNetCore": "Warning"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -8,5 +8,10 @@
|
|||||||
"Microsoft.AspNetCore": "Warning"
|
"Microsoft.AspNetCore": "Warning"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"AllowedHosts": "*"
|
"AllowedHosts": "*",
|
||||||
|
"ConnectionStrings": {
|
||||||
|
//"EmployeeConnection": "Server=DESKTOP-OF5DPLQ\\SQLEXPRESS;Database=da_survey_dev;Trusted_Connection=True;TrustServerCertificate=True;"
|
||||||
|
"EmployeeConnection": "Server=207.180.248.35;Database=da_survey_dev;User Id=sa;Password=YourStrongPassw0rd;TrustServerCertificate=True;"
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,10 +11,24 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1" />
|
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.9" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.9">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.9" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.9" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.9">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.21" />
|
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.21" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.5" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.5" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.5" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.5" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
|
||||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.4" />
|
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.4" />
|
||||||
|
<PackageReference Include="Serilog.Extensions.Logging.File" Version="3.0.0" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ using System.ComponentModel.DataAnnotations.Schema;
|
|||||||
|
|
||||||
namespace DamageAssesment.Api.Locations.Db
|
namespace DamageAssesment.Api.Locations.Db
|
||||||
{
|
{
|
||||||
|
[Table("Locations")]
|
||||||
public class Location
|
public class Location
|
||||||
{
|
{
|
||||||
[Key]
|
[Key]
|
||||||
|
@ -4,6 +4,16 @@ namespace DamageAssesment.Api.Locations.Db
|
|||||||
{
|
{
|
||||||
public class LocationDbContext : DbContext
|
public class LocationDbContext : DbContext
|
||||||
{
|
{
|
||||||
|
private IConfiguration _Configuration { get; set; }
|
||||||
|
public LocationDbContext(DbContextOptions options, IConfiguration configuration) : base(options)
|
||||||
|
{
|
||||||
|
_Configuration = configuration;
|
||||||
|
}
|
||||||
|
protected override void OnConfiguring(DbContextOptionsBuilder options)
|
||||||
|
{
|
||||||
|
// connect to sql server with connection string from app settings
|
||||||
|
options.UseSqlServer(_Configuration.GetConnectionString("LocationConnection"));
|
||||||
|
}
|
||||||
public DbSet<Db.Location> Locations { get; set; }
|
public DbSet<Db.Location> Locations { get; set; }
|
||||||
public DbSet<Db.Region> Regions { get; set; }
|
public DbSet<Db.Region> Regions { get; set; }
|
||||||
public LocationDbContext(DbContextOptions options) : base(options)
|
public LocationDbContext(DbContextOptions options) : base(options)
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
|
||||||
namespace DamageAssesment.Api.Locations.Db
|
namespace DamageAssesment.Api.Locations.Db
|
||||||
{
|
{
|
||||||
|
[Table("Regions")]
|
||||||
public class Region
|
public class Region
|
||||||
{
|
{
|
||||||
[Key]
|
[Key]
|
||||||
|
@ -9,9 +9,16 @@ using System.Reflection;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
builder.Services.AddCors(p => p.AddPolicy("DamageAppCorsPolicy", build => {
|
||||||
|
build.WithOrigins("*").AllowAnyMethod().AllowAnyHeader().AllowAnyOrigin();
|
||||||
|
}));
|
||||||
// Add services to the container.
|
// Add services to the container.
|
||||||
var authkey = builder.Configuration.GetValue<string>("JwtSettings:securitykey");
|
var authkey = builder.Configuration.GetValue<string>("JwtSettings:securitykey");
|
||||||
|
builder.Services.AddLogging(builder =>
|
||||||
|
{
|
||||||
|
//builder.AddConsole(); // Optional: Add other providers if needed
|
||||||
|
builder.AddFile("logs/Locations-{Date}.txt"); // Specify the file path and format
|
||||||
|
});
|
||||||
builder.Services.AddAuthentication(item =>
|
builder.Services.AddAuthentication(item =>
|
||||||
{
|
{
|
||||||
item.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
|
item.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
|
||||||
@ -74,7 +81,7 @@ builder.Services.AddScoped<IRegionsProvider, RegionsProvider>();
|
|||||||
builder.Services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies()); //4/30
|
builder.Services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies()); //4/30
|
||||||
builder.Services.AddDbContext<LocationDbContext>(option =>
|
builder.Services.AddDbContext<LocationDbContext>(option =>
|
||||||
{
|
{
|
||||||
option.UseInMemoryDatabase("Locations");
|
option.UseSqlServer("LocationConnection");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
@ -96,7 +103,7 @@ if (app.Environment.IsDevelopment())
|
|||||||
regionProvider.SeedData();
|
regionProvider.SeedData();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
app.UseCors("DamageAppCorsPolicy");
|
||||||
app.UseAuthentication();
|
app.UseAuthentication();
|
||||||
app.UseAuthorization();
|
app.UseAuthorization();
|
||||||
|
|
||||||
|
@ -1,8 +0,0 @@
|
|||||||
{
|
|
||||||
"Logging": {
|
|
||||||
"LogLevel": {
|
|
||||||
"Default": "Information",
|
|
||||||
"Microsoft.AspNetCore": "Warning"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -8,5 +8,10 @@
|
|||||||
"Microsoft.AspNetCore": "Warning"
|
"Microsoft.AspNetCore": "Warning"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"AllowedHosts": "*"
|
"AllowedHosts": "*",
|
||||||
|
"ConnectionStrings": {
|
||||||
|
//"LocationConnection": "Server=DESKTOP-OF5DPLQ\\SQLEXPRESS;Database=da_survey_dev;Trusted_Connection=True;TrustServerCertificate=True;"
|
||||||
|
"LocationConnection": "Server=207.180.248.35;Database=da_survey_dev;User Id=sa;Password=YourStrongPassw0rd;TrustServerCertificate=True;"
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -109,7 +109,7 @@ namespace DamageAssesment.Api.Questions.Controllers
|
|||||||
|
|
||||||
return BadRequest(result.ErrorMessage);
|
return BadRequest(result.ErrorMessage);
|
||||||
}
|
}
|
||||||
return CreatedAtRoute("DefaultApi",questions);
|
return CreatedAtRoute("DefaultApi", questions);
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// PUT request for update a multiple question (multilingual) for survey.
|
/// PUT request for update a multiple question (multilingual) for survey.
|
||||||
|
@ -11,10 +11,24 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1" />
|
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.9" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.9">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.9" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.9" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.9">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.21" />
|
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.21" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.5" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.5" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.5" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.5" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
|
||||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.4" />
|
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.4" />
|
||||||
|
<PackageReference Include="Serilog.Extensions.Logging.File" Version="3.0.0" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ using System.ComponentModel.DataAnnotations;
|
|||||||
|
|
||||||
namespace DamageAssesment.Api.Questions.Db
|
namespace DamageAssesment.Api.Questions.Db
|
||||||
{
|
{
|
||||||
|
[Table("QuestionCategoryTrans")]
|
||||||
public class CategoryTranslation
|
public class CategoryTranslation
|
||||||
{
|
{
|
||||||
[Key]
|
[Key]
|
||||||
|
@ -3,6 +3,7 @@ using System.ComponentModel.DataAnnotations.Schema;
|
|||||||
|
|
||||||
namespace DamageAssesment.Api.Questions.Db
|
namespace DamageAssesment.Api.Questions.Db
|
||||||
{
|
{
|
||||||
|
[Table("Questions")]
|
||||||
public class Question
|
public class Question
|
||||||
{
|
{
|
||||||
[Key]
|
[Key]
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
using System.Buffers.Text;
|
using System.Buffers.Text;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
|
||||||
namespace DamageAssesment.Api.Questions.Db
|
namespace DamageAssesment.Api.Questions.Db
|
||||||
{
|
{
|
||||||
|
[Table("QuestionCategories")]
|
||||||
public class QuestionCategory
|
public class QuestionCategory
|
||||||
{
|
{
|
||||||
[Key]
|
[Key]
|
||||||
|
@ -6,6 +6,16 @@ namespace DamageAssesment.Api.Questions.Db
|
|||||||
{
|
{
|
||||||
public class QuestionDbContext : DbContext
|
public class QuestionDbContext : DbContext
|
||||||
{
|
{
|
||||||
|
private IConfiguration _Configuration { get; set; }
|
||||||
|
public QuestionDbContext(DbContextOptions options, IConfiguration configuration) : base(options)
|
||||||
|
{
|
||||||
|
_Configuration = configuration;
|
||||||
|
}
|
||||||
|
protected override void OnConfiguring(DbContextOptionsBuilder options)
|
||||||
|
{
|
||||||
|
// connect to sql server with connection string from app settings
|
||||||
|
options.UseSqlServer(_Configuration.GetConnectionString("QuestionConnection"));
|
||||||
|
}
|
||||||
public DbSet<Db.Question> Questions { get; set; }
|
public DbSet<Db.Question> Questions { get; set; }
|
||||||
public DbSet<Db.QuestionType> QuestionTypes { get; set; }
|
public DbSet<Db.QuestionType> QuestionTypes { get; set; }
|
||||||
public DbSet<Db.QuestionsTranslation> QuestionsTranslations { get; set; }
|
public DbSet<Db.QuestionsTranslation> QuestionsTranslations { get; set; }
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
|
||||||
namespace DamageAssesment.Api.Questions.Db
|
namespace DamageAssesment.Api.Questions.Db
|
||||||
{
|
{
|
||||||
|
[Table("QuestionTypes")]
|
||||||
public class QuestionType
|
public class QuestionType
|
||||||
{
|
{
|
||||||
[Key]
|
[Key]
|
||||||
|
@ -3,6 +3,7 @@ using System.ComponentModel.DataAnnotations.Schema;
|
|||||||
|
|
||||||
namespace DamageAssesment.Api.Questions.Db
|
namespace DamageAssesment.Api.Questions.Db
|
||||||
{
|
{
|
||||||
|
[Table("QuestionTrans")]
|
||||||
public class QuestionsTranslation
|
public class QuestionsTranslation
|
||||||
{
|
{
|
||||||
[Key]
|
[Key]
|
||||||
|
@ -9,6 +9,14 @@ using System.Reflection;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
builder.Services.AddCors(p => p.AddPolicy("DamageAppCorsPolicy", build => {
|
||||||
|
build.WithOrigins("*").AllowAnyMethod().AllowAnyHeader().AllowAnyOrigin();
|
||||||
|
}));
|
||||||
|
builder.Services.AddLogging(builder =>
|
||||||
|
{
|
||||||
|
//builder.AddConsole(); // Optional: Add other providers if needed
|
||||||
|
builder.AddFile("logs/Questions-{Date}.txt"); // Specify the file path and format
|
||||||
|
});
|
||||||
// Add services to the container.
|
// Add services to the container.
|
||||||
var authkey = builder.Configuration.GetValue<string>("JwtSettings:securitykey");
|
var authkey = builder.Configuration.GetValue<string>("JwtSettings:securitykey");
|
||||||
builder.Services.AddAuthentication(item =>
|
builder.Services.AddAuthentication(item =>
|
||||||
@ -76,7 +84,7 @@ builder.Services.AddSwaggerGen(options =>
|
|||||||
|
|
||||||
builder.Services.AddDbContext<QuestionDbContext>(option =>
|
builder.Services.AddDbContext<QuestionDbContext>(option =>
|
||||||
{
|
{
|
||||||
option.UseInMemoryDatabase("Questions");
|
option.UseSqlServer("QuestionConnection");
|
||||||
});
|
});
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
@ -93,6 +101,7 @@ if (app.Environment.IsDevelopment())
|
|||||||
questionProvider.SeedData();
|
questionProvider.SeedData();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
app.UseCors("DamageAppCorsPolicy");
|
||||||
app.UseAuthentication();
|
app.UseAuthentication();
|
||||||
app.UseAuthorization();
|
app.UseAuthorization();
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ namespace DamageAssesment.Api.Questions.Providers
|
|||||||
this.questionDbContext = questionDbContext;
|
this.questionDbContext = questionDbContext;
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
this.mapper = mapper;
|
this.mapper = mapper;
|
||||||
// SeedData();
|
// SeedData();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SeedData()
|
public void SeedData()
|
||||||
@ -69,7 +69,7 @@ namespace DamageAssesment.Api.Questions.Providers
|
|||||||
var question4 = new Db.Question() { QuestionTypeId = 1, SurveyId = 2, QuestionNumber = 2, IsRequired = false, Comment = true, Key = false, CategoryId = 2 };
|
var question4 = new Db.Question() { QuestionTypeId = 1, SurveyId = 2, QuestionNumber = 2, IsRequired = false, Comment = true, Key = false, CategoryId = 2 };
|
||||||
var question5 = new Db.Question() { QuestionTypeId = 1, SurveyId = 3, QuestionNumber = 1, IsRequired = true, Comment = false, Key = true, CategoryId = 1 };
|
var question5 = new Db.Question() { QuestionTypeId = 1, SurveyId = 3, QuestionNumber = 1, IsRequired = true, Comment = false, Key = true, CategoryId = 1 };
|
||||||
var question6 = new Db.Question() { QuestionTypeId = 1, SurveyId = 3, QuestionNumber = 2, IsRequired = false, Comment = true, Key = false, CategoryId = 2 };
|
var question6 = new Db.Question() { QuestionTypeId = 1, SurveyId = 3, QuestionNumber = 2, IsRequired = false, Comment = true, Key = false, CategoryId = 2 };
|
||||||
var question7 = new Db.Question() { QuestionTypeId = 1, SurveyId = 3, QuestionNumber = 1, IsRequired = true, Comment = false, Key = true, CategoryId = 3 };
|
var question7 = new Db.Question() { QuestionTypeId = 1, SurveyId = 3, QuestionNumber = 1, IsRequired = true, Comment = false, Key = true, CategoryId = 3};
|
||||||
var question8 = new Db.Question() { QuestionTypeId = 1, SurveyId = 3, QuestionNumber = 2, IsRequired = false, Comment = true, Key = false, CategoryId = 4 };
|
var question8 = new Db.Question() { QuestionTypeId = 1, SurveyId = 3, QuestionNumber = 2, IsRequired = false, Comment = true, Key = false, CategoryId = 4 };
|
||||||
var question9 = new Db.Question() { QuestionTypeId = 1, SurveyId = 3, QuestionNumber = 1, IsRequired = true, Comment = true, Key = true, CategoryId = 5 };
|
var question9 = new Db.Question() { QuestionTypeId = 1, SurveyId = 3, QuestionNumber = 1, IsRequired = true, Comment = true, Key = true, CategoryId = 5 };
|
||||||
var question10 = new Db.Question() { QuestionTypeId = 1, SurveyId = 3, QuestionNumber = 2, IsRequired = false, Comment = false, Key = true, CategoryId = 1 };
|
var question10 = new Db.Question() { QuestionTypeId = 1, SurveyId = 3, QuestionNumber = 2, IsRequired = false, Comment = false, Key = true, CategoryId = 1 };
|
||||||
@ -274,7 +274,7 @@ namespace DamageAssesment.Api.Questions.Providers
|
|||||||
if (question != null)
|
if (question != null)
|
||||||
{
|
{
|
||||||
logger?.LogInformation($"{question} customer(s) found");
|
logger?.LogInformation($"{question} customer(s) found");
|
||||||
var result = mapper.Map<Db.Question, Models.MultiLanguage>(question);
|
var result = mapper.Map<Db.Question, Models.MultiLanguage>(question);
|
||||||
result.Text = CreateMultiLanguageObject(GetQuestionsTranslations(id, language));
|
result.Text = CreateMultiLanguageObject(GetQuestionsTranslations(id, language));
|
||||||
return (true, result, null);
|
return (true, result, null);
|
||||||
}
|
}
|
||||||
@ -313,7 +313,7 @@ namespace DamageAssesment.Api.Questions.Providers
|
|||||||
CategoryId = item.Id,
|
CategoryId = item.Id,
|
||||||
IconLibrary = item.IconLibrary,
|
IconLibrary = item.IconLibrary,
|
||||||
IconName = item.IconName,
|
IconName = item.IconName,
|
||||||
CategoryNames = CreateCategoryMultiLanguageObject(GetCategoryTranslations(item.Id, language)),
|
CategoryNames= CreateCategoryMultiLanguageObject(GetCategoryTranslations(item.Id, language)),
|
||||||
QuestionsText = GetSurveyQuestion(mapper.Map<List<Db.Question>, List<Models.MultiLanguage>>(questions.Where(a => a.CategoryId == item.Id).ToList()), language)
|
QuestionsText = GetSurveyQuestion(mapper.Map<List<Db.Question>, List<Models.MultiLanguage>>(questions.Where(a => a.CategoryId == item.Id).ToList()), language)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,8 +0,0 @@
|
|||||||
{
|
|
||||||
"Logging": {
|
|
||||||
"LogLevel": {
|
|
||||||
"Default": "Information",
|
|
||||||
"Microsoft.AspNetCore": "Warning"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -8,5 +8,10 @@
|
|||||||
"Microsoft.AspNetCore": "Warning"
|
"Microsoft.AspNetCore": "Warning"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"AllowedHosts": "*"
|
"AllowedHosts": "*",
|
||||||
|
"ConnectionStrings": {
|
||||||
|
//"QuestionConnection": "Server=DESKTOP-OF5DPLQ\\SQLEXPRESS;Database=da_survey_dev;Trusted_Connection=True;TrustServerCertificate=True;"
|
||||||
|
"QuestionConnection": "Server=207.180.248.35;Database=da_survey_dev;User Id=sa;Password=YourStrongPassw0rd;TrustServerCertificate=True;"
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.5" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.9" />
|
||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
|
||||||
<PackageReference Include="Moq" Version="4.18.4" />
|
<PackageReference Include="Moq" Version="4.18.4" />
|
||||||
<PackageReference Include="xunit" Version="2.4.2" />
|
<PackageReference Include="xunit" Version="2.4.2" />
|
||||||
|
@ -86,8 +86,9 @@ namespace DamageAssesment.Api.Questions.Test
|
|||||||
List<Models.Question> Questions = new List<Models.Question>();
|
List<Models.Question> Questions = new List<Models.Question>();
|
||||||
QuestionsTranslations.Add(QuestionsTranslation);
|
QuestionsTranslations.Add(QuestionsTranslation);
|
||||||
Questions.Models.Question question = new Questions.Models.Question() { Id = 1, Questions = QuestionsTranslations, TypeText = "Text 1", SurveyId = 1, QuestionNumber = 1, IsRequired = true, Comment = false, Key = true, CategoryId = 1 };
|
Questions.Models.Question question = new Questions.Models.Question() { Id = 1, Questions = QuestionsTranslations, TypeText = "Text 1", SurveyId = 1, QuestionNumber = 1, IsRequired = true, Comment = false, Key = true, CategoryId = 1 };
|
||||||
Questions.Add(question);
|
Questions.Add(question);
|
||||||
return Questions;
|
return Questions;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -356,6 +356,5 @@ namespace DamageAssesment.Api.Questions.Test
|
|||||||
|
|
||||||
Assert.Equal(404, result.StatusCode);
|
Assert.Equal(404, result.StatusCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -11,13 +11,30 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1" />
|
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1" />
|
||||||
<PackageReference Include="EPPlus" Version="7.0.0" />
|
<PackageReference Include="ClosedXML" Version="0.102.1" />
|
||||||
|
<PackageReference Include="EPPlus" Version="6.2.10" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.9" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.9">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.9" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.9" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.9">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="7.0.9" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.21" />
|
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.21" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.5" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.5" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.5" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.5" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="7.0.5" />
|
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="7.0.5" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
|
||||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.4" />
|
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.4" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
|
<PackageReference Include="Serilog.Extensions.Logging.File" Version="3.0.0" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ using System.ComponentModel.DataAnnotations.Schema;
|
|||||||
|
|
||||||
namespace DamageAssesment.Api.Responses.Db
|
namespace DamageAssesment.Api.Responses.Db
|
||||||
{
|
{
|
||||||
|
[Table("SurveyResponses")]
|
||||||
public class SurveyResponse
|
public class SurveyResponse
|
||||||
{
|
{
|
||||||
[Key]
|
[Key]
|
||||||
|
@ -4,12 +4,17 @@ namespace DamageAssesment.Api.Responses.Db
|
|||||||
{
|
{
|
||||||
public class SurveyResponseDbContext:DbContext
|
public class SurveyResponseDbContext:DbContext
|
||||||
{
|
{
|
||||||
public DbSet<Db.SurveyResponse> SurveyResponses { get; set; }
|
private IConfiguration _Configuration { get; set; }
|
||||||
|
public SurveyResponseDbContext(DbContextOptions options, IConfiguration configuration) : base(options)
|
||||||
public SurveyResponseDbContext(DbContextOptions options) : base(options)
|
|
||||||
{
|
{
|
||||||
|
_Configuration = configuration;
|
||||||
}
|
}
|
||||||
|
protected override void OnConfiguring(DbContextOptionsBuilder options)
|
||||||
|
{
|
||||||
|
// connect to sql server with connection string from app settings
|
||||||
|
options.UseSqlServer(_Configuration.GetConnectionString("ResponsesConnection"));
|
||||||
|
}
|
||||||
|
public DbSet<Db.SurveyResponse> SurveyResponses { get; set; }
|
||||||
|
|
||||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
|
@ -7,4 +7,4 @@ namespace DamageAssesment.Api.Responses.Interfaces
|
|||||||
Task<List<Employee>> getEmployeesAsync(string token);
|
Task<List<Employee>> getEmployeesAsync(string token);
|
||||||
Task<Employee> getEmployeeAsync(int employeeId, string token);
|
Task<Employee> getEmployeeAsync(int employeeId, string token);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -4,7 +4,7 @@ namespace DamageAssesment.Api.Responses.Interfaces
|
|||||||
{
|
{
|
||||||
public interface IQuestionServiceProvider
|
public interface IQuestionServiceProvider
|
||||||
{
|
{
|
||||||
Task<List<Question>> getQuestionsAsync(string language,string token);
|
Task<List<Question>> getQuestionsAsync(string language, string token);
|
||||||
Task<List<SurveyQuestions>> getSurveyQuestionsAsync(int surveyId, string token);
|
Task<List<SurveyQuestions>> getSurveyQuestionsAsync(int surveyId, string token);
|
||||||
Task<Question> getQuestionsAsync(int questionId, string token);
|
Task<Question> getQuestionsAsync(int questionId, string token);
|
||||||
Task<List<QuestionCategory>> GetQuestionCategoriesAsync(string? language, string token);
|
Task<List<QuestionCategory>> GetQuestionCategoriesAsync(string? language, string token);
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
public class SurveyExport
|
public class SurveyExport
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
public string SurveyQuestion { get; set; }
|
public string SurveyQuestion { get; set; }
|
||||||
public string Answer { get; set; }
|
public string Answer { get; set; }
|
||||||
public string Category { get; set; }
|
public string Category { get; set; }
|
||||||
|
|
||||||
|
@ -16,7 +16,14 @@ const int intervalToRetry = 2; //2 seconds
|
|||||||
const int maxRetryForCircuitBraker = 5;
|
const int maxRetryForCircuitBraker = 5;
|
||||||
const int intervalForCircuitBraker = 5; //5 seconds
|
const int intervalForCircuitBraker = 5; //5 seconds
|
||||||
|
|
||||||
|
builder.Services.AddCors(p => p.AddPolicy("DamageAppCorsPolicy", build => {
|
||||||
|
build.WithOrigins("*").AllowAnyMethod().AllowAnyHeader().AllowAnyOrigin();
|
||||||
|
}));
|
||||||
|
builder.Services.AddLogging(builder =>
|
||||||
|
{
|
||||||
|
//builder.AddConsole(); // Optional: Add other providers if needed
|
||||||
|
builder.AddFile("logs/Responses-{Date}.txt"); // Specify the file path and format
|
||||||
|
});
|
||||||
// Add services to the container.
|
// Add services to the container.
|
||||||
var authkey = builder.Configuration.GetValue<string>("JwtSettings:securitykey");
|
var authkey = builder.Configuration.GetValue<string>("JwtSettings:securitykey");
|
||||||
builder.Services.AddAuthentication(item =>
|
builder.Services.AddAuthentication(item =>
|
||||||
@ -48,8 +55,8 @@ builder.Services.AddScoped<IQuestionServiceProvider, QuestionServiceProvider>();
|
|||||||
builder.Services.AddScoped<IEmployeeServiceProvider, EmployeeServiceProvider>();
|
builder.Services.AddScoped<IEmployeeServiceProvider, EmployeeServiceProvider>();
|
||||||
builder.Services.AddScoped<IAttachmentServiceProvider, AttachmentServiceProvider>();
|
builder.Services.AddScoped<IAttachmentServiceProvider, AttachmentServiceProvider>();
|
||||||
builder.Services.AddScoped<ISurveyServiceProvider, SurveyServiceProvider>();
|
builder.Services.AddScoped<ISurveyServiceProvider, SurveyServiceProvider>();
|
||||||
builder.Services.AddHttpContextAccessor();
|
|
||||||
builder.Services.AddScoped<IExcelExportService, ExcelExportService>();
|
builder.Services.AddScoped<IExcelExportService, ExcelExportService>();
|
||||||
|
builder.Services.AddHttpContextAccessor();
|
||||||
|
|
||||||
builder.Services.AddHttpClient<IHttpUtil, HttpUtil>().
|
builder.Services.AddHttpClient<IHttpUtil, HttpUtil>().
|
||||||
AddTransientHttpErrorPolicy(policy => policy.WaitAndRetryAsync(maxApiCallRetries, _ => TimeSpan.FromSeconds(intervalToRetry))).
|
AddTransientHttpErrorPolicy(policy => policy.WaitAndRetryAsync(maxApiCallRetries, _ => TimeSpan.FromSeconds(intervalToRetry))).
|
||||||
@ -96,7 +103,7 @@ builder.Services.AddSwaggerGen(options =>
|
|||||||
});
|
});
|
||||||
builder.Services.AddDbContext<SurveyResponseDbContext>(option =>
|
builder.Services.AddDbContext<SurveyResponseDbContext>(option =>
|
||||||
{
|
{
|
||||||
option.UseInMemoryDatabase("Responses");
|
option.UseSqlServer("ResponsesConnection");
|
||||||
});
|
});
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
@ -106,7 +113,7 @@ if (app.Environment.IsDevelopment())
|
|||||||
app.UseSwagger();
|
app.UseSwagger();
|
||||||
app.UseSwaggerUI();
|
app.UseSwaggerUI();
|
||||||
}
|
}
|
||||||
|
app.UseCors("DamageAppCorsPolicy");
|
||||||
app.UseAuthentication();
|
app.UseAuthentication();
|
||||||
app.UseAuthorization();
|
app.UseAuthorization();
|
||||||
|
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
using DamageAssesment.Api.Responses.Interfaces;
|
using ClosedXML.Excel;
|
||||||
|
using DamageAssesment.Api.Responses.Interfaces;
|
||||||
using DamageAssesment.Api.Responses.Models;
|
using DamageAssesment.Api.Responses.Models;
|
||||||
using OfficeOpenXml;
|
using OfficeOpenXml;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
|
||||||
|
|
||||||
namespace DamageAssesment.Api.Responses.Providers
|
namespace DamageAssesment.Api.Responses.Providers
|
||||||
{
|
{
|
||||||
public class ExcelExportService : IExcelExportService
|
public class ExcelExportService: IExcelExportService
|
||||||
{
|
{
|
||||||
public byte[] ExportToExcel<T1>(List<object> responses)
|
public byte[] ExportToExcel<T1>(List<object> responses)
|
||||||
{
|
{
|
||||||
ExcelPackage.LicenseContext = OfficeOpenXml.LicenseContext.NonCommercial;
|
ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
|
||||||
using (var package = new ExcelPackage())
|
using (var package = new ExcelPackage())
|
||||||
{
|
{
|
||||||
// Create the first worksheet and populate it with responses
|
// Create the first worksheet and populate it with responses
|
||||||
@ -29,7 +29,7 @@ namespace DamageAssesment.Api.Responses.Providers
|
|||||||
for (int col = 1; col <= properties.Length; col++)
|
for (int col = 1; col <= properties.Length; col++)
|
||||||
{
|
{
|
||||||
worksheet.Cells[1, col].Value = properties[col - 1].Name;
|
worksheet.Cells[1, col].Value = properties[col - 1].Name;
|
||||||
if (properties[col - 1].Name.ToLower().Contains("attachment"))
|
if(properties[col - 1].Name.ToLower().Contains("attachment"))
|
||||||
IsAttchments.Add(col);
|
IsAttchments.Add(col);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,8 +38,8 @@ namespace DamageAssesment.Api.Responses.Providers
|
|||||||
{
|
{
|
||||||
for (int col = 1; col <= properties.Length; col++)
|
for (int col = 1; col <= properties.Length; col++)
|
||||||
{
|
{
|
||||||
|
|
||||||
string value = Convert.ToString(properties[col - 1].GetValue(data[row - 2]));
|
string value = Convert.ToString(properties[col - 1].GetValue(data[row - 2]));
|
||||||
if (IsAttchments.Where(a => a == col).Count() > 0 && !string.IsNullOrEmpty(value))
|
if (IsAttchments.Where(a => a == col).Count() > 0 && !string.IsNullOrEmpty(value))
|
||||||
{
|
{
|
||||||
List<string> attachments = value.Split("##").ToList();
|
List<string> attachments = value.Split("##").ToList();
|
||||||
@ -53,7 +53,7 @@ namespace DamageAssesment.Api.Responses.Providers
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
worksheet.Cells[row, col].Value = value;
|
worksheet.Cells[row, col].Value = value;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -82,7 +82,7 @@ namespace DamageAssesment.Api.Responses.Providers
|
|||||||
}
|
}
|
||||||
listSurveyResponse = listSurveyResponse
|
listSurveyResponse = listSurveyResponse
|
||||||
.OrderByDescending(obj => obj.Id)
|
.OrderByDescending(obj => obj.Id)
|
||||||
.GroupBy(obj => new { obj.SurveyId, obj.EmployeeId, obj.LocationId })
|
.GroupBy(obj => new { obj.SurveyId, obj.LocationId })//obj.EmployeeId,
|
||||||
.Select(group => group.FirstOrDefault()) // or .FirstOrDefault() if you want to handle empty groups
|
.Select(group => group.FirstOrDefault()) // or .FirstOrDefault() if you want to handle empty groups
|
||||||
.ToList();
|
.ToList();
|
||||||
if (listSurveyResponse.Any())
|
if (listSurveyResponse.Any())
|
||||||
@ -139,7 +139,7 @@ namespace DamageAssesment.Api.Responses.Providers
|
|||||||
{
|
{
|
||||||
logger?.LogInformation("Querying to get SurveyResponse object from DB");
|
logger?.LogInformation("Querying to get SurveyResponse object from DB");
|
||||||
//get all the survey that already taken by the employee
|
//get all the survey that already taken by the employee
|
||||||
var surveys = await surveyServiceProvider.getSurveysAsync(language,token);
|
var surveys = await surveyServiceProvider.getSurveysAsync(language, token);
|
||||||
surveys = surveys.Where(s => s.IsEnabled == true && s.Status == SurveyStatus.ACTIVE.ToString()).ToList();
|
surveys = surveys.Where(s => s.IsEnabled == true && s.Status == SurveyStatus.ACTIVE.ToString()).ToList();
|
||||||
if (employeeid == null || employeeid == 0)
|
if (employeeid == null || employeeid == 0)
|
||||||
return (true, surveys, null);
|
return (true, surveys, null);
|
||||||
@ -443,7 +443,6 @@ namespace DamageAssesment.Api.Responses.Providers
|
|||||||
var answersList = await answerServiceProvider.getAnswersAsync(token);
|
var answersList = await answerServiceProvider.getAnswersAsync(token);
|
||||||
if (answersList == null || !answersList.Any())
|
if (answersList == null || !answersList.Any())
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
//get all the answers for the particular survey
|
//get all the answers for the particular survey
|
||||||
var surveyAnswers = answersList.Join(
|
var surveyAnswers = answersList.Join(
|
||||||
surveyResponses,
|
surveyResponses,
|
||||||
@ -528,7 +527,7 @@ namespace DamageAssesment.Api.Responses.Providers
|
|||||||
{
|
{
|
||||||
var employee = await employeeServiceProvider.getEmployeeAsync(surveyResponse.EmployeeId, token);
|
var employee = await employeeServiceProvider.getEmployeeAsync(surveyResponse.EmployeeId, token);
|
||||||
var answers = await answerServiceProvider.GetAnswersByResponseIdAsync(surveyResponse.Id, token);
|
var answers = await answerServiceProvider.GetAnswersByResponseIdAsync(surveyResponse.Id, token);
|
||||||
var allQuestions = await questionServiceProvider.getQuestionsAsync(null,token);
|
var allQuestions = await questionServiceProvider.getQuestionsAsync(null, token);
|
||||||
var questions = allQuestions.Where(s => s.SurveyId == surveyResponse.SurveyId);
|
var questions = allQuestions.Where(s => s.SurveyId == surveyResponse.SurveyId);
|
||||||
var attachments = await attachmentServiceProvider.getAttachmentsAsync(token);
|
var attachments = await attachmentServiceProvider.getAttachmentsAsync(token);
|
||||||
|
|
||||||
@ -539,14 +538,14 @@ namespace DamageAssesment.Api.Responses.Providers
|
|||||||
surveyResponse.LocationId,
|
surveyResponse.LocationId,
|
||||||
surveyResponse.EmployeeId,
|
surveyResponse.EmployeeId,
|
||||||
surveyResponse.ClientDevice,
|
surveyResponse.ClientDevice,
|
||||||
surveyResponse.KeyAnswerResult,
|
// surveyResponse.KeyAnswerResult,
|
||||||
surveyResponse.Longitute,
|
surveyResponse.Longitute,
|
||||||
surveyResponse.Latitude,
|
surveyResponse.Latitude,
|
||||||
Employee = employee,
|
Employee = employee,
|
||||||
answers = from ans in answers
|
answers = from ans in answers
|
||||||
select new
|
select new
|
||||||
{
|
{
|
||||||
ans.QuestionId,
|
// ans.QuestionId,
|
||||||
ans.Id,
|
ans.Id,
|
||||||
ans.AnswerText,
|
ans.AnswerText,
|
||||||
ans.Comment,
|
ans.Comment,
|
||||||
@ -582,6 +581,11 @@ namespace DamageAssesment.Api.Responses.Providers
|
|||||||
surveyResonses = await surveyResponseDbContext.SurveyResponses.Where(x => x.SurveyId == surveyId && x.EmployeeId == employeeid).ToListAsync();
|
surveyResonses = await surveyResponseDbContext.SurveyResponses.Where(x => x.SurveyId == surveyId && x.EmployeeId == employeeid).ToListAsync();
|
||||||
employee = await employeeServiceProvider.getEmployeeAsync(employeeid, token);
|
employee = await employeeServiceProvider.getEmployeeAsync(employeeid, token);
|
||||||
}
|
}
|
||||||
|
surveyResonses = surveyResonses
|
||||||
|
.OrderByDescending(obj => obj.Id)
|
||||||
|
.GroupBy(obj => new { obj.SurveyId, obj.LocationId })//obj.EmployeeId,
|
||||||
|
.Select(group => group.FirstOrDefault()) // or .FirstOrDefault() if you want to handle empty groups
|
||||||
|
.ToList();
|
||||||
|
|
||||||
var answers = await answerServiceProvider.getAnswersAsync(token);
|
var answers = await answerServiceProvider.getAnswersAsync(token);
|
||||||
var questions = await questionServiceProvider.getQuestionsAsync(null, token);
|
var questions = await questionServiceProvider.getQuestionsAsync(null, token);
|
||||||
@ -598,16 +602,16 @@ namespace DamageAssesment.Api.Responses.Providers
|
|||||||
r.LocationId,
|
r.LocationId,
|
||||||
r.EmployeeId,
|
r.EmployeeId,
|
||||||
r.ClientDevice,
|
r.ClientDevice,
|
||||||
r.KeyAnswerResult,
|
// r.KeyAnswerResult,
|
||||||
r.Longitute,
|
r.Longitute,
|
||||||
r.Latitude,
|
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(),
|
// 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
|
answers = from ans in answers
|
||||||
where ans.SurveyResponseId == r.Id
|
where ans.SurveyResponseId == r.Id
|
||||||
select new
|
select new
|
||||||
{
|
{
|
||||||
ans.Id,
|
ans.Id,
|
||||||
ans.QuestionId,
|
// ans.QuestionId,
|
||||||
ans.AnswerText,
|
ans.AnswerText,
|
||||||
ans.Comment,
|
ans.Comment,
|
||||||
Questions = (from q in surveyQuestions where q.Id == ans.QuestionId select new { q.Id, q.QuestionNumber, q.CategoryId, q.Text }).SingleOrDefault(),
|
Questions = (from q in surveyQuestions where q.Id == ans.QuestionId select new { q.Id, q.QuestionNumber, q.CategoryId, q.Text }).SingleOrDefault(),
|
||||||
@ -650,9 +654,13 @@ namespace DamageAssesment.Api.Responses.Providers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
surveyResonses = surveyResonses
|
||||||
|
.OrderByDescending(obj => obj.Id)
|
||||||
|
.GroupBy(obj => new { obj.SurveyId, obj.EmployeeId, obj.LocationId })
|
||||||
|
.Select(group => group.FirstOrDefault()) // or .FirstOrDefault() if you want to handle empty groups
|
||||||
|
.ToList();
|
||||||
var answers = await answerServiceProvider.getAnswersAsync(token);
|
var answers = await answerServiceProvider.getAnswersAsync(token);
|
||||||
var questions = await questionServiceProvider.getQuestionsAsync(null,token);
|
var questions = await questionServiceProvider.getQuestionsAsync(null, token);
|
||||||
var attachments = await attachmentServiceProvider.getAttachmentsAsync(token);
|
var attachments = await attachmentServiceProvider.getAttachmentsAsync(token);
|
||||||
|
|
||||||
var result = from r in surveyResonses
|
var result = from r in surveyResonses
|
||||||
@ -663,16 +671,16 @@ namespace DamageAssesment.Api.Responses.Providers
|
|||||||
r.LocationId,
|
r.LocationId,
|
||||||
r.EmployeeId,
|
r.EmployeeId,
|
||||||
r.ClientDevice,
|
r.ClientDevice,
|
||||||
r.KeyAnswerResult,
|
// r.KeyAnswerResult,
|
||||||
r.Longitute,
|
r.Longitute,
|
||||||
r.Latitude,
|
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 = 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(),
|
||||||
answers = from ans in answers
|
answers = from ans in answers
|
||||||
where ans.SurveyResponseId == r.Id
|
where ans.SurveyResponseId == r.Id
|
||||||
select new
|
select new
|
||||||
{
|
{
|
||||||
ans.Id,
|
ans.Id,
|
||||||
ans.QuestionId,
|
// ans.QuestionId,
|
||||||
ans.AnswerText,
|
ans.AnswerText,
|
||||||
ans.Comment,
|
ans.Comment,
|
||||||
Questions = (from q in questions where q.Id == ans.QuestionId select new { q.Id, q.QuestionNumber, q.CategoryId, q.Text }).SingleOrDefault(),
|
Questions = (from q in questions where q.Id == ans.QuestionId select new { q.Id, q.QuestionNumber, q.CategoryId, q.Text }).SingleOrDefault(),
|
||||||
@ -911,9 +919,13 @@ namespace DamageAssesment.Api.Responses.Providers
|
|||||||
_employee = new { employee.Id, employee.Name, employee.BirthDate, employee.Email, employee.OfficePhoneNumber };
|
_employee = new { employee.Id, employee.Name, employee.BirthDate, employee.Email, employee.OfficePhoneNumber };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
surveyResonses = surveyResonses
|
||||||
|
.OrderByDescending(obj => obj.Id)
|
||||||
|
.GroupBy(obj => new { obj.SurveyId, obj.LocationId }) //obj.EmployeeId,
|
||||||
|
.Select(group => group.FirstOrDefault()) // or .FirstOrDefault() if you want to handle empty groups
|
||||||
|
.ToList();
|
||||||
var answers = await answerServiceProvider.getAnswersAsync(token);
|
var answers = await answerServiceProvider.getAnswersAsync(token);
|
||||||
var questions = await questionServiceProvider.getQuestionsAsync(null,token);
|
var questions = await questionServiceProvider.getQuestionsAsync(null, token);
|
||||||
var surveyQuestions = from q in questions where q.SurveyId == surveyId select q;
|
var surveyQuestions = from q in questions where q.SurveyId == surveyId select q;
|
||||||
var attachments = await attachmentServiceProvider.getAttachmentsAsync(token);
|
var attachments = await attachmentServiceProvider.getAttachmentsAsync(token);
|
||||||
|
|
||||||
@ -925,16 +937,16 @@ namespace DamageAssesment.Api.Responses.Providers
|
|||||||
r.LocationId,
|
r.LocationId,
|
||||||
r.EmployeeId,
|
r.EmployeeId,
|
||||||
r.ClientDevice,
|
r.ClientDevice,
|
||||||
r.KeyAnswerResult,
|
// r.KeyAnswerResult,
|
||||||
r.Longitute,
|
r.Longitute,
|
||||||
r.Latitude,
|
r.Latitude,
|
||||||
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
|
answers = from ans in answers
|
||||||
where ans.SurveyResponseId == r.Id
|
where ans.SurveyResponseId == r.Id
|
||||||
|
|
||||||
select new
|
select new
|
||||||
{
|
{
|
||||||
ans.QuestionId,
|
// ans.QuestionId,
|
||||||
ans.Id,
|
ans.Id,
|
||||||
ans.AnswerText,
|
ans.AnswerText,
|
||||||
ans.Comment,
|
ans.Comment,
|
||||||
@ -977,7 +989,11 @@ namespace DamageAssesment.Api.Responses.Providers
|
|||||||
_employee = new { employee.Id, employee.Name, employee.BirthDate, employee.Email, employee.OfficePhoneNumber };
|
_employee = new { employee.Id, employee.Name, employee.BirthDate, employee.Email, employee.OfficePhoneNumber };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
surveyResponses = surveyResponses
|
||||||
|
.OrderByDescending(obj => obj.Id)
|
||||||
|
.GroupBy(obj => new { obj.SurveyId, obj.LocationId })//, obj.EmployeeId
|
||||||
|
.Select(group => group.FirstOrDefault()) // or .FirstOrDefault() if you want to handle empty groups
|
||||||
|
.ToList();
|
||||||
//var surveyResponses = await surveyResponseDbContext.Responses.Where(x => x.SurveyId == survey.Id).ToListAsync();
|
//var surveyResponses = await surveyResponseDbContext.Responses.Where(x => x.SurveyId == survey.Id).ToListAsync();
|
||||||
// var employees = await employeeServiceProvider.getEmployeesAsync();
|
// var employees = await employeeServiceProvider.getEmployeesAsync();
|
||||||
var answers = await answerServiceProvider.getAnswersAsync(token);
|
var answers = await answerServiceProvider.getAnswersAsync(token);
|
||||||
@ -991,10 +1007,10 @@ namespace DamageAssesment.Api.Responses.Providers
|
|||||||
r.LocationId,
|
r.LocationId,
|
||||||
r.EmployeeId,
|
r.EmployeeId,
|
||||||
r.ClientDevice,
|
r.ClientDevice,
|
||||||
r.KeyAnswerResult,
|
// r.KeyAnswerResult,
|
||||||
r.Longitute,
|
r.Longitute,
|
||||||
r.Latitude,
|
r.Latitude,
|
||||||
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
|
answers = from ans in answers
|
||||||
where ans.SurveyResponseId == r.Id
|
where ans.SurveyResponseId == r.Id
|
||||||
&& ans.QuestionId == question.Id
|
&& ans.QuestionId == question.Id
|
||||||
@ -1002,7 +1018,7 @@ namespace DamageAssesment.Api.Responses.Providers
|
|||||||
|
|
||||||
select new
|
select new
|
||||||
{
|
{
|
||||||
ans.QuestionId,
|
// ans.QuestionId,
|
||||||
AnswerId = ans.Id,
|
AnswerId = ans.Id,
|
||||||
ans.AnswerText,
|
ans.AnswerText,
|
||||||
ans.Comment,
|
ans.Comment,
|
||||||
|
@ -15,7 +15,7 @@ namespace DamageAssesment.Api.Responses.Services
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null, token);
|
var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null,token);
|
||||||
var employees = JsonConvert.DeserializeObject<List<Employee>>(responseJsonString);
|
var employees = JsonConvert.DeserializeObject<List<Employee>>(responseJsonString);
|
||||||
|
|
||||||
if (employees == null || !employees.Any())
|
if (employees == null || !employees.Any())
|
||||||
@ -33,7 +33,7 @@ namespace DamageAssesment.Api.Responses.Services
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
url = urlBase + string.Format(configuration.GetValue<string>("RessourceSettings:EmployeeById"), employeeId);
|
url = urlBase + string.Format(configuration.GetValue<string>("RessourceSettings:EmployeeById"), employeeId);
|
||||||
var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null, token);
|
var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null, token);
|
||||||
var employee = JsonConvert.DeserializeObject<Employee>(responseJsonString);
|
var employee = JsonConvert.DeserializeObject<Employee>(responseJsonString);
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
using DamageAssesment.Api.Responses.Interfaces;
|
using DamageAssesment.Api.Responses.Interfaces;
|
||||||
using DamageAssesment.Api.Responses.Models;
|
using DamageAssesment.Api.Responses.Models;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using OfficeOpenXml.FormulaParsing.LexicalAnalysis;
|
|
||||||
|
|
||||||
namespace DamageAssesment.Api.Responses.Services
|
namespace DamageAssesment.Api.Responses.Services
|
||||||
{
|
{
|
||||||
@ -11,13 +10,13 @@ namespace DamageAssesment.Api.Responses.Services
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<List<Question>> getQuestionsAsync(string language,string token)
|
public async Task<List<Question>> getQuestionsAsync(string language, string token)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(language))
|
if (!string.IsNullOrEmpty(language))
|
||||||
url = url + "/" + language;
|
url = url + "/" + language;
|
||||||
var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null,token);
|
var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null, token);
|
||||||
var questions = JsonConvert.DeserializeObject<List<Question>>(responseJsonString);
|
var questions = JsonConvert.DeserializeObject<List<Question>>(responseJsonString);
|
||||||
|
|
||||||
if (questions == null || !questions.Any())
|
if (questions == null || !questions.Any())
|
||||||
@ -30,7 +29,7 @@ namespace DamageAssesment.Api.Responses.Services
|
|||||||
return new List<Question>();
|
return new List<Question>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public async Task<List<QuestionCategory>> GetQuestionCategoriesAsync(string? language,string token)
|
public async Task<List<QuestionCategory>> GetQuestionCategoriesAsync(string? language, string token)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -4,7 +4,7 @@ using Newtonsoft.Json;
|
|||||||
|
|
||||||
namespace DamageAssesment.Api.Responses.Services
|
namespace DamageAssesment.Api.Responses.Services
|
||||||
{
|
{
|
||||||
public class SurveyServiceProvider : ServiceProviderBase, ISurveyServiceProvider
|
public class SurveyServiceProvider :ServiceProviderBase, ISurveyServiceProvider
|
||||||
{
|
{
|
||||||
public SurveyServiceProvider(IConfiguration configuration, IHttpUtil httpUtil, ILogger<EmployeeServiceProvider> logger) : base(configuration, httpUtil, logger, configuration.GetValue<string>("RessourceSettings:Survey"), configuration.GetValue<string>("EndPointSettings:SurveyUrlBase"))
|
public SurveyServiceProvider(IConfiguration configuration, IHttpUtil httpUtil, ILogger<EmployeeServiceProvider> logger) : base(configuration, httpUtil, logger, configuration.GetValue<string>("RessourceSettings:Survey"), configuration.GetValue<string>("EndPointSettings:SurveyUrlBase"))
|
||||||
{
|
{
|
||||||
@ -16,7 +16,7 @@ namespace DamageAssesment.Api.Responses.Services
|
|||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(language))
|
if (!string.IsNullOrEmpty(language))
|
||||||
url = url + "/" + language;
|
url = url + "/" + language;
|
||||||
var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null,token);
|
var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null, token);
|
||||||
var surveys = JsonConvert.DeserializeObject<List<Survey>>(responseJsonString);
|
var surveys = JsonConvert.DeserializeObject<List<Survey>>(responseJsonString);
|
||||||
|
|
||||||
if (surveys == null || !surveys.Any())
|
if (surveys == null || !surveys.Any())
|
||||||
@ -38,7 +38,7 @@ namespace DamageAssesment.Api.Responses.Services
|
|||||||
var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null, token);
|
var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null, token);
|
||||||
var survey = JsonConvert.DeserializeObject<Survey>(responseJsonString);
|
var survey = JsonConvert.DeserializeObject<Survey>(responseJsonString);
|
||||||
|
|
||||||
if (survey == null)
|
if (survey == null )
|
||||||
return null;
|
return null;
|
||||||
else return survey;
|
else return survey;
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,10 @@
|
|||||||
"JwtSettings": {
|
"JwtSettings": {
|
||||||
"securitykey": "bWlhbWkgZGFkZSBzY2hvb2xzIHNlY3JldCBrZXk="
|
"securitykey": "bWlhbWkgZGFkZSBzY2hvb2xzIHNlY3JldCBrZXk="
|
||||||
},
|
},
|
||||||
|
"ConnectionStrings": {
|
||||||
|
//"ResponsesConnection": "Server=DESKTOP-OF5DPLQ\\SQLEXPRESS;Database=da_survey_dev;Trusted_Connection=True;TrustServerCertificate=True;"
|
||||||
|
"ResponsesConnection": "Server=207.180.248.35;Database=da_survey_dev;User Id=sa;Password=YourStrongPassw0rd;TrustServerCertificate=True;"
|
||||||
|
},
|
||||||
//"EndPointSettings": {
|
//"EndPointSettings": {
|
||||||
// "AnswerUrlBase": "http://localhost:5200",
|
// "AnswerUrlBase": "http://localhost:5200",
|
||||||
// "LocationUrlBase": "http://localhost:5213",
|
// "LocationUrlBase": "http://localhost:5213",
|
||||||
@ -18,7 +22,6 @@
|
|||||||
// "AttachmentUrlBase": "http://localhost:5243",
|
// "AttachmentUrlBase": "http://localhost:5243",
|
||||||
// "SurveyUrlBase": "http://localhost:5009"
|
// "SurveyUrlBase": "http://localhost:5009"
|
||||||
//},
|
//},
|
||||||
//Endpoints for docker-container
|
|
||||||
"EndPointSettings": {
|
"EndPointSettings": {
|
||||||
"AnswerUrlBase": "http://damageassesment.api.answers:80",
|
"AnswerUrlBase": "http://damageassesment.api.answers:80",
|
||||||
"LocationUrlBase": "http://damageassesment.api.locations:80",
|
"LocationUrlBase": "http://damageassesment.api.locations:80",
|
||||||
@ -27,6 +30,7 @@
|
|||||||
"AttachmentUrlBase": "http://damageassesment.api.attachments:80",
|
"AttachmentUrlBase": "http://damageassesment.api.attachments:80",
|
||||||
"SurveyUrlBase": "http://damageassesment.api.surveys:80"
|
"SurveyUrlBase": "http://damageassesment.api.surveys:80"
|
||||||
},
|
},
|
||||||
|
|
||||||
"RessourceSettings": {
|
"RessourceSettings": {
|
||||||
"Employee": "/employees",
|
"Employee": "/employees",
|
||||||
"EmployeeById": "/employees/{0}",
|
"EmployeeById": "/employees/{0}",
|
||||||
|
@ -34,7 +34,55 @@ namespace DamageAssesment.Api.Surveys.Test
|
|||||||
|
|
||||||
Assert.Equal(204, result.StatusCode);
|
Assert.Equal(204, result.StatusCode);
|
||||||
}
|
}
|
||||||
|
[Fact(DisplayName = "Get active Surveys - Ok case")]
|
||||||
|
public async Task GetActiveSurveysAsync_ShouldReturnStatusCode200()
|
||||||
|
{
|
||||||
|
var mockSurveyService = new Mock<ISurveyProvider>();
|
||||||
|
var mockResponse = await MockData.getOkResponse();
|
||||||
|
mockSurveyService.Setup(service => service.GetActiveSurveysAsync(true,null)).ReturnsAsync(mockResponse);
|
||||||
|
|
||||||
|
var surveyProvider = new SurveysController(mockSurveyService.Object);
|
||||||
|
var result = (OkObjectResult)await surveyProvider.GetActiveSurveysAsync(null);
|
||||||
|
|
||||||
|
Assert.Equal(200, result.StatusCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact(DisplayName = "Get active Surveys - NoContent Case")]
|
||||||
|
public async Task GetActiveSurveysAsync_ShouldReturnStatusCode204()
|
||||||
|
{
|
||||||
|
var mockSurveyService = new Mock<ISurveyProvider>();
|
||||||
|
var mockResponse = await MockData.getNoContentResponse();
|
||||||
|
mockSurveyService.Setup(service => service.GetActiveSurveysAsync(true,null)).ReturnsAsync(mockResponse);
|
||||||
|
|
||||||
|
var surveyProvider = new SurveysController(mockSurveyService.Object);
|
||||||
|
var result = (NoContentResult)await surveyProvider.GetActiveSurveysAsync(null);
|
||||||
|
|
||||||
|
Assert.Equal(204, result.StatusCode);
|
||||||
|
}
|
||||||
|
[Fact(DisplayName = "Get inactive Surveys - Ok case")]
|
||||||
|
public async Task GetInActiveSurveysAsync_ShouldReturnStatusCode200()
|
||||||
|
{
|
||||||
|
var mockSurveyService = new Mock<ISurveyProvider>();
|
||||||
|
var mockResponse = await MockData.getOkResponse();
|
||||||
|
mockSurveyService.Setup(service => service.GetActiveSurveysAsync(false, null)).ReturnsAsync(mockResponse);
|
||||||
|
|
||||||
|
var surveyProvider = new SurveysController(mockSurveyService.Object);
|
||||||
|
var result = (OkObjectResult)await surveyProvider.GetInActiveSurveysAsync(null);
|
||||||
|
|
||||||
|
Assert.Equal(200, result.StatusCode);
|
||||||
|
}
|
||||||
|
[Fact(DisplayName = "Get in active Surveys - NoContent Case")]
|
||||||
|
public async Task GetInActiveSurveysAsync_ShouldReturnStatusCode204()
|
||||||
|
{
|
||||||
|
var mockSurveyService = new Mock<ISurveyProvider>();
|
||||||
|
var mockResponse = await MockData.getNoContentResponse();
|
||||||
|
mockSurveyService.Setup(service => service.GetActiveSurveysAsync(false, null)).ReturnsAsync(mockResponse);
|
||||||
|
|
||||||
|
var surveyProvider = new SurveysController(mockSurveyService.Object);
|
||||||
|
var result = (NoContentResult)await surveyProvider.GetInActiveSurveysAsync(null);
|
||||||
|
|
||||||
|
Assert.Equal(204, result.StatusCode);
|
||||||
|
}
|
||||||
[Fact(DisplayName = "Get Survey by Id - Ok case")]
|
[Fact(DisplayName = "Get Survey by Id - Ok case")]
|
||||||
public async Task GetSurveyAsync_ShouldReturnStatusCode200()
|
public async Task GetSurveyAsync_ShouldReturnStatusCode200()
|
||||||
{
|
{
|
||||||
|
@ -29,7 +29,38 @@ namespace DamageAssesment.Api.Surveys.Controllers
|
|||||||
}
|
}
|
||||||
return NoContent();
|
return NoContent();
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// GET request for retrieving all active surveys.
|
||||||
|
/// </summary>
|
||||||
|
[Authorize(Roles = "admin,survey,user,report")]
|
||||||
|
[Route("surveys/active")]
|
||||||
|
[Route("surveys/active/{language:alpha}")]
|
||||||
|
[HttpGet]
|
||||||
|
public async Task<ActionResult> GetActiveSurveysAsync(string? language)
|
||||||
|
{
|
||||||
|
var result = await this.surveyProvider.GetActiveSurveysAsync(true,language);
|
||||||
|
if (result.IsSuccess)
|
||||||
|
{
|
||||||
|
return Ok(result.Surveys);
|
||||||
|
}
|
||||||
|
return NoContent();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// GET request for retrieving all inactive surveys.
|
||||||
|
/// </summary>
|
||||||
|
[Authorize(Roles = "admin,survey,user,report")]
|
||||||
|
[Route("surveys/inactive")]
|
||||||
|
[Route("surveys/inactive/{language:alpha}")]
|
||||||
|
[HttpGet]
|
||||||
|
public async Task<ActionResult> GetInActiveSurveysAsync(string? language)
|
||||||
|
{
|
||||||
|
var result = await this.surveyProvider.GetActiveSurveysAsync(false, language);
|
||||||
|
if (result.IsSuccess)
|
||||||
|
{
|
||||||
|
return Ok(result.Surveys);
|
||||||
|
}
|
||||||
|
return NoContent();
|
||||||
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// GET request for retrieving surveys by ID.
|
/// GET request for retrieving surveys by ID.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -11,10 +11,24 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1" />
|
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.9" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.9">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.9" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.9" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.9">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.21" />
|
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.21" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.5" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.5" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.5" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.5" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
|
||||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.4" />
|
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.4" />
|
||||||
|
<PackageReference Include="Serilog.Extensions.Logging.File" Version="3.0.0" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ using System.ComponentModel.DataAnnotations;
|
|||||||
|
|
||||||
namespace DamageAssesment.Api.Surveys.Db
|
namespace DamageAssesment.Api.Surveys.Db
|
||||||
{
|
{
|
||||||
|
[Table("SurveyTrans")]
|
||||||
public class SurveyTranslation
|
public class SurveyTranslation
|
||||||
{
|
{
|
||||||
[Key]
|
[Key]
|
||||||
|
@ -4,11 +4,18 @@ namespace DamageAssesment.Api.Surveys.Db
|
|||||||
{
|
{
|
||||||
public class SurveysDbContext : DbContext
|
public class SurveysDbContext : DbContext
|
||||||
{
|
{
|
||||||
|
private IConfiguration _Configuration { get; set; }
|
||||||
|
public SurveysDbContext(DbContextOptions options, IConfiguration configuration) : base(options)
|
||||||
|
{
|
||||||
|
_Configuration = configuration;
|
||||||
|
}
|
||||||
|
|
||||||
public DbSet<Db.Survey> Surveys { get; set; }
|
public DbSet<Db.Survey> Surveys { get; set; }
|
||||||
public DbSet<Db.SurveyTranslation> SurveysTranslation { get; set; }
|
public DbSet<Db.SurveyTranslation> SurveysTranslation { get; set; }
|
||||||
public SurveysDbContext(DbContextOptions options) : base(options)
|
protected override void OnConfiguring(DbContextOptionsBuilder options)
|
||||||
{
|
{
|
||||||
|
// connect to sql server with connection string from app settings
|
||||||
|
options.UseSqlServer(_Configuration.GetConnectionString("SurveyConnection"));
|
||||||
}
|
}
|
||||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
public interface ISurveyProvider
|
public interface ISurveyProvider
|
||||||
{
|
{
|
||||||
Task<(bool IsSuccess, IEnumerable< Models.MultiLanSurvey> Surveys, string ErrorMessage)> GetSurveysAsync(string language);
|
Task<(bool IsSuccess, IEnumerable< Models.MultiLanSurvey> Surveys, string ErrorMessage)> GetSurveysAsync(string language);
|
||||||
|
Task<(bool IsSuccess, IEnumerable<Models.MultiLanSurvey> Surveys, string ErrorMessage)> GetActiveSurveysAsync(bool IsActive,string language);
|
||||||
Task<(bool IsSuccess, Models.MultiLanSurvey Surveys, string ErrorMessage)> GetSurveysAsync(int id, string language);
|
Task<(bool IsSuccess, Models.MultiLanSurvey Surveys, string ErrorMessage)> GetSurveysAsync(int id, string language);
|
||||||
Task<(bool IsSuccess, Models.MultiLanSurvey Survey, string ErrorMessage)> PostSurveyAsync(Models.Survey Survey);
|
Task<(bool IsSuccess, Models.MultiLanSurvey Survey, string ErrorMessage)> PostSurveyAsync(Models.Survey Survey);
|
||||||
Task<(bool IsSuccess, Models.MultiLanSurvey Survey, string ErrorMessage)> PutSurveyAsync(int id, Models.Survey Survey);
|
Task<(bool IsSuccess, Models.MultiLanSurvey Survey, string ErrorMessage)> PutSurveyAsync(int id, Models.Survey Survey);
|
||||||
|
@ -9,7 +9,14 @@ using System.Reflection;
|
|||||||
using Microsoft.OpenApi.Models;
|
using Microsoft.OpenApi.Models;
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
builder.Services.AddCors(p => p.AddPolicy("DamageAppCorsPolicy", build => {
|
||||||
|
build.WithOrigins("*").AllowAnyMethod().AllowAnyHeader().AllowAnyOrigin();
|
||||||
|
}));
|
||||||
|
builder.Services.AddLogging(builder =>
|
||||||
|
{
|
||||||
|
//builder.AddConsole(); // Optional: Add other providers if needed
|
||||||
|
builder.AddFile("logs/Surveys-{Date}.txt"); // Specify the file path and format
|
||||||
|
});
|
||||||
// Add services to the container.
|
// Add services to the container.
|
||||||
var authkey = builder.Configuration.GetValue<string>("JwtSettings:securitykey");
|
var authkey = builder.Configuration.GetValue<string>("JwtSettings:securitykey");
|
||||||
builder.Services.AddAuthentication(item =>
|
builder.Services.AddAuthentication(item =>
|
||||||
@ -75,7 +82,7 @@ builder.Services.AddSwaggerGen(options =>
|
|||||||
|
|
||||||
builder.Services.AddDbContext<SurveysDbContext>(option =>
|
builder.Services.AddDbContext<SurveysDbContext>(option =>
|
||||||
{
|
{
|
||||||
option.UseInMemoryDatabase("Surveys");
|
option.UseSqlServer("SurveyConnection");
|
||||||
});
|
});
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
@ -93,6 +100,7 @@ if (app.Environment.IsDevelopment())
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
app.UseCors("DamageAppCorsPolicy");
|
||||||
app.UseAuthentication();
|
app.UseAuthentication();
|
||||||
app.UseAuthorization();
|
app.UseAuthorization();
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ namespace DamageAssesment.Api.Surveys.Providers
|
|||||||
surveyDbContext.SurveysTranslation.Add(new Db.SurveyTranslation { SurveyId = survey2.Id, Language = "en", Title = "Hurricane Andrew Aftermath Survey" });
|
surveyDbContext.SurveysTranslation.Add(new Db.SurveyTranslation { SurveyId = survey2.Id, Language = "en", Title = "Hurricane Andrew Aftermath Survey" });
|
||||||
surveyDbContext.SurveysTranslation.Add(new Db.SurveyTranslation { SurveyId = survey2.Id, Language = "es", Title = "Encuesta sobre las secuelas del huracán Andrew" });
|
surveyDbContext.SurveysTranslation.Add(new Db.SurveyTranslation { SurveyId = survey2.Id, Language = "es", Title = "Encuesta sobre las secuelas del huracán Andrew" });
|
||||||
surveyDbContext.SurveysTranslation.Add(new Db.SurveyTranslation { SurveyId = survey2.Id, Language = "fr", Title = "Enquête sur les conséquences de l'ouragan Andrew" });
|
surveyDbContext.SurveysTranslation.Add(new Db.SurveyTranslation { SurveyId = survey2.Id, Language = "fr", Title = "Enquête sur les conséquences de l'ouragan Andrew" });
|
||||||
|
|
||||||
surveyDbContext.SurveysTranslation.Add(new Db.SurveyTranslation { SurveyId = survey3.Id, Language = "en", Title = "Hurricane Irma" });
|
surveyDbContext.SurveysTranslation.Add(new Db.SurveyTranslation { SurveyId = survey3.Id, Language = "en", Title = "Hurricane Irma" });
|
||||||
surveyDbContext.SurveysTranslation.Add(new Db.SurveyTranslation { SurveyId = survey3.Id, Language = "es", Title = "Huracán Irma" });
|
surveyDbContext.SurveysTranslation.Add(new Db.SurveyTranslation { SurveyId = survey3.Id, Language = "es", Title = "Huracán Irma" });
|
||||||
surveyDbContext.SurveysTranslation.Add(new Db.SurveyTranslation { SurveyId = survey3.Id, Language = "fr", Title = "Ouragan Irma" });
|
surveyDbContext.SurveysTranslation.Add(new Db.SurveyTranslation { SurveyId = survey3.Id, Language = "fr", Title = "Ouragan Irma" });
|
||||||
@ -85,7 +85,7 @@ namespace DamageAssesment.Api.Surveys.Providers
|
|||||||
MultiLanguage = dict;
|
MultiLanguage = dict;
|
||||||
return MultiLanguage;
|
return MultiLanguage;
|
||||||
}
|
}
|
||||||
public string GetStatus(DateTime? StartDate, DateTime? EndDate)
|
public string GetStatus(DateTime? StartDate,DateTime? EndDate)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -101,12 +101,15 @@ namespace DamageAssesment.Api.Surveys.Providers
|
|||||||
return SurveyStatus.INACTIVE.ToString();
|
return SurveyStatus.INACTIVE.ToString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Method to get surveys asynchronously with multi-language support
|
// Method to get surveys asynchronously with multi-language support
|
||||||
public async Task<(bool IsSuccess, IEnumerable<Models.MultiLanSurvey> Surveys, string ErrorMessage)> GetSurveysAsync(string language)
|
public async Task<(bool IsSuccess, IEnumerable<Models.MultiLanSurvey> Surveys, string ErrorMessage)> GetActiveSurveysAsync(bool IsActive,string language)
|
||||||
{
|
{
|
||||||
IEnumerable<Models.MultiLanSurvey> surveysList = null;
|
IEnumerable<Models.MultiLanSurvey> surveysList = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
string status = SurveyStatus.ACTIVE.ToString();
|
||||||
|
if(!IsActive) status = SurveyStatus.INACTIVE.ToString();
|
||||||
logger?.LogInformation("Get all Surveys from DB");
|
logger?.LogInformation("Get all Surveys from DB");
|
||||||
//checking is enabled in survey response
|
//checking is enabled in survey response
|
||||||
var surveys = await surveyDbContext.Surveys.ToListAsync();//Where(s => s.IsEnabled == true)
|
var surveys = await surveyDbContext.Surveys.ToListAsync();//Where(s => s.IsEnabled == true)
|
||||||
@ -124,6 +127,39 @@ namespace DamageAssesment.Api.Surveys.Providers
|
|||||||
Status = GetStatus(s.StartDate, s.EndDate),
|
Status = GetStatus(s.StartDate, s.EndDate),
|
||||||
Titles = CreateMultiLanguageObject(GetSurveyTranslations(s.Id, null, language))
|
Titles = CreateMultiLanguageObject(GetSurveyTranslations(s.Id, null, language))
|
||||||
};
|
};
|
||||||
|
logger?.LogInformation($"{surveys.Count} Items(s) found");
|
||||||
|
return (true, surveysList.Where(a=>a.Status==status).OrderByDescending(a=>a.Id), null);
|
||||||
|
}
|
||||||
|
return (false, null, "Not found");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
logger?.LogError(ex.ToString());
|
||||||
|
return (false, null, ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Method to get surveys asynchronously with multi-language support
|
||||||
|
public async Task<(bool IsSuccess, IEnumerable<Models.MultiLanSurvey> Surveys, string ErrorMessage)> GetSurveysAsync(string language)
|
||||||
|
{
|
||||||
|
IEnumerable<Models.MultiLanSurvey> surveysList = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
logger?.LogInformation("Get all Surveys from DB");
|
||||||
|
//checking is enabled in survey response
|
||||||
|
var surveys = await surveyDbContext.Surveys.ToListAsync();//Where(s => s.IsEnabled == true)
|
||||||
|
if (surveys != null)
|
||||||
|
{
|
||||||
|
surveysList = from s in surveys
|
||||||
|
select new Models.MultiLanSurvey
|
||||||
|
{
|
||||||
|
Id = s.Id,
|
||||||
|
StartDate = s.StartDate,
|
||||||
|
EndDate = s.EndDate,
|
||||||
|
IsEnabled = s.IsEnabled,
|
||||||
|
CreatedDate = s.CreatedDate,
|
||||||
|
Status= GetStatus(s.StartDate,s.EndDate),
|
||||||
|
Titles = CreateMultiLanguageObject(GetSurveyTranslations(s.Id, null, language))
|
||||||
|
};
|
||||||
|
|
||||||
logger?.LogInformation($"{surveys.Count} Items(s) found");
|
logger?.LogInformation($"{surveys.Count} Items(s) found");
|
||||||
return (true, surveysList, null);
|
return (true, surveysList, null);
|
||||||
|
@ -1,8 +0,0 @@
|
|||||||
{
|
|
||||||
"Logging": {
|
|
||||||
"LogLevel": {
|
|
||||||
"Default": "Information",
|
|
||||||
"Microsoft.AspNetCore": "Warning"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -8,5 +8,10 @@
|
|||||||
"Microsoft.AspNetCore": "Warning"
|
"Microsoft.AspNetCore": "Warning"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"AllowedHosts": "*"
|
"AllowedHosts": "*",
|
||||||
|
"ConnectionStrings": {
|
||||||
|
//"SurveyConnection": "Server=DESKTOP-OF5DPLQ\\SQLEXPRESS;Database=da_survey_dev;Trusted_Connection=True;TrustServerCertificate=True;"
|
||||||
|
"SurveyConnection": "Server=207.180.248.35;Database=da_survey_dev;User Id=sa;Password=YourStrongPassw0rd;TrustServerCertificate=True;"
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,9 +18,9 @@ namespace DamageAssesment.Api.UsersAccess.Test
|
|||||||
public async Task GetTokenAsync_ShouldReturnStatusCode200()
|
public async Task GetTokenAsync_ShouldReturnStatusCode200()
|
||||||
{
|
{
|
||||||
var response = await MockData.getTokenResponse(true,null);
|
var response = await MockData.getTokenResponse(true,null);
|
||||||
mockService.Setup(service => service.AuthenticateAsync("Emp1")).ReturnsAsync(response);
|
mockService.Setup(service => service.AuthenticateAsync()).ReturnsAsync(response);
|
||||||
var controller = new UsersAccessController(mockService.Object);
|
var controller = new UsersAccessController(mockService.Object);
|
||||||
var result = (OkObjectResult)await controller.AuthenticateAsync("Emp1");
|
var result = (OkObjectResult)await controller.AuthenticateAsync();
|
||||||
Assert.Equal(200, result.StatusCode);
|
Assert.Equal(200, result.StatusCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -28,9 +28,9 @@ namespace DamageAssesment.Api.UsersAccess.Test
|
|||||||
public async Task GetTokenAsync_ShouldReturnStatusCode401()
|
public async Task GetTokenAsync_ShouldReturnStatusCode401()
|
||||||
{
|
{
|
||||||
var response = await MockData.getTokenResponse(false, null);
|
var response = await MockData.getTokenResponse(false, null);
|
||||||
mockService.Setup(service => service.AuthenticateAsync("Emp1")).ReturnsAsync(response);
|
mockService.Setup(service => service.AuthenticateAsync()).ReturnsAsync(response);
|
||||||
var controller = new UsersAccessController(mockService.Object);
|
var controller = new UsersAccessController(mockService.Object);
|
||||||
var result = (UnauthorizedObjectResult)await controller.AuthenticateAsync("Emp1");
|
var result = (UnauthorizedObjectResult)await controller.AuthenticateAsync();
|
||||||
Assert.Equal(401, result.StatusCode);
|
Assert.Equal(401, result.StatusCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,36 +8,38 @@ namespace DamageAssesment.Api.UsersAccess.Controllers
|
|||||||
[ApiController]
|
[ApiController]
|
||||||
public class UsersAccessController : ControllerBase
|
public class UsersAccessController : ControllerBase
|
||||||
{
|
{
|
||||||
private IUsersAccessProvider userAccessProvider;
|
private readonly IUsersAccessProvider userAccessProvider;
|
||||||
|
|
||||||
public UsersAccessController(IUsersAccessProvider userAccessProvider)
|
public UsersAccessController(IUsersAccessProvider userAccessProvider)
|
||||||
{
|
{
|
||||||
this.userAccessProvider = userAccessProvider;
|
this.userAccessProvider = userAccessProvider;
|
||||||
}
|
}
|
||||||
[HttpPost("dadeschooltoken")]
|
[HttpPost("dadeschools/token")]
|
||||||
public async Task<ActionResult> DadeSchoolAuthenticateAsync(string username, string password)
|
public async Task<ActionResult> DadeSchoolAuthenticateAsync(UserCredentials userCredentials)
|
||||||
{
|
{
|
||||||
var result = await userAccessProvider.DadeSchoolAuthenticateAsync(username, password);
|
var result = await userAccessProvider.AuthenticateAsync(userCredentials.username, userCredentials.password);
|
||||||
|
|
||||||
if (result.IsSuccess)
|
if (result.IsSuccess)
|
||||||
{
|
{
|
||||||
return Ok(result.TokenResponse);
|
return Ok(result.TokenResponse);
|
||||||
}
|
}
|
||||||
return Unauthorized(result.ErrorMessage);
|
return Unauthorized(result.ErrorMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Authorize(Policy = "Dadeschools")]
|
[Authorize(Policy = "Dadeschools")]
|
||||||
[HttpPost("token/{employecode}")]
|
[HttpGet("damageapp/token")]
|
||||||
public async Task<ActionResult> AuthenticateAsync(string employecode)
|
public async Task<ActionResult> AuthenticateAsync()
|
||||||
{
|
{
|
||||||
var result = await userAccessProvider.AuthenticateAsync(employecode);
|
var result = await userAccessProvider.AuthenticateAsync();
|
||||||
if (result.IsSuccess)
|
if (result.IsSuccess)
|
||||||
{
|
{
|
||||||
return Ok(result.TokenResponse);
|
return Ok(result.TokenResponse);
|
||||||
}
|
}
|
||||||
return Unauthorized(result.ErrorMessage);
|
return Unauthorized(result.ErrorMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Authorize(Policy = "Dadeschools")]
|
[Authorize(Policy = "Dadeschools")]
|
||||||
[HttpPost("refreshtoken")]
|
[HttpPost("damageapp/refreshtoken")]
|
||||||
public async Task<ActionResult> RefreshTokenAsync(TokenResponse tokenResponse)
|
public async Task<ActionResult> RefreshTokenAsync(TokenResponse tokenResponse)
|
||||||
{
|
{
|
||||||
var result = await userAccessProvider.RefreshTokenAsync(tokenResponse);
|
var result = await userAccessProvider.RefreshTokenAsync(tokenResponse);
|
||||||
@ -48,7 +50,7 @@ namespace DamageAssesment.Api.UsersAccess.Controllers
|
|||||||
return Unauthorized(result.ErrorMessage);
|
return Unauthorized(result.ErrorMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Authorize(Policy = "DamageApp", Roles ="admin")]
|
[Authorize(Policy = "DamageApp", Roles = "admin")]
|
||||||
[HttpGet("users")]
|
[HttpGet("users")]
|
||||||
public async Task<ActionResult> GetUsersAsync()
|
public async Task<ActionResult> GetUsersAsync()
|
||||||
{
|
{
|
||||||
@ -60,7 +62,7 @@ namespace DamageAssesment.Api.UsersAccess.Controllers
|
|||||||
return NoContent();
|
return NoContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Authorize(Policy = "DamageApp", Roles = "admin")]
|
// [Authorize(Policy = "DamageApp", Roles = "admin")]
|
||||||
[HttpGet("users/{Id}")]
|
[HttpGet("users/{Id}")]
|
||||||
public async Task<ActionResult> GetUsersAsync(int Id)
|
public async Task<ActionResult> GetUsersAsync(int Id)
|
||||||
{
|
{
|
||||||
@ -72,7 +74,7 @@ namespace DamageAssesment.Api.UsersAccess.Controllers
|
|||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Authorize(Policy = "DamageApp", Roles = "admin")]
|
//[Authorize(Policy = "DamageApp", Roles = "admin")]
|
||||||
[HttpGet("roles")]
|
[HttpGet("roles")]
|
||||||
public async Task<ActionResult> GetRolesAsync()
|
public async Task<ActionResult> GetRolesAsync()
|
||||||
{
|
{
|
||||||
@ -83,7 +85,7 @@ namespace DamageAssesment.Api.UsersAccess.Controllers
|
|||||||
}
|
}
|
||||||
return NoContent();
|
return NoContent();
|
||||||
}
|
}
|
||||||
[Authorize(Policy = "DamageApp", Roles = "admin")]
|
//[Authorize(Policy = "DamageApp", Roles = "admin")]
|
||||||
[HttpPost("users")]
|
[HttpPost("users")]
|
||||||
public async Task<ActionResult> PostUserAsync(User user)
|
public async Task<ActionResult> PostUserAsync(User user)
|
||||||
{
|
{
|
||||||
@ -95,7 +97,7 @@ namespace DamageAssesment.Api.UsersAccess.Controllers
|
|||||||
return BadRequest(result.ErrorMessage);
|
return BadRequest(result.ErrorMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Authorize(Policy = "DamageApp", Roles = "admin")]
|
//[Authorize(Policy = "DamageApp", Roles = "admin")]
|
||||||
[HttpPut("users/{Id}")]
|
[HttpPut("users/{Id}")]
|
||||||
public async Task<ActionResult> PutUserAsync(int Id, User user)
|
public async Task<ActionResult> PutUserAsync(int Id, User user)
|
||||||
{
|
{
|
||||||
|
@ -12,12 +12,25 @@
|
|||||||
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1" />
|
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1" />
|
||||||
<PackageReference Include="IdentityServer4.AccessTokenValidation" Version="3.0.1" />
|
<PackageReference Include="IdentityServer4.AccessTokenValidation" Version="3.0.1" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.21" />
|
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.21" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.5" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.9" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.5" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.9">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.9" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.9" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.9">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="7.0.10" />
|
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="7.0.10" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
|
||||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.18.1" />
|
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.18.1" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
|
<PackageReference Include="Serilog.Extensions.Logging.File" Version="3.0.0" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
|
||||||
|
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.21.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
|
||||||
namespace DamageAssesment.Api.UsersAccess.Db
|
namespace DamageAssesment.Api.UsersAccess.Db
|
||||||
{
|
{
|
||||||
@ -7,9 +8,15 @@ namespace DamageAssesment.Api.UsersAccess.Db
|
|||||||
public DbSet<Db.User> Users { get; set; }
|
public DbSet<Db.User> Users { get; set; }
|
||||||
public DbSet<Db.Role> Roles { get; set; }
|
public DbSet<Db.Role> Roles { get; set; }
|
||||||
public DbSet<Db.Token> Tokens { get; set; }
|
public DbSet<Db.Token> Tokens { get; set; }
|
||||||
public UsersAccessDbContext(DbContextOptions options) : base(options)
|
private IConfiguration _Configuration { get; set; }
|
||||||
|
public UsersAccessDbContext(DbContextOptions options, IConfiguration configuration) : base(options)
|
||||||
{
|
{
|
||||||
|
_Configuration = configuration;
|
||||||
|
}
|
||||||
|
protected override void OnConfiguring(DbContextOptionsBuilder options)
|
||||||
|
{
|
||||||
|
// connect to sql server with connection string from app settings
|
||||||
|
options.UseSqlServer(_Configuration.GetConnectionString("UsersAccessConnection"));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
using DamageAssesment.Api.UsersAccess.Models;
|
using DamageAssesment.Api.UsersAccess.Models;
|
||||||
|
|
||||||
namespace DamageAssesment.Api.UsersAccess.Interfaces
|
namespace DamageAssesment.Api.UsersAccess.Interfaces
|
||||||
{
|
{
|
||||||
public interface IEmployeeServiceProvider
|
public interface IEmployeeServiceProvider
|
||||||
{
|
{
|
||||||
Task<List<Employee>> getEmployeesAsync();
|
Task<List<Employee>> getEmployeesAsync(string token);
|
||||||
Task<Employee> getEmployeeAsync(int employeeId);
|
Task<Employee> getEmployeeAsync(int employeeId, string token);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +0,0 @@
|
|||||||
using DamageAssesment.Api.UsersAccess.Models;
|
|
||||||
|
|
||||||
namespace DamageAssesment.Api.UsersAccess.Interfaces
|
|
||||||
{
|
|
||||||
public interface IHttpUtil
|
|
||||||
{
|
|
||||||
Task<string> SendAsync(HttpMethod method, string url, string JsonInput);
|
|
||||||
}
|
|
||||||
}
|
|
@ -7,5 +7,7 @@ namespace DamageAssesment.Api.UsersAccess.Interfaces
|
|||||||
{
|
{
|
||||||
Task<string> GenerateToken(Models.User user);
|
Task<string> GenerateToken(Models.User user);
|
||||||
Task<TokenResponse> TokenAuthenticate(Models.User user, Claim[] claims);
|
Task<TokenResponse> TokenAuthenticate(Models.User user, Claim[] claims);
|
||||||
|
|
||||||
|
Task<string> ConvertJsonToDadeSchoolsJwt(string json);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -4,14 +4,15 @@ namespace DamageAssesment.Api.UsersAccess.Interfaces
|
|||||||
{
|
{
|
||||||
public interface IUsersAccessProvider
|
public interface IUsersAccessProvider
|
||||||
{
|
{
|
||||||
public Task<(bool IsSuccess, IEnumerable< Models.User> Users, string ErrorMessage)> GetUsersAsync();
|
public Task<(bool IsSuccess, IEnumerable<object> Users, string ErrorMessage)> GetUsersAsync();
|
||||||
public Task<(bool IsSuccess, Models.User User, string ErrorMessage)> GetUsersAsync(int Id);
|
public Task<(bool IsSuccess, object 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)> 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)> PutUserAsync(int Id,Models.User User);
|
||||||
public Task<(bool IsSuccess, Models.User User, string ErrorMessage)> DeleteUserAsync(int Id);
|
public Task<(bool IsSuccess, Models.User User, string ErrorMessage)> DeleteUserAsync(int Id);
|
||||||
public Task<(bool IsSuccess, IEnumerable<Models.Role> Roles, string ErrorMessage)> GetRolesAsync();
|
public Task<(bool IsSuccess, IEnumerable<Models.Role> Roles, string ErrorMessage)> GetRolesAsync();
|
||||||
public Task<(bool IsSuccess, Models.TokenResponse TokenResponse, string ErrorMessage)> AuthenticateAsync(string employeCode);
|
public Task<(bool IsSuccess, Models.TokenResponse TokenResponse, string ErrorMessage)> AuthenticateAsync();
|
||||||
public Task<(bool IsSuccess, Models.DadeSchoolToken TokenResponse, string ErrorMessage)> DadeSchoolAuthenticateAsync(string username, string password);
|
public Task<(bool IsSuccess, DadeSchoolToken TokenResponse, string ErrorMessage)> AuthenticateAsync(string username, string password);
|
||||||
|
|
||||||
public Task<(bool IsSuccess, Models.TokenResponse TokenResponse, string ErrorMessage)>RefreshTokenAsync(TokenResponse tokenResponse);
|
public Task<(bool IsSuccess, Models.TokenResponse TokenResponse, string ErrorMessage)>RefreshTokenAsync(TokenResponse tokenResponse);
|
||||||
public void seedData();
|
public void seedData();
|
||||||
}
|
}
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user