forked from MDCPS/DamageAssessment_Backend
Compare commits
21 Commits
user-acces
...
user-acces
Author | SHA1 | Date | |
---|---|---|---|
fe5e3129b5 | |||
86dea1b942 | |||
5507bd7999 | |||
d2627645b0 | |||
e93168f1df | |||
1bf92fe95d | |||
2604c6fd4a | |||
42295d68df | |||
b7ba8c499c | |||
f8912ce31a | |||
eb0df19522 | |||
126da500a1 | |||
c80749e292 | |||
6f10e99627 | |||
b569f6d404 | |||
94ea46c466 | |||
15acd00959 | |||
46520c7e62 | |||
f6387fc371 | |||
4ebd40108d | |||
77816605d1 |
Binary file not shown.
@ -1,7 +0,0 @@
|
|||||||
{
|
|
||||||
"ExpandedNodes": [
|
|
||||||
""
|
|
||||||
],
|
|
||||||
"SelectedNode": "\\DamageAssesment.sln",
|
|
||||||
"PreviewInSolutionExplorer": false
|
|
||||||
}
|
|
1
DamageAssesmentApi/.gitignore
vendored
1
DamageAssesmentApi/.gitignore
vendored
@ -396,4 +396,3 @@ FodyWeavers.xsd
|
|||||||
|
|
||||||
# JetBrains Rider
|
# JetBrains Rider
|
||||||
*.sln.iml
|
*.sln.iml
|
||||||
**/migrations/
|
|
@ -13,12 +13,7 @@
|
|||||||
<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.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.4" />
|
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.4" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
@ -3,7 +3,6 @@ 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,19 +1,13 @@
|
|||||||
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,IConfiguration configuration):base(options)
|
public AnswerDbContext(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("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)
|
||||||
|
@ -73,7 +73,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.UseSqlServer("AnswerConnection");
|
option.UseInMemoryDatabase("Answers");
|
||||||
});
|
});
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
@ -198,12 +198,13 @@ namespace DamageAssesment.Api.Answers.Providers
|
|||||||
{
|
{
|
||||||
if (!answerDbContext.Answers.Any())
|
if (!answerDbContext.Answers.Any())
|
||||||
{
|
{
|
||||||
answerDbContext.Answers.Add(new Db.Answer() { AnswerText = "Yes", Comment = "", QuestionId = 1, SurveyResponseId = 1 });
|
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 = "No", Comment = "myComment", QuestionId = 2, 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 = "No Comment", QuestionId = 3, SurveyResponseId = 1 });
|
// Uncomment the lines below to add more initial data if needed
|
||||||
//answerDbContext.Answers.Add(new Db.Answer() { AnswerText = "Yes", Comment = "No Comment", QuestionId = 1, SurveyResponseId = 2 });
|
//answerDbContext.Answers.Add(new Db.Answer() { Id = 3, AnswerText = "No", Comment = "No Comment", QuestionId = 3, SurveyResponseId = 1 });
|
||||||
//answerDbContext.Answers.Add(new Db.Answer() { AnswerText = "No", Comment = "No Comment", QuestionId = 2, 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 = 3, 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() { Id = 6, AnswerText = "No", Comment = "No Comment", QuestionId = 3, SurveyResponseId = 2 });
|
||||||
answerDbContext.SaveChanges();
|
answerDbContext.SaveChanges();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"Logging": {
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Information",
|
||||||
|
"Microsoft.AspNetCore": "Warning"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -8,10 +8,5 @@
|
|||||||
"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;"
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -13,12 +13,11 @@ 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.
|
||||||
|
@ -14,19 +14,8 @@
|
|||||||
<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.9" />
|
<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.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.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.4" />
|
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.4" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
@ -3,7 +3,6 @@ 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,19 +1,11 @@
|
|||||||
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
|
||||||
{
|
{
|
||||||
private IConfiguration _Configuration { get; set; }
|
public AttachmentsDbContext(DbContextOptions options) : base(options)
|
||||||
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,15 +1,10 @@
|
|||||||
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);
|
||||||
Task<List<Attachment>> UploadAttachment(int responseId, int answerId, int counter, List<IFormFile> postedFile);
|
void DeleteFile(string path);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -78,7 +78,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.UseSqlServer("AttachmentConnection");
|
option.UseInMemoryDatabase("Attachments");
|
||||||
});
|
});
|
||||||
builder.Services.Configure<FormOptions>(o =>
|
builder.Services.Configure<FormOptions>(o =>
|
||||||
{
|
{
|
||||||
|
@ -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,9 +3,6 @@ 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
|
||||||
{
|
{
|
||||||
@ -13,95 +10,11 @@ namespace DamageAssesment.Api.Attachments.Providers
|
|||||||
{
|
{
|
||||||
BlobServiceClient _blobClient;
|
BlobServiceClient _blobClient;
|
||||||
BlobContainerClient _containerClient;
|
BlobContainerClient _containerClient;
|
||||||
string azureConnectionString;
|
string azureConnectionString = "<Primary Connection String>";
|
||||||
private string uploadpath = "";
|
public AzureBlobService()
|
||||||
private string Deletepath = "";
|
|
||||||
public AzureBlobService(IConfiguration configuration)
|
|
||||||
{
|
{
|
||||||
uploadpath = configuration.GetValue<string>("Fileupload:folderpath");
|
_blobClient = new BlobServiceClient(azureConnectionString);
|
||||||
Deletepath = configuration.GetValue<string>("Fileupload:Deletepath");
|
_containerClient = _blobClient.GetBlobContainerClient("apiimages");
|
||||||
_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)
|
||||||
@ -122,52 +35,10 @@ namespace DamageAssesment.Api.Attachments.Providers
|
|||||||
|
|
||||||
return azureResponse;
|
return azureResponse;
|
||||||
}
|
}
|
||||||
public string getMovefilename(string movefilename)
|
public void DeleteFile(string url)
|
||||||
{
|
{
|
||||||
var list = movefilename.Split('.');
|
var blob = _containerClient.GetBlockBlobClient(url);
|
||||||
if (list.Length > 0)
|
blob.DeleteIfExists();
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"Logging": {
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Information",
|
||||||
|
"Microsoft.AspNetCore": "Warning"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -11,14 +11,6 @@
|
|||||||
"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;"
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -5,6 +5,7 @@ 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
|
||||||
{
|
{
|
||||||
@ -13,7 +14,6 @@ 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,9 +42,9 @@ 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);
|
||||||
@ -206,6 +206,7 @@ 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}")]
|
||||||
@ -222,6 +223,7 @@ 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]
|
||||||
@ -252,7 +254,7 @@ namespace DamageAssesment.Api.DocuLinks.Controllers
|
|||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// update existing doclink.
|
/// Upload new document.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Authorize(Roles = "admin")]
|
[Authorize(Roles = "admin")]
|
||||||
[HttpPut]
|
[HttpPut]
|
||||||
@ -294,7 +296,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)
|
||||||
@ -320,7 +322,7 @@ namespace DamageAssesment.Api.DocuLinks.Controllers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Delete Doculink by id.
|
/// Delete document by id.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Authorize(Roles = "admin")]
|
[Authorize(Roles = "admin")]
|
||||||
[HttpDelete]
|
[HttpDelete]
|
||||||
|
@ -0,0 +1 @@
|
|||||||
|
sample
|
@ -0,0 +1 @@
|
|||||||
|
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.18.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.9" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.9" />
|
||||||
|
@ -3,7 +3,6 @@ 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,7 +3,6 @@ using System.ComponentModel.DataAnnotations;
|
|||||||
|
|
||||||
namespace DamageAssesment.Api.DocuLinks.Db
|
namespace DamageAssesment.Api.DocuLinks.Db
|
||||||
{
|
{
|
||||||
[Table("DoculinkAttachments")]
|
|
||||||
public class DoculinkAttachments
|
public class DoculinkAttachments
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -7,15 +7,8 @@ namespace DamageAssesment.Api.DocuLinks.Db
|
|||||||
{
|
{
|
||||||
public class DoculinkDbContext : DbContext
|
public class DoculinkDbContext : DbContext
|
||||||
{
|
{
|
||||||
private IConfiguration _Configuration { get; set; }
|
public DoculinkDbContext(DbContextOptions options) : base(options)
|
||||||
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,7 +3,6 @@ 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,9 +1,7 @@
|
|||||||
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,7 +3,6 @@ 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,14 +1,10 @@
|
|||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -76,7 +76,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.UseSqlServer("DoculinkConnection");
|
option.UseInMemoryDatabase("DocumentConnection");
|
||||||
});
|
});
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
"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,17 +1,8 @@
|
|||||||
|
|
||||||
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
|
||||||
{
|
{
|
||||||
@ -19,111 +10,11 @@ namespace DamageAssesment.Api.DocuLinks.Providers
|
|||||||
{
|
{
|
||||||
BlobServiceClient _blobClient;
|
BlobServiceClient _blobClient;
|
||||||
BlobContainerClient _containerClient;
|
BlobContainerClient _containerClient;
|
||||||
string azureConnectionString;
|
string azureConnectionString = "<Primary Connection String>";
|
||||||
private string uploadpath = "";
|
public AzureBlobService()
|
||||||
private string Deletepath = "";
|
|
||||||
public AzureBlobService(IConfiguration configuration)
|
|
||||||
{
|
{
|
||||||
uploadpath = configuration.GetValue<string>("Fileupload:folderpath");
|
_blobClient = new BlobServiceClient(azureConnectionString);
|
||||||
Deletepath = configuration.GetValue<string>("Fileupload:Deletepath");
|
_containerClient = _blobClient.GetBlobContainerClient("apiimages");
|
||||||
_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)
|
||||||
@ -144,52 +35,10 @@ 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)
|
||||||
{
|
{
|
||||||
BlobClient sourceBlobClient = _containerClient.GetBlobClient(url);
|
var blob = _containerClient.GetBlockBlobClient(url);
|
||||||
sourceBlobClient.DeleteIfExists();
|
blob.DeleteIfExists();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -24,12 +24,11 @@ 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, IAzureBlobService azureBlobService, IHttpContextAccessor httpContextAccessor)
|
public DoculinkProvider(DoculinkDbContext DocumentDbContext, ILogger<DoculinkProvider> logger, IMapper mapper, IUploadService uploadservice, IHttpContextAccessor httpContextAccessor)
|
||||||
{
|
{
|
||||||
this.DocumentDbContext = DocumentDbContext;
|
this.DocumentDbContext = DocumentDbContext;
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
@ -38,13 +37,12 @@ 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";
|
||||||
this.azureBlobService = azureBlobService;
|
SeedData();
|
||||||
//SeedData();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private async Task SeedDataAsync()
|
private void SeedData()
|
||||||
{
|
{
|
||||||
if (!DocumentDbContext.LinkTypes.Any())
|
if (!DocumentDbContext.LinkTypes.Any())
|
||||||
{
|
{
|
||||||
|
@ -116,16 +116,15 @@ 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}{2}", document.Id, counter1, item.FileExtension);
|
var fileName = String.Format("Document_{0}{1}", counter, 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;
|
||||||
|
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"Logging": {
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Information",
|
||||||
|
"Microsoft.AspNetCore": "Warning"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +1,4 @@
|
|||||||
{
|
{
|
||||||
"JwtSettings": {
|
|
||||||
"securitykey": "bWlhbWkgZGFkZSBzY2hvb2xzIHNlY3JldCBrZXk="
|
|
||||||
},
|
|
||||||
"Logging": {
|
"Logging": {
|
||||||
"LogLevel": {
|
"LogLevel": {
|
||||||
"Default": "Information",
|
"Default": "Information",
|
||||||
@ -9,15 +6,12 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"AllowedHosts": "*",
|
"AllowedHosts": "*",
|
||||||
"ConnectionStrings": {
|
"JwtSettings": {
|
||||||
//"DoculinkConnection": "Server=DESKTOP-OF5DPLQ\\SQLEXPRESS;Database=da_survey_dev;Trusted_Connection=True;TrustServerCertificate=True;"
|
"securitykey": "bWlhbWkgZGFkZSBzY2hvb2xzIHNlY3JldCBrZXk="
|
||||||
"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,18 +12,8 @@
|
|||||||
<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.9" />
|
<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.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.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.4" />
|
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.4" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
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,23 +4,18 @@ namespace DamageAssesment.Api.Employees.Db
|
|||||||
{
|
{
|
||||||
public class EmployeeDbContext: DbContext
|
public class EmployeeDbContext: DbContext
|
||||||
{
|
{
|
||||||
private IConfiguration _Configuration { get; set; }
|
public DbSet<Db.Employee> Employees { get; set; }
|
||||||
public EmployeeDbContext(DbContextOptions options, IConfiguration configuration) : base(options)
|
public EmployeeDbContext(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("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; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -75,7 +75,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.UseSqlServer("EmployeeConnection");
|
option.UseInMemoryDatabase("Employees");
|
||||||
});
|
});
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"Logging": {
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Information",
|
||||||
|
"Microsoft.AspNetCore": "Warning"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -8,10 +8,5 @@
|
|||||||
"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,17 +11,6 @@
|
|||||||
|
|
||||||
<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" />
|
||||||
|
@ -3,7 +3,6 @@ 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,16 +4,6 @@ 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,9 +1,7 @@
|
|||||||
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]
|
||||||
|
@ -74,7 +74,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.UseSqlServer("LocationConnection");
|
option.UseInMemoryDatabase("Locations");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"Logging": {
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Information",
|
||||||
|
"Microsoft.AspNetCore": "Warning"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -8,10 +8,5 @@
|
|||||||
"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;"
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -11,17 +11,6 @@
|
|||||||
|
|
||||||
<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" />
|
||||||
|
@ -3,7 +3,6 @@ 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,7 +3,6 @@ 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,10 +1,8 @@
|
|||||||
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,16 +6,6 @@ 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,9 +1,7 @@
|
|||||||
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,7 +3,6 @@ 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]
|
||||||
|
@ -76,7 +76,7 @@ builder.Services.AddSwaggerGen(options =>
|
|||||||
|
|
||||||
builder.Services.AddDbContext<QuestionDbContext>(option =>
|
builder.Services.AddDbContext<QuestionDbContext>(option =>
|
||||||
{
|
{
|
||||||
option.UseSqlServer("QuestionConnection");
|
option.UseInMemoryDatabase("Questions");
|
||||||
});
|
});
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
|
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"Logging": {
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Information",
|
||||||
|
"Microsoft.AspNetCore": "Warning"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -8,10 +8,5 @@
|
|||||||
"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.9" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.5" />
|
||||||
<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" />
|
||||||
|
@ -89,6 +89,5 @@ namespace DamageAssesment.Api.Questions.Test
|
|||||||
Questions.Add(question);
|
Questions.Add(question);
|
||||||
return Questions;
|
return Questions;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -356,5 +356,6 @@ namespace DamageAssesment.Api.Questions.Test
|
|||||||
|
|
||||||
Assert.Equal(404, result.StatusCode);
|
Assert.Equal(404, result.StatusCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -11,21 +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="ClosedXML" Version="0.102.1" />
|
<PackageReference Include="EPPlus" Version="7.0.0" />
|
||||||
<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" />
|
||||||
|
@ -3,7 +3,6 @@ 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,18 +4,13 @@ namespace DamageAssesment.Api.Responses.Db
|
|||||||
{
|
{
|
||||||
public class SurveyResponseDbContext:DbContext
|
public class SurveyResponseDbContext:DbContext
|
||||||
{
|
{
|
||||||
private IConfiguration _Configuration { get; set; }
|
|
||||||
public SurveyResponseDbContext(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("ResponsesConnection"));
|
|
||||||
}
|
|
||||||
public DbSet<Db.SurveyResponse> SurveyResponses { get; set; }
|
public DbSet<Db.SurveyResponse> SurveyResponses { get; set; }
|
||||||
|
|
||||||
|
public SurveyResponseDbContext(DbContextOptions options) : base(options)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
base.OnModelCreating(modelBuilder);
|
base.OnModelCreating(modelBuilder);
|
||||||
|
@ -48,8 +48,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.AddScoped<IExcelExportService, ExcelExportService>();
|
|
||||||
builder.Services.AddHttpContextAccessor();
|
builder.Services.AddHttpContextAccessor();
|
||||||
|
builder.Services.AddScoped<IExcelExportService, ExcelExportService>();
|
||||||
|
|
||||||
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 +96,7 @@ builder.Services.AddSwaggerGen(options =>
|
|||||||
});
|
});
|
||||||
builder.Services.AddDbContext<SurveyResponseDbContext>(option =>
|
builder.Services.AddDbContext<SurveyResponseDbContext>(option =>
|
||||||
{
|
{
|
||||||
option.UseSqlServer("ResponsesConnection");
|
option.UseInMemoryDatabase("Responses");
|
||||||
});
|
});
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
using ClosedXML.Excel;
|
using DamageAssesment.Api.Responses.Interfaces;
|
||||||
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
|
||||||
{
|
{
|
||||||
@ -10,7 +10,7 @@ namespace DamageAssesment.Api.Responses.Providers
|
|||||||
{
|
{
|
||||||
public byte[] ExportToExcel<T1>(List<object> responses)
|
public byte[] ExportToExcel<T1>(List<object> responses)
|
||||||
{
|
{
|
||||||
ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
|
ExcelPackage.LicenseContext = OfficeOpenXml.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
|
||||||
|
@ -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.LocationId })//obj.EmployeeId,
|
.GroupBy(obj => new { obj.SurveyId, obj.EmployeeId, obj.LocationId })
|
||||||
.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())
|
||||||
@ -582,11 +582,6 @@ 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);
|
||||||
@ -916,11 +911,7 @@ 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;
|
||||||
@ -986,11 +977,7 @@ 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);
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
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
|
||||||
{
|
{
|
||||||
|
@ -9,10 +9,6 @@
|
|||||||
"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",
|
||||||
@ -22,6 +18,7 @@
|
|||||||
// "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",
|
||||||
@ -30,7 +27,6 @@
|
|||||||
"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}",
|
||||||
|
@ -11,17 +11,6 @@
|
|||||||
|
|
||||||
<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" />
|
||||||
|
@ -3,7 +3,6 @@ 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,18 +4,11 @@ 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; }
|
||||||
protected override void OnConfiguring(DbContextOptionsBuilder options)
|
public SurveysDbContext(DbContextOptions options) : base(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)
|
||||||
{
|
{
|
||||||
|
@ -75,7 +75,7 @@ builder.Services.AddSwaggerGen(options =>
|
|||||||
|
|
||||||
builder.Services.AddDbContext<SurveysDbContext>(option =>
|
builder.Services.AddDbContext<SurveysDbContext>(option =>
|
||||||
{
|
{
|
||||||
option.UseSqlServer("SurveyConnection");
|
option.UseInMemoryDatabase("Surveys");
|
||||||
});
|
});
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
|
@ -110,6 +110,7 @@ namespace DamageAssesment.Api.Surveys.Providers
|
|||||||
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)
|
||||||
|
|
||||||
if (surveys != null)
|
if (surveys != null)
|
||||||
{
|
{
|
||||||
surveysList = from s in surveys
|
surveysList = from s in surveys
|
||||||
|
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"Logging": {
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Information",
|
||||||
|
"Microsoft.AspNetCore": "Warning"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -8,10 +8,5 @@
|
|||||||
"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;"
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -12,17 +12,8 @@
|
|||||||
<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.9" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.5" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.9">
|
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.5" />
|
||||||
<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.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" />
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Extensions.Configuration;
|
|
||||||
|
|
||||||
namespace DamageAssesment.Api.UsersAccess.Db
|
namespace DamageAssesment.Api.UsersAccess.Db
|
||||||
{
|
{
|
||||||
@ -8,15 +7,9 @@ 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; }
|
||||||
private IConfiguration _Configuration { get; set; }
|
public UsersAccessDbContext(DbContextOptions options) : base(options)
|
||||||
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,4 +1,4 @@
|
|||||||
using DamageAssesment.Api.UsersAccess.Models;
|
using DamageAssesment.Api.UsersAccess.Models;
|
||||||
|
|
||||||
namespace DamageAssesment.Api.UsersAccess.Interfaces
|
namespace DamageAssesment.Api.UsersAccess.Interfaces
|
||||||
{
|
{
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
using DamageAssesment.Api.UsersAccess.Models;
|
||||||
|
|
||||||
namespace DamageAssesment.Api.UsersAccess.Interfaces
|
namespace DamageAssesment.Api.UsersAccess.Interfaces
|
||||||
{
|
{
|
||||||
public interface IHttpUtil
|
public interface IHttpUtil
|
@ -121,7 +121,7 @@ builder.Services.AddSwaggerGen(options =>
|
|||||||
|
|
||||||
builder.Services.AddDbContext<UsersAccessDbContext>(option =>
|
builder.Services.AddDbContext<UsersAccessDbContext>(option =>
|
||||||
{
|
{
|
||||||
option.UseSqlServer("UsersAccessConnection");
|
option.UseInMemoryDatabase("UsersAccess");
|
||||||
});
|
});
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
|
@ -39,19 +39,19 @@ namespace DamageAssesment.Api.UsersAccess.Providers
|
|||||||
{
|
{
|
||||||
if (!userAccessDbContext.Users.Any())
|
if (!userAccessDbContext.Users.Any())
|
||||||
{
|
{
|
||||||
userAccessDbContext.Users.Add(new Db.User { EmployeeId = 1, EmployeeCode = "Emp1", RoleId = 1, IsActive = true, CreateDate = DateTime.Now });
|
userAccessDbContext.Users.Add(new Db.User { Id = 1, EmployeeId = 1, EmployeeCode = "Emp1", RoleId = 1, IsActive = true, CreateDate = DateTime.Now });
|
||||||
userAccessDbContext.Users.Add(new Db.User { EmployeeId = 2, EmployeeCode = "Emp2", RoleId = 2, IsActive = true, CreateDate = DateTime.Now });
|
userAccessDbContext.Users.Add(new Db.User { Id = 2, EmployeeId = 2, EmployeeCode = "Emp2", RoleId = 2, IsActive = true, CreateDate = DateTime.Now });
|
||||||
//userAccessDbContext.Users.Add(new Db.User { EmployeeId = 3, EmployeeCode = "Emp3", RoleId = 3, IsActive = true, CreateDate = DateTime.Now });
|
userAccessDbContext.Users.Add(new Db.User { Id = 3, EmployeeId = 3, EmployeeCode = "Emp3", RoleId = 3, IsActive = true, CreateDate = DateTime.Now });
|
||||||
userAccessDbContext.SaveChanges();
|
userAccessDbContext.SaveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!userAccessDbContext.Roles.Any())
|
if (!userAccessDbContext.Roles.Any())
|
||||||
{
|
{
|
||||||
userAccessDbContext.Roles.Add(new Db.Role { Name = "admin", Description ="Administrator role have full access" });
|
userAccessDbContext.Roles.Add(new Db.Role { Id = 1, Name = "admin", Description ="Administrator role have full access" });
|
||||||
userAccessDbContext.Roles.Add(new Db.Role { Name = "user", Description =" User role"});
|
userAccessDbContext.Roles.Add(new Db.Role { Id = 2, Name = "user", Description =" User role"});
|
||||||
userAccessDbContext.Roles.Add(new Db.Role { Name = "survey", Description ="Survey role" });
|
userAccessDbContext.Roles.Add(new Db.Role { Id = 3, Name = "survey", Description ="Survey role" });
|
||||||
userAccessDbContext.Roles.Add(new Db.Role { Name = "report", Description ="Report role"});
|
userAccessDbContext.Roles.Add(new Db.Role { Id = 4, Name = "report", Description ="Report role"});
|
||||||
userAccessDbContext.Roles.Add(new Db.Role { Name = "document", Description ="Document role" });
|
userAccessDbContext.Roles.Add(new Db.Role { Id = 5, Name = "document", Description ="Document role" });
|
||||||
userAccessDbContext.SaveChanges();
|
userAccessDbContext.SaveChanges();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using DamageAssesment.Api.UsersAccess.Interfaces;
|
using DamageAssesment.Api.UsersAccess.Interfaces;
|
||||||
using DamageAssesment.Api.UsersAccess.Models;
|
using DamageAssesment.Api.UsersAccess.Models;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
@ -36,10 +36,5 @@
|
|||||||
"Name": "profile",
|
"Name": "profile",
|
||||||
"Description": "Read basic information about you such as your date of brith and full name"
|
"Description": "Read basic information about you such as your date of brith and full name"
|
||||||
}
|
}
|
||||||
],
|
]
|
||||||
"ConnectionStrings": {
|
|
||||||
// "UsersAccessConnection": "Server=DESKTOP-OF5DPLQ\\SQLEXPRESS;Database=da_survey_dev;Trusted_Connection=True;TrustServerCertificate=True;"
|
|
||||||
"UsersAccessConnection": "Server=207.180.248.35;Database=da_survey_dev;User Id=sa;Password=YourStrongPassw0rd;TrustServerCertificate=True;"
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,30 +0,0 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<TargetFramework>net6.0</TargetFramework>
|
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
|
||||||
<Nullable>enable</Nullable>
|
|
||||||
|
|
||||||
<IsPackable>false</IsPackable>
|
|
||||||
<IsTestProject>true</IsTestProject>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
|
|
||||||
<PackageReference Include="Moq" Version="4.18.4" />
|
|
||||||
<PackageReference Include="xunit" Version="2.4.2" />
|
|
||||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
|
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
|
||||||
<PrivateAssets>all</PrivateAssets>
|
|
||||||
</PackageReference>
|
|
||||||
<PackageReference Include="coverlet.collector" Version="3.2.0">
|
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
|
||||||
<PrivateAssets>all</PrivateAssets>
|
|
||||||
</PackageReference>
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<ProjectReference Include="..\DamageAssesment.Api.Responses\DamageAssesment.Api.Responses.csproj" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
|
@ -1,30 +0,0 @@
|
|||||||
|
|
||||||
using DamageAssesment.Api.Responses.Models;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace DamageAssesment.Api.Responses.Test
|
|
||||||
{
|
|
||||||
public class MockData
|
|
||||||
{
|
|
||||||
public static async Task<(bool, SurveyResponse, string)> getOkResponse(SurveyResponse data)
|
|
||||||
{
|
|
||||||
return (true, data, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static async Task<(bool, dynamic, string)> getOkResponse()
|
|
||||||
{
|
|
||||||
return (true, new { }, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static async Task<(bool, Models.SurveyResponse, string)> getResponse()
|
|
||||||
{
|
|
||||||
return (false, null, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static async Task<Models.SurveyResponse> getSurveyResponseObject()
|
|
||||||
{
|
|
||||||
return new Models.SurveyResponse { EmployeeId = 1, LocationId = 1, SurveyId = 1, Id = 1 };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,251 +0,0 @@
|
|||||||
using DamageAssesment.Api.Responses.Controllers;
|
|
||||||
using DamageAssesment.Api.Responses.Interfaces;
|
|
||||||
using DamageAssesment.Api.Responses.Models;
|
|
||||||
using DamageAssesment.Api.Responses.Test;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using Moq;
|
|
||||||
using Xunit;
|
|
||||||
|
|
||||||
|
|
||||||
namespace DamageAssesment.SurveyResponses.Test
|
|
||||||
{
|
|
||||||
public class ResponsesServiceTest
|
|
||||||
{
|
|
||||||
private Mock<ISurveysResponse> mockSurveyResponseService;
|
|
||||||
private string token { get; set; }
|
|
||||||
public ResponsesServiceTest()
|
|
||||||
{
|
|
||||||
mockSurveyResponseService = new Mock<ISurveysResponse>();
|
|
||||||
token = Guid.NewGuid().ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact(DisplayName = "Get Responses - Ok case")]
|
|
||||||
public async Task GetSurveyResponsesAsync_ShouldReturnStatusCode200()
|
|
||||||
{
|
|
||||||
SurveyResponse mockRequestObject = await MockData.getSurveyResponseObject();
|
|
||||||
var mockResponse = await MockData.getOkResponse(mockRequestObject);
|
|
||||||
mockSurveyResponseService.Setup(service => service.GetSurveyResponsesAsync()).ReturnsAsync(mockResponse);
|
|
||||||
var surveyResponseProvider = new ResponsesController(mockSurveyResponseService.Object);
|
|
||||||
var result = (OkObjectResult)await surveyResponseProvider.GetSurveyResponsesAsync();
|
|
||||||
Assert.Equal(200, result.StatusCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact(DisplayName = "Get Responses - BadRequest case")]
|
|
||||||
public async Task GetSurveyResponsesAsync_ShouldReturnStatusCode204()
|
|
||||||
{
|
|
||||||
var mockResponse = await MockData.getResponse();
|
|
||||||
mockSurveyResponseService.Setup(service => service.GetSurveyResponsesAsync()).ReturnsAsync(mockResponse);
|
|
||||||
var surveyResponseProvider = new ResponsesController(mockSurveyResponseService.Object);
|
|
||||||
var result = (BadRequestObjectResult)await surveyResponseProvider.GetSurveyResponsesAsync();
|
|
||||||
Assert.Equal(400, result.StatusCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact(DisplayName = "Get Responses by surveyId - Ok case")]
|
|
||||||
public async Task GetSurveyResponsesBySurveyAsync_ShouldReturnStatusCode200()
|
|
||||||
{
|
|
||||||
SurveyResponse mockRequestObject = await MockData.getSurveyResponseObject();
|
|
||||||
var mockResponse = await MockData.getOkResponse();
|
|
||||||
<<<<<<<< HEAD:DamageAssesmentApi/DamageAssesment.Api.Responses.Test/SurveyResponsesServiceTest.cs
|
|
||||||
mockSurveyResponseService.Setup(service => service.GetSurveyResponsesBySurveyAsync(1,1)).ReturnsAsync(mockResponse);
|
|
||||||
var surveyResponseProvider = new SurveyResponsesController(mockSurveyResponseService.Object);
|
|
||||||
var result = (OkObjectResult)await surveyResponseProvider.GetSurveyResponsesAsync(1,1);
|
|
||||||
========
|
|
||||||
mockSurveyResponseService.Setup(service => service.GetSurveyResponsesBySurveyAsync(1)).ReturnsAsync(mockResponse);
|
|
||||||
var surveyResponseProvider = new ResponsesController(mockSurveyResponseService.Object);
|
|
||||||
var result = (OkObjectResult)await surveyResponseProvider.GetSurveyResponsesAsync(1);
|
|
||||||
>>>>>>>> Azure-Integration:DamageAssesmentApi/DamageAssesment.Responses.Test/ResponsesServiceTest.cs
|
|
||||||
Assert.Equal(200, result.StatusCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact(DisplayName = "Get Responses by surveyId - NoContent case")]
|
|
||||||
public async Task GetSurveyResponsesBySurveyAsync_ShouldReturnStatusCode204()
|
|
||||||
{
|
|
||||||
var mockResponse = await MockData.getResponse();
|
|
||||||
<<<<<<<< HEAD:DamageAssesmentApi/DamageAssesment.Api.Responses.Test/SurveyResponsesServiceTest.cs
|
|
||||||
mockSurveyResponseService.Setup(service => service.GetSurveyResponsesBySurveyAsync(1,1)).ReturnsAsync(mockResponse);
|
|
||||||
var surveyResponseProvider = new SurveyResponsesController(mockSurveyResponseService.Object);
|
|
||||||
var result = (NoContentResult)await surveyResponseProvider.GetSurveyResponsesAsync(1,1);
|
|
||||||
========
|
|
||||||
mockSurveyResponseService.Setup(service => service.GetSurveyResponsesBySurveyAsync(1)).ReturnsAsync(mockResponse);
|
|
||||||
var surveyResponseProvider = new ResponsesController(mockSurveyResponseService.Object);
|
|
||||||
var result = (NoContentResult)await surveyResponseProvider.GetSurveyResponsesAsync(1);
|
|
||||||
>>>>>>>> Azure-Integration:DamageAssesmentApi/DamageAssesment.Responses.Test/ResponsesServiceTest.cs
|
|
||||||
Assert.Equal(204, result.StatusCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[Fact(DisplayName = "Get Responses by surveyId and locationId - Ok case")]
|
|
||||||
public async Task GetSurveyResponsesBySurveyLocationAsync_ShouldReturnStatusCode200()
|
|
||||||
{
|
|
||||||
SurveyResponse mockRequestObject = await MockData.getSurveyResponseObject();
|
|
||||||
var mockResponse = await MockData.getOkResponse();
|
|
||||||
mockSurveyResponseService.Setup(service => service.GetSurveyResponsesBySurveyAndLocationAsync(1, 1)).ReturnsAsync(mockResponse);
|
|
||||||
var surveyResponseProvider = new ResponsesController(mockSurveyResponseService.Object);
|
|
||||||
var result = (OkObjectResult)await surveyResponseProvider.GetSurveyResponsesBySurveyAndLocationAsync(1, 1);
|
|
||||||
Assert.Equal(200, result.StatusCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact(DisplayName = "Get Responses by surveyId and locationId - NoContent case")]
|
|
||||||
public async Task GetSurveyResponsesBySurveyLocationAsync_ShouldReturnStatusCode204()
|
|
||||||
{
|
|
||||||
var mockResponse = await MockData.getResponse();
|
|
||||||
mockSurveyResponseService.Setup(service => service.GetSurveyResponsesBySurveyAndLocationAsync(1, 1)).ReturnsAsync(mockResponse);
|
|
||||||
var surveyResponseProvider = new ResponsesController(mockSurveyResponseService.Object);
|
|
||||||
var result = (NoContentResult)await surveyResponseProvider.GetSurveyResponsesBySurveyAndLocationAsync(1, 1);
|
|
||||||
Assert.Equal(204, result.StatusCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact(DisplayName = "Get Responses by surveyId and QuestionId and Answer - Ok case")]
|
|
||||||
public async Task GetSurveyResponsesBySurveyQuestionAnswerAsync_ShouldReturnStatusCode200()
|
|
||||||
{
|
|
||||||
SurveyResponse mockRequestObject = await MockData.getSurveyResponseObject();
|
|
||||||
var mockResponse = await MockData.getOkResponse();
|
|
||||||
mockSurveyResponseService.Setup(service => service.GetResponsesByAnswerAsync(1, 1, "Yes")).ReturnsAsync(mockResponse);
|
|
||||||
var surveyResponseProvider = new ResponsesController(mockSurveyResponseService.Object);
|
|
||||||
var result = (OkObjectResult)await surveyResponseProvider.GetSurveyResponsesByAnswerAsyncAsync(1, 1, "Yes");
|
|
||||||
Assert.Equal(200, result.StatusCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact(DisplayName = "Get Responses by surveyId and QuestionId and Answer - NoContent case")]
|
|
||||||
public async Task GetSurveyResponsesBySurveyQuestionAnswerAsync_ShouldReturnStatusCode204()
|
|
||||||
{
|
|
||||||
var mockResponse = await MockData.getResponse();
|
|
||||||
mockSurveyResponseService.Setup(service => service.GetResponsesByAnswerAsync(1, 1, "Yes")).ReturnsAsync(mockResponse);
|
|
||||||
var surveyResponseProvider = new ResponsesController(mockSurveyResponseService.Object);
|
|
||||||
var result = (NoContentResult)await surveyResponseProvider.GetSurveyResponsesByAnswerAsyncAsync(1, 1, "Yes");
|
|
||||||
Assert.Equal(204, result.StatusCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
[Fact(DisplayName = "Get Responses by region and surveyId - Ok case")]
|
|
||||||
public async Task GetSurveyResponsesByRegionSurveyAsync_ShouldReturnStatusCode200()
|
|
||||||
{
|
|
||||||
SurveyResponse mockRequestObject = await MockData.getSurveyResponseObject();
|
|
||||||
var mockResponse = await MockData.getOkResponse();
|
|
||||||
mockSurveyResponseService.Setup(service => service.GetAnswersByRegionAsync(1)).ReturnsAsync(mockResponse);
|
|
||||||
var surveyResponseProvider = new ResponsesController(mockSurveyResponseService.Object);
|
|
||||||
var result = (OkObjectResult)await surveyResponseProvider.GetAnswersByRegionAsync(1);
|
|
||||||
Assert.Equal(200, result.StatusCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact(DisplayName = "Get Responses by region and surveyId - NoContent Case")]
|
|
||||||
public async Task GetSurveyResponsesByRegionSurveyAsync_ShouldReturnStatusCode204()
|
|
||||||
{
|
|
||||||
var mockResponse = await MockData.getResponse();
|
|
||||||
mockSurveyResponseService.Setup(service => service.GetAnswersByRegionAsync(1)).ReturnsAsync(mockResponse);
|
|
||||||
var surveyResponseProvider = new ResponsesController(mockSurveyResponseService.Object);
|
|
||||||
var result = (NoContentResult)await surveyResponseProvider.GetAnswersByRegionAsync(1);
|
|
||||||
Assert.Equal(204, result.StatusCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact(DisplayName = "Get Responses by maintenanceCenter and surveyId - Ok case")]
|
|
||||||
public async Task GetSurveyResponsesMaintenanceCenterSurveyAsync_ShouldReturnStatusCode200()
|
|
||||||
{
|
|
||||||
SurveyResponse mockRequestObject = await MockData.getSurveyResponseObject();
|
|
||||||
var mockResponse = await MockData.getOkResponse();
|
|
||||||
mockSurveyResponseService.Setup(service => service.GetSurveyResponsesByMaintenanceCenterAsync(1)).ReturnsAsync(mockResponse);
|
|
||||||
var surveyResponseProvider = new ResponsesController(mockSurveyResponseService.Object);
|
|
||||||
var result = (OkObjectResult)await surveyResponseProvider.GetAnswersByMaintenaceCentersync(1);
|
|
||||||
Assert.Equal(200, result.StatusCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact(DisplayName = "Get Responses by maintenanceCenter and surveyId - No Content Case")]
|
|
||||||
public async Task GetSurveyResponsesMaintenanceCenterSurveyAsync_ShouldReturnStatusCode204()
|
|
||||||
{
|
|
||||||
var mockResponse = await MockData.getResponse();
|
|
||||||
mockSurveyResponseService.Setup(service => service.GetSurveyResponsesByMaintenanceCenterAsync(1)).ReturnsAsync(mockResponse);
|
|
||||||
var surveyResponseProvider = new ResponsesController(mockSurveyResponseService.Object);
|
|
||||||
var result = (NoContentResult)await surveyResponseProvider.GetAnswersByMaintenaceCentersync(1);
|
|
||||||
Assert.Equal(204, result.StatusCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact(DisplayName = "Get SurveyResponse by responseId- Ok case")]
|
|
||||||
public async Task GetSurveyResponsesByResponseIdyAsync_ShouldReturnStatusCode200()
|
|
||||||
{
|
|
||||||
SurveyResponse mockRequestObject = await MockData.getSurveyResponseObject();
|
|
||||||
var mockResponse = await MockData.getOkResponse();
|
|
||||||
mockSurveyResponseService.Setup(service => service.GetSurveyResponseByIdAsync(1)).ReturnsAsync(mockResponse);
|
|
||||||
var surveyResponseProvider = new ResponsesController(mockSurveyResponseService.Object);
|
|
||||||
var result = (OkObjectResult)await surveyResponseProvider.GetSurveyResponseByIdAsync(1);
|
|
||||||
Assert.Equal(200, result.StatusCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact(DisplayName = "Get Responses by maintenanceCenter and surveyId - NoContent Case")]
|
|
||||||
public async Task GetSurveyResponsesByResponseIdyAsync_ShouldReturnStatusCode204()
|
|
||||||
{
|
|
||||||
var mockResponse = await MockData.getResponse();
|
|
||||||
mockSurveyResponseService.Setup(service => service.GetSurveyResponseByIdAsync(1)).ReturnsAsync(mockResponse);
|
|
||||||
var surveyResponseProvider = new ResponsesController(mockSurveyResponseService.Object);
|
|
||||||
var result = (NoContentResult)await surveyResponseProvider.GetSurveyResponseByIdAsync(1);
|
|
||||||
Assert.Equal(204, result.StatusCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
[Fact(DisplayName = "Post Responses - Ok case")]
|
|
||||||
public async Task PostSurveyAsync_ShouldReturnStatusCode200()
|
|
||||||
{
|
|
||||||
SurveyResponse mockRequestObject = await MockData.getSurveyResponseObject();
|
|
||||||
var mockResponse = await MockData.getOkResponse(mockRequestObject);
|
|
||||||
mockSurveyResponseService.Setup(service => service.PostSurveyResponseAsync(mockRequestObject)).ReturnsAsync(mockResponse);
|
|
||||||
var surveyResponseController = new ResponsesController(mockSurveyResponseService.Object);
|
|
||||||
var result = (OkObjectResult)await surveyResponseController.PostSurveysAsync(mockRequestObject);
|
|
||||||
Assert.Equal(200, result.StatusCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact(DisplayName = "Post Responses - BadRequest case")]
|
|
||||||
public async Task PostSurveyAsync_ShouldReturnStatusCode400()
|
|
||||||
{
|
|
||||||
SurveyResponse mockRequestObject = await MockData.getSurveyResponseObject();
|
|
||||||
var mockResponse = await MockData.getResponse();
|
|
||||||
mockSurveyResponseService.Setup(service => service.PostSurveyResponseAsync(mockRequestObject)).ReturnsAsync(mockResponse);
|
|
||||||
var surveyResponseController = new ResponsesController(mockSurveyResponseService.Object);
|
|
||||||
var result = (BadRequestObjectResult)await surveyResponseController.PostSurveysAsync(mockRequestObject);
|
|
||||||
Assert.Equal(400, result.StatusCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact(DisplayName = "Put Responses - Ok case")]
|
|
||||||
public async Task PutSurveyAsync_ShouldReturnStatusCode200()
|
|
||||||
{
|
|
||||||
SurveyResponse mockRequestObject = await MockData.getSurveyResponseObject();
|
|
||||||
var mockResponse = await MockData.getOkResponse(mockRequestObject);
|
|
||||||
mockSurveyResponseService.Setup(service => service.PutSurveyResponseAsync(1, mockRequestObject)).ReturnsAsync(mockResponse);
|
|
||||||
var surveyResponseController = new ResponsesController(mockSurveyResponseService.Object);
|
|
||||||
var result = (OkObjectResult)await surveyResponseController.PutSurveyResponseAsync(1, mockRequestObject);
|
|
||||||
Assert.Equal(200, result.StatusCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact(DisplayName = "Put Responses - BadRequest case")]
|
|
||||||
public async Task PutSurveyAsync_ShouldReturnStatusCode404()
|
|
||||||
{
|
|
||||||
SurveyResponse mockRequestObject = await MockData.getSurveyResponseObject();
|
|
||||||
var mockResponse = await MockData.getResponse();
|
|
||||||
mockSurveyResponseService.Setup(service => service.PutSurveyResponseAsync(1, mockRequestObject)).ReturnsAsync(mockResponse); ;
|
|
||||||
var surveyResponseController = new ResponsesController(mockSurveyResponseService.Object);
|
|
||||||
var result = (BadRequestObjectResult)await surveyResponseController.PutSurveyResponseAsync(1, mockRequestObject);
|
|
||||||
Assert.Equal(400, result.StatusCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact(DisplayName = "Delete Responses - Ok case")]
|
|
||||||
public async Task DeleteSurveyAsync_ShouldReturnStatusCode200()
|
|
||||||
{
|
|
||||||
SurveyResponse mockRequestObject = await MockData.getSurveyResponseObject();
|
|
||||||
var mockResponse = await MockData.getOkResponse(mockRequestObject);
|
|
||||||
mockSurveyResponseService.Setup(service => service.DeleteSurveyResponseAsync(1)).ReturnsAsync(mockResponse);
|
|
||||||
var surveyResponseController = new ResponsesController(mockSurveyResponseService.Object);
|
|
||||||
var result = (OkObjectResult)await surveyResponseController.DeleteSurveyResponseAsync(1);
|
|
||||||
Assert.Equal(200, result.StatusCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact(DisplayName = "Delete Responses - NotFound case")]
|
|
||||||
public async Task DeleteSurveyAsync_ShouldReturnStatusCode404()
|
|
||||||
{
|
|
||||||
var mockResponse = await MockData.getResponse();
|
|
||||||
mockSurveyResponseService.Setup(service => service.DeleteSurveyResponseAsync(1)).ReturnsAsync(mockResponse); ;
|
|
||||||
var surveyResponseController = new ResponsesController(mockSurveyResponseService.Object);
|
|
||||||
var result = (NotFoundResult)await surveyResponseController.DeleteSurveyResponseAsync(1);
|
|
||||||
Assert.Equal(404, result.StatusCode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -11,7 +11,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DamageAssesment.Api.Attachm
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{4CB40DC2-D9D2-4384-A7A6-9968F5C777A2}"
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{4CB40DC2-D9D2-4384-A7A6-9968F5C777A2}"
|
||||||
ProjectSection(SolutionItems) = preProject
|
ProjectSection(SolutionItems) = preProject
|
||||||
..\..\..\..\Sample\Migrations.ps1 = ..\..\..\..\Sample\Migrations.ps1
|
|
||||||
ReadMe.txt = ReadMe.txt
|
ReadMe.txt = ReadMe.txt
|
||||||
ReadMe4Dev.txt = ReadMe4Dev.txt
|
ReadMe4Dev.txt = ReadMe4Dev.txt
|
||||||
EndProjectSection
|
EndProjectSection
|
||||||
@ -36,12 +35,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DamageAssesment.Api.Employe
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DamageAssesment.Api.DocuLinks.Test", "DamageAssesment.Api.DocuLinks.Test\DamageAssesment.Api.DocuLinks.Test.csproj", "{A7F17ED7-71D2-4FD0-87E5-D83415078FC0}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DamageAssesment.Api.DocuLinks.Test", "DamageAssesment.Api.DocuLinks.Test\DamageAssesment.Api.DocuLinks.Test.csproj", "{A7F17ED7-71D2-4FD0-87E5-D83415078FC0}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{E53339B2-1760-4266-BCC7-CA923CBCF16C}") = "docker-compose", "docker-compose.dcproj", "{0DD44934-6826-43C8-A438-320A05209967}"
|
||||||
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DamageAssesment.Api.UsersAccess", "DamageAssesment.Api.UsersAccess\DamageAssesment.Api.UsersAccess.csproj", "{40240AD6-90D2-4128-BCDF-12C77D1B1B55}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DamageAssesment.Api.UsersAccess", "DamageAssesment.Api.UsersAccess\DamageAssesment.Api.UsersAccess.csproj", "{40240AD6-90D2-4128-BCDF-12C77D1B1B55}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DamageAssesment.Api.UsersAccess.Test", "DamageAssesment.Api.UsersAccess.Test\DamageAssesment.Api.UsersAccess.Test.csproj", "{ADAF9385-262C-4A37-A603-A53B77EA515D}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DamageAssesment.Api.UsersAccess.Test", "DamageAssesment.Api.UsersAccess.Test\DamageAssesment.Api.UsersAccess.Test.csproj", "{ADAF9385-262C-4A37-A603-A53B77EA515D}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{E53339B2-1760-4266-BCC7-CA923CBCF16C}") = "docker-compose", "docker-compose.dcproj", "{0DD44934-6826-43C8-A438-320A05209967}"
|
|
||||||
EndProject
|
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DamageAssesment.Api.DocuLinks", "DamageAssesment.Api.DocuLinks\DamageAssesment.Api.DocuLinks.csproj", "{B027FBB9-1357-4FD6-85B3-8ADCE11CAE05}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DamageAssesment.Api.DocuLinks", "DamageAssesment.Api.DocuLinks\DamageAssesment.Api.DocuLinks.csproj", "{B027FBB9-1357-4FD6-85B3-8ADCE11CAE05}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DamageAssesment.Api.Responses", "DamageAssesment.Api.Responses\DamageAssesment.Api.Responses.csproj", "{B5C446DF-30DF-46E3-BD87-DA454C8B9C4F}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DamageAssesment.Api.Responses", "DamageAssesment.Api.Responses\DamageAssesment.Api.Responses.csproj", "{B5C446DF-30DF-46E3-BD87-DA454C8B9C4F}"
|
||||||
@ -106,6 +105,10 @@ Global
|
|||||||
{A7F17ED7-71D2-4FD0-87E5-D83415078FC0}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{A7F17ED7-71D2-4FD0-87E5-D83415078FC0}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{A7F17ED7-71D2-4FD0-87E5-D83415078FC0}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{A7F17ED7-71D2-4FD0-87E5-D83415078FC0}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{A7F17ED7-71D2-4FD0-87E5-D83415078FC0}.Release|Any CPU.Build.0 = Release|Any CPU
|
{A7F17ED7-71D2-4FD0-87E5-D83415078FC0}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{0DD44934-6826-43C8-A438-320A05209967}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{0DD44934-6826-43C8-A438-320A05209967}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{0DD44934-6826-43C8-A438-320A05209967}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{0DD44934-6826-43C8-A438-320A05209967}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{40240AD6-90D2-4128-BCDF-12C77D1B1B55}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{40240AD6-90D2-4128-BCDF-12C77D1B1B55}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{40240AD6-90D2-4128-BCDF-12C77D1B1B55}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{40240AD6-90D2-4128-BCDF-12C77D1B1B55}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{40240AD6-90D2-4128-BCDF-12C77D1B1B55}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{40240AD6-90D2-4128-BCDF-12C77D1B1B55}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
@ -114,10 +117,6 @@ Global
|
|||||||
{ADAF9385-262C-4A37-A603-A53B77EA515D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{ADAF9385-262C-4A37-A603-A53B77EA515D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{ADAF9385-262C-4A37-A603-A53B77EA515D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{ADAF9385-262C-4A37-A603-A53B77EA515D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{ADAF9385-262C-4A37-A603-A53B77EA515D}.Release|Any CPU.Build.0 = Release|Any CPU
|
{ADAF9385-262C-4A37-A603-A53B77EA515D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{0DD44934-6826-43C8-A438-320A05209967}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{0DD44934-6826-43C8-A438-320A05209967}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{0DD44934-6826-43C8-A438-320A05209967}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{0DD44934-6826-43C8-A438-320A05209967}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
{B027FBB9-1357-4FD6-85B3-8ADCE11CAE05}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{B027FBB9-1357-4FD6-85B3-8ADCE11CAE05}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{B027FBB9-1357-4FD6-85B3-8ADCE11CAE05}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{B027FBB9-1357-4FD6-85B3-8ADCE11CAE05}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{B027FBB9-1357-4FD6-85B3-8ADCE11CAE05}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{B027FBB9-1357-4FD6-85B3-8ADCE11CAE05}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
18
DamageAssesmentApi/azure-pipelines.yml
Normal file
18
DamageAssesmentApi/azure-pipelines.yml
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
trigger:
|
||||||
|
- '*'
|
||||||
|
|
||||||
|
pr:
|
||||||
|
- '*'
|
||||||
|
|
||||||
|
pool:
|
||||||
|
vmImage: 'ubuntu-latest'
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- checkout: self
|
||||||
|
|
||||||
|
- script: |
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
chmod +x ./Scripts/build_and_push_services2acr.sh
|
||||||
|
./Scripts/build_and_push_services2acr.sh
|
||||||
|
displayName: 'Run build_and_push_services2acr.sh'
|
@ -1,75 +0,0 @@
|
|||||||
version: '3.4'
|
|
||||||
|
|
||||||
services:
|
|
||||||
damageassesment.api.answers:
|
|
||||||
image: dadeschoolscontainerregistry.azurecr.io/damageassesmentapianswers
|
|
||||||
build:
|
|
||||||
context: .
|
|
||||||
dockerfile: DamageAssesment.Api.Answers/Dockerfile
|
|
||||||
ports:
|
|
||||||
- "6001:80"
|
|
||||||
command: bash -c "docker push dadeschoolscontainerregistry.azurecr.io/damageassesmentapianswers"
|
|
||||||
|
|
||||||
damageassesment.api.attachments:
|
|
||||||
image: dadeschoolscontainerregistry.azurecr.io/damageassesmentapiattachments
|
|
||||||
build:
|
|
||||||
context: .
|
|
||||||
dockerfile: DamageAssesment.Api.Attachments/Dockerfile
|
|
||||||
ports:
|
|
||||||
- "6001:80"
|
|
||||||
command: bash -c "docker push dadeschoolscontainerregistry.azurecr.io/damageassesmentapiattachments"
|
|
||||||
|
|
||||||
damageassesment.api.employees:
|
|
||||||
image: dadeschoolscontainerregistry.azurecr.io/damageassesmentapiemployees
|
|
||||||
build:
|
|
||||||
context: .
|
|
||||||
dockerfile: DamageAssesment.Api.Employees/Dockerfile
|
|
||||||
ports:
|
|
||||||
- "6003:80"
|
|
||||||
command: bash -c "docker push dadeschoolscontainerregistry.azurecr.io/damageassesmentapiemployees"
|
|
||||||
|
|
||||||
damageassesment.api.locations:
|
|
||||||
image: dadeschoolscontainerregistry.azurecr.io/damageassesmentapilocations
|
|
||||||
build:
|
|
||||||
context: .
|
|
||||||
dockerfile: DamageAssesment.Api.Locations/Dockerfile
|
|
||||||
ports:
|
|
||||||
- "6004:80"
|
|
||||||
command: bash -c "docker push dadeschoolscontainerregistry.azurecr.io/damageassesmentapilocations"
|
|
||||||
|
|
||||||
damageassesment.api.questions:
|
|
||||||
image: dadeschoolscontainerregistry.azurecr.io/damageassesmentapiquestions
|
|
||||||
build:
|
|
||||||
context: .
|
|
||||||
dockerfile: DamageAssesment.Api.Questions/Dockerfile
|
|
||||||
ports:
|
|
||||||
- "6005:80"
|
|
||||||
command: bash -c "docker push dadeschoolscontainerregistry.azurecr.io/damageassesmentapiquestions"
|
|
||||||
|
|
||||||
damageassesment.api.surveys:
|
|
||||||
image: dadeschoolscontainerregistry.azurecr.io/damageassesmentapisurveys
|
|
||||||
build:
|
|
||||||
context: .
|
|
||||||
dockerfile: DamageAssesment.Api.Surveys/Dockerfile
|
|
||||||
ports:
|
|
||||||
- "6006:80"
|
|
||||||
command: bash -c "docker push dadeschoolscontainerregistry.azurecr.io/damageassesmentapisurveys"
|
|
||||||
|
|
||||||
damageassesment.api.doculinks:
|
|
||||||
image: dadeschoolscontainerregistry.azurecr.io/damageassesmentapidoculinks
|
|
||||||
build:
|
|
||||||
context: .
|
|
||||||
dockerfile: DamageAssesment.Api.DocuLinks/Dockerfile
|
|
||||||
ports:
|
|
||||||
- "6008:80"
|
|
||||||
command: bash -c "docker push dadeschoolscontainerregistry.azurecr.io/damageassesmentapidoculinks"
|
|
||||||
|
|
||||||
damageassesment.api.responses:
|
|
||||||
image: dadeschoolscontainerregistry.azurecr.io/damageassesmentapiresponses
|
|
||||||
build:
|
|
||||||
context: .
|
|
||||||
dockerfile: DamageAssesment.Api.Responses/Dockerfile
|
|
||||||
ports:
|
|
||||||
- "6007:80"
|
|
||||||
command: bash -c "docker push dadeschoolscontainerregistry.azurecr.io/damageassesmentapiresponses"
|
|
||||||
|
|
@ -9,7 +9,6 @@
|
|||||||
<DockerServiceName>damageassesment.api.answers</DockerServiceName>
|
<DockerServiceName>damageassesment.api.answers</DockerServiceName>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="docker-compos.tst.yml" />
|
|
||||||
<None Include="docker-compose.sql.yml" />
|
<None Include="docker-compose.sql.yml" />
|
||||||
<None Include="docker-compose.asf.yml" />
|
<None Include="docker-compose.asf.yml" />
|
||||||
<None Include="docker-compose.override.yml">
|
<None Include="docker-compose.override.yml">
|
||||||
|
@ -1,13 +1,78 @@
|
|||||||
version: '3.4'
|
version: '3.4'
|
||||||
|
|
||||||
services:
|
services:
|
||||||
|
answers:
|
||||||
|
image: santhoshsnair/damageassesmentapianswers:latest
|
||||||
|
environment:
|
||||||
|
- ASPNETCORE_ENVIRONMENT=Development
|
||||||
|
ports:
|
||||||
|
- "6001:80"
|
||||||
|
|
||||||
|
attachments:
|
||||||
|
image: santhoshsnair/damageassesmentapiattachments:latest
|
||||||
|
environment:
|
||||||
|
- ASPNETCORE_ENVIRONMENT=Development
|
||||||
|
ports:
|
||||||
|
- "6002:80"
|
||||||
|
|
||||||
|
|
||||||
|
employees:
|
||||||
|
image: santhoshsnair/damageassesmentapiemployees:latest
|
||||||
|
environment:
|
||||||
|
- ASPNETCORE_ENVIRONMENT=Development
|
||||||
|
ports:
|
||||||
|
- "6003:80"
|
||||||
|
|
||||||
|
|
||||||
|
locations:
|
||||||
|
image: santhoshsnair/damageassesmentapilocations:latest
|
||||||
|
environment:
|
||||||
|
- ASPNETCORE_ENVIRONMENT=Development
|
||||||
|
ports:
|
||||||
|
- "6004:80"
|
||||||
|
|
||||||
|
|
||||||
|
questions:
|
||||||
|
image: santhoshsnair/damageassesmentapiquestions:latest
|
||||||
|
environment:
|
||||||
|
- ASPNETCORE_ENVIRONMENT=Development
|
||||||
|
ports:
|
||||||
|
- "6005:80"
|
||||||
|
|
||||||
|
|
||||||
|
responses:
|
||||||
|
image: santhoshsnair/damageassesmentapisurveyresponses:latest
|
||||||
|
environment:
|
||||||
|
- ASPNETCORE_ENVIRONMENT=Development
|
||||||
|
- services__Answers=http://10.0.0.4:19081/dasapp/answers/
|
||||||
|
- services__Locations=http://10.0.0.4:19081/dasapp/locations/
|
||||||
|
- services__Questions=http://10.0.0.4:19081/dasapp/questions/
|
||||||
|
- services__Employees=http://10.0.0.4:19081/dasapp/employees/
|
||||||
|
- services__Attachments=http://10.0.0.4:19081/dasapp/attachments/
|
||||||
|
- services__Surveys=http://10.0.0.4:19081/dasapp/survey/
|
||||||
|
|
||||||
|
ports:
|
||||||
|
- "6006:80"
|
||||||
|
|
||||||
|
|
||||||
|
surveys:
|
||||||
|
image: santhoshsnair/damageassesmentapisurveys:latest
|
||||||
|
environment:
|
||||||
|
- ASPNETCORE_ENVIRONMENT=Development
|
||||||
|
ports:
|
||||||
|
- "6007:80"
|
||||||
|
|
||||||
|
|
||||||
|
doculinks:
|
||||||
|
image: santhoshsnair/damageassesmentapidoculinks:latest
|
||||||
|
environment:
|
||||||
|
- ASPNETCORE_ENVIRONMENT=Development
|
||||||
|
ports:
|
||||||
|
- "6009:80"
|
||||||
sqlserver:
|
sqlserver:
|
||||||
image: mcr.microsoft.com/mssql/server:2019-latest
|
image: mcr.microsoft.com/mssql/server:2019-latest
|
||||||
environment:
|
environment:
|
||||||
- SA_PASSWORD=Test123
|
- SA_PASSWORD=your_password
|
||||||
- ACCEPT_EULA=Y
|
- ACCEPT_EULA=Y
|
||||||
ports:
|
ports:
|
||||||
- "1433:1433"
|
- "1433:1433"
|
||||||
volumes:
|
|
||||||
- ./data:/var/opt/mssql # Mount a volume to persist data
|
|
||||||
|
30
Scripts/build_and_push_services2acr.ps1
Normal file
30
Scripts/build_and_push_services2acr.ps1
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
# powershell -ExecutionPolicy Bypass -File .\build_and_push_services2acr.ps1
|
||||||
|
# Specify the path to your docker-compose.yml
|
||||||
|
$composeFile = "C:\Users\santh\OneDrive\Desktop\DOCKERS\ubuntu\Sprint6\C1011\Backend-API-Services\DamageAssesmentApi\docker-compose.yml"
|
||||||
|
|
||||||
|
# List of services to build, tag, and push
|
||||||
|
$services = @(
|
||||||
|
"damageassesmentapianswers",
|
||||||
|
"damageassesmentapiattachments",
|
||||||
|
"damageassesmentapiemployees",
|
||||||
|
"damageassesmentapilocations",
|
||||||
|
"damageassesmentapiquestions",
|
||||||
|
"damageassesmentapisurveys",
|
||||||
|
"damageassesmentapidoculinks",
|
||||||
|
"damageassesmentapiresponses"
|
||||||
|
)
|
||||||
|
|
||||||
|
# Log in to ACR (replace ACR_USERNAME and ACR_PASSWORD)
|
||||||
|
docker login dadeschoolscontainerregistry.azurecr.io -u dadeSchoolsContainerRegistry -p k1f8hE0O5hj3tYCCR/5stNrkw5BZoTmAqid/hvaVo8+ACRDc2Arn
|
||||||
|
|
||||||
|
# Loop through the services and build, tag, and push
|
||||||
|
foreach ($service in $services) {
|
||||||
|
# Build the service
|
||||||
|
docker-compose -f $composeFile build $service
|
||||||
|
|
||||||
|
# Tag the image for ACR
|
||||||
|
docker tag "$service" "dadeschoolscontainerregistry.azurecr.io/$service"
|
||||||
|
|
||||||
|
# Push the image to ACR
|
||||||
|
docker push "dadeschoolscontainerregistry.azurecr.io/$service"
|
||||||
|
}
|
39
Scripts/build_and_push_services2acr.sh
Normal file
39
Scripts/build_and_push_services2acr.sh
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Determine the current directory (where the script is located)
|
||||||
|
script_directory="$( cd "$(dirname "$0")" ; pwd -P )"
|
||||||
|
|
||||||
|
# Use the 'find' command to locate the 'docker-compose.yml' file within the repository directory
|
||||||
|
composeFile=$(find "$script_directory/.." -name "docker-compose.yml" -type f | head -n 1)
|
||||||
|
|
||||||
|
if [ -z "$composeFile" ]; then
|
||||||
|
echo "docker-compose.yml not found."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# List of services to build, tag, and push
|
||||||
|
services=(
|
||||||
|
"damageassesmentapianswers"
|
||||||
|
"damageassesmentapiattachments"
|
||||||
|
"damageassesmentapiemployees"
|
||||||
|
"damageassesmentapilocations"
|
||||||
|
"damageassesmentapiquestions"
|
||||||
|
"damageassesmentapisurveys"
|
||||||
|
"damageassesmentapidoculinks"
|
||||||
|
"damageassesmentapiresponses"
|
||||||
|
)
|
||||||
|
|
||||||
|
# Log in to ACR (replace ACR_USERNAME and ACR_PASSWORD)
|
||||||
|
docker login dadeschoolscontainerregistry.azurecr.io -u dadeSchoolsContainerRegistry -p k1f8hE0O5hj3tYCCR/5stNrkw5BZoTmAqid/hvaVo8+ACRDc2Arn
|
||||||
|
|
||||||
|
# Loop through the services and build, tag, and push
|
||||||
|
for service in "${services[@]}"; do
|
||||||
|
# Build the service
|
||||||
|
docker-compose -f "$composeFile" build "$service"
|
||||||
|
|
||||||
|
# Tag the image for ACR
|
||||||
|
docker tag "$service" "dadeschoolscontainerregistry.azurecr.io/$service"
|
||||||
|
|
||||||
|
# Push the image to ACR
|
||||||
|
docker push "dadeschoolscontainerregistry.azurecr.io/$service"
|
||||||
|
done
|
@ -1,39 +0,0 @@
|
|||||||
# Define the path to your application's root directory
|
|
||||||
$applicationRoot = "C:\Users\santh\OneDrive\Desktop\DOCKERS\ubuntu\Sprint6\C1011\Backend-API-Services\DamageAssesmentApi\"
|
|
||||||
#To execute: powershell -ExecutionPolicy Bypass -File .\migrate-sqldb.ps1
|
|
||||||
# Define the list of microservice directories
|
|
||||||
$microservices = @(
|
|
||||||
"DamageAssesment.Api.Answers",
|
|
||||||
"DamageAssesment.Api.Attachments",
|
|
||||||
"DamageAssesment.Api.DocuLinks",
|
|
||||||
"DamageAssesment.Api.Employees",
|
|
||||||
"DamageAssesment.Api.Locations",
|
|
||||||
"DamageAssesment.Api.Questions",
|
|
||||||
"DamageAssesment.Api.Responses",
|
|
||||||
"DamageAssesment.Api.Surveys"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
# Define the migration name with the current date and time
|
|
||||||
$migrationName = "Migration_" + (Get-Date -Format "yyyyMMdd_HHmmss")
|
|
||||||
|
|
||||||
# Function to run migrations for a microservice
|
|
||||||
Function Run-Migrations {
|
|
||||||
param (
|
|
||||||
[string]$microservicePath
|
|
||||||
)
|
|
||||||
|
|
||||||
Write-Host "Running Migrations for $microservicePath..."
|
|
||||||
Set-Location -Path $microservicePath
|
|
||||||
dotnet ef migrations add $migrationName
|
|
||||||
dotnet ef database update
|
|
||||||
Write-Host "Migrations for $microservicePath completed."
|
|
||||||
}
|
|
||||||
|
|
||||||
# Run migrations for each microservice
|
|
||||||
$microservices | ForEach-Object {
|
|
||||||
$microservicePath = Join-Path -Path $applicationRoot -ChildPath $_
|
|
||||||
Run-Migrations -microservicePath $microservicePath
|
|
||||||
}
|
|
||||||
|
|
||||||
Write-Host "All Migrations Completed."
|
|
Reference in New Issue
Block a user