Db context changes for auto insertion
This commit is contained in:
parent
099055d088
commit
82f2ae265a
@ -43,9 +43,9 @@ namespace DamageAssesment.Api.Answers.Test
|
|||||||
return (false, list, null);
|
return (false, list, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task<Answers.Db.Answer> getInputAnswerData()
|
public static async Task<Answers.Models.Answer> getInputAnswerData()
|
||||||
{
|
{
|
||||||
return new Answers.Db.Answer { Id = 1, AnswerText = "Yes", Comment = "", QuestionId = 1, SurveyResponseId = 1 };
|
return new Answers.Models.Answer { Id = 1, AnswerText = "Yes", Comment = "", QuestionId = 1, SurveyResponseId = 1 };
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,7 +78,7 @@ namespace DamageAssesment.Api.Answers.Controllers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
||||||
[HttpPut("Answers")]
|
[HttpPut("Answers")]
|
||||||
public IActionResult UpdateAnswer(Db.Answer answer)
|
public IActionResult UpdateAnswer(Models.Answer answer)
|
||||||
{
|
{
|
||||||
if (answer != null)
|
if (answer != null)
|
||||||
{
|
{
|
||||||
@ -99,7 +99,7 @@ namespace DamageAssesment.Api.Answers.Controllers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
||||||
[HttpPost("Answers")]
|
[HttpPost("Answers")]
|
||||||
public IActionResult CreateAnswer(Db.Answer answer)
|
public IActionResult CreateAnswer(Models.Answer answer)
|
||||||
{
|
{
|
||||||
if (answer != null)
|
if (answer != null)
|
||||||
{
|
{
|
||||||
|
@ -10,7 +10,13 @@ namespace DamageAssesment.Api.Answers.Db
|
|||||||
|
|
||||||
}
|
}
|
||||||
public DbSet<Db.Answer> Answers { get; set; }
|
public DbSet<Db.Answer> Answers { get; set; }
|
||||||
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
base.OnModelCreating(modelBuilder);
|
||||||
|
modelBuilder.Entity<Answer>()
|
||||||
|
.Property(item => item.Id)
|
||||||
|
.ValueGeneratedOnAdd();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -6,8 +6,8 @@
|
|||||||
Task<(bool IsSuccess, IEnumerable<Models.Answer> Answers, string ErrorMessage)> GetAnswersByQuestionAsync(int questionId);
|
Task<(bool IsSuccess, IEnumerable<Models.Answer> Answers, string ErrorMessage)> GetAnswersByQuestionAsync(int questionId);
|
||||||
Task<(bool IsSuccess, Models.Answer Answer, string ErrorMessage)> GetAnswerByIdAsync(int Id);
|
Task<(bool IsSuccess, Models.Answer Answer, string ErrorMessage)> GetAnswerByIdAsync(int Id);
|
||||||
Task<(bool IsSuccess, IEnumerable<Models.Answer> Answers, string ErrorMessage)> GetAnswersAsync(int responseId);
|
Task<(bool IsSuccess, IEnumerable<Models.Answer> Answers, string ErrorMessage)> GetAnswersAsync(int responseId);
|
||||||
(bool IsSuccess, Models.Answer Answer, string ErrorMessage) PostAnswerAsync(Db.Answer Answer);
|
(bool IsSuccess, Models.Answer Answer, string ErrorMessage) PostAnswerAsync(Models.Answer Answer);
|
||||||
(bool IsSuccess, Models.Answer Answer, string ErrorMessage) UpdateAnswerAsync(Db.Answer Answer);
|
(bool IsSuccess, Models.Answer Answer, string ErrorMessage) UpdateAnswerAsync(Models.Answer Answer);
|
||||||
Task<(bool IsSuccess, Models.Answer Answer, string ErrorMessage)> DeleteAnswerAsync(int Id);
|
Task<(bool IsSuccess, Models.Answer Answer, string ErrorMessage)> DeleteAnswerAsync(int Id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ namespace DamageAssesment.Api.Answers.Profiles
|
|||||||
public AnswersProfile()
|
public AnswersProfile()
|
||||||
{
|
{
|
||||||
CreateMap<Db.Answer,Models.Answer>();
|
CreateMap<Db.Answer,Models.Answer>();
|
||||||
|
CreateMap<Models.Answer, Db.Answer>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -108,16 +108,17 @@ namespace DamageAssesment.Api.Answers.Providers
|
|||||||
return (false, null, ex.Message);
|
return (false, null, ex.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public (bool IsSuccess, Models.Answer Answer, string ErrorMessage) PostAnswerAsync(Db.Answer Answer)
|
public (bool IsSuccess, Models.Answer Answer, string ErrorMessage) PostAnswerAsync(Models.Answer Answer)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
logger?.LogInformation("Query Answer");
|
logger?.LogInformation("Query Answer");
|
||||||
if (!AnswerExists(Answer.Id))
|
if (!AnswerExists(Answer.Id))
|
||||||
{
|
{
|
||||||
answerDbContext.Answers.Add(Answer);
|
Db.Answer answer = mapper.Map<Models.Answer, Db.Answer>(Answer);
|
||||||
|
answerDbContext.Answers.Add(answer);
|
||||||
answerDbContext.SaveChanges();
|
answerDbContext.SaveChanges();
|
||||||
var result = mapper.Map<Db.Answer, Models.Answer>(Answer);
|
var result = mapper.Map<Db.Answer, Models.Answer>(answer);
|
||||||
return (true, result, null);
|
return (true, result, null);
|
||||||
}
|
}
|
||||||
return (false, null, "Answer is already exits");
|
return (false, null, "Answer is already exits");
|
||||||
@ -128,7 +129,7 @@ namespace DamageAssesment.Api.Answers.Providers
|
|||||||
return (false, null, ex.Message);
|
return (false, null, ex.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public (bool IsSuccess, Models.Answer Answer, string ErrorMessage) UpdateAnswerAsync(Db.Answer Answer)
|
public (bool IsSuccess, Models.Answer Answer, string ErrorMessage) UpdateAnswerAsync(Models.Answer Answer)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -137,9 +138,10 @@ namespace DamageAssesment.Api.Answers.Providers
|
|||||||
var existing = answerDbContext.Answers.AsNoTracking().FirstOrDefault(x => x.Id == Answer.Id);
|
var existing = answerDbContext.Answers.AsNoTracking().FirstOrDefault(x => x.Id == Answer.Id);
|
||||||
if (existing != null)
|
if (existing != null)
|
||||||
{
|
{
|
||||||
answerDbContext.Answers.Update(Answer);
|
Db.Answer answer = mapper.Map<Models.Answer, Db.Answer>(Answer);
|
||||||
|
answerDbContext.Answers.Update(answer);
|
||||||
answerDbContext.SaveChanges();
|
answerDbContext.SaveChanges();
|
||||||
return (true, mapper.Map<Db.Answer, Models.Answer>(Answer), "Successful");
|
return (true, mapper.Map<Db.Answer, Models.Answer>(answer), "Successful");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -17,7 +17,7 @@ namespace DamageAssesment.Api.Attachments.Test
|
|||||||
|
|
||||||
for (int i = 0; i < 10; i++)
|
for (int i = 0; i < 10; i++)
|
||||||
{
|
{
|
||||||
list.Add(new Attachments.Models.Attachment(i, Guid.NewGuid().ToString() + "@gmail.com")
|
list.Add(new Attachments.Models.Attachment()
|
||||||
{
|
{
|
||||||
Id = i,
|
Id = i,
|
||||||
AnswerId = i,
|
AnswerId = i,
|
||||||
@ -73,10 +73,10 @@ namespace DamageAssesment.Api.Attachments.Test
|
|||||||
return (false, list, null);
|
return (false, list, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task<List<Attachments.Db.Attachment>> getInputAttachmentData()
|
public static async Task<List<Attachments.Models.Attachment>> getInputAttachmentData()
|
||||||
{
|
{
|
||||||
List<Attachments.Db.Attachment> Attachments=new List<Db.Attachment>();
|
List<Attachments.Models.Attachment> Attachments=new List<Models.Attachment>();
|
||||||
Attachments.Add(new Db.Attachment{ Id = 0, AnswerId = 10, ResponseId = 10, URI = "sample", IsDeleted = false,FileName="sample1" }) ;
|
Attachments.Add(new Models.Attachment{ Id = 0, AnswerId = 10, ResponseId = 10, URI = "sample", IsDeleted = false,FileName="sample1" }) ;
|
||||||
return Attachments;
|
return Attachments;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ namespace DamageAssesment.Api.Attachments.Controllers
|
|||||||
if (attachmentInfo.Answers.Count > 0)
|
if (attachmentInfo.Answers.Count > 0)
|
||||||
{
|
{
|
||||||
var Attachments = this.AttachmentProvider.GetAttachmentCounter();
|
var Attachments = this.AttachmentProvider.GetAttachmentCounter();
|
||||||
List<Db.Attachment> attachments = UploadService.UploadAttachment(attachmentInfo.ResponseId, Attachments.counter, attachmentInfo.Answers);
|
List<Models.Attachment> attachments = UploadService.UploadAttachment(attachmentInfo.ResponseId, Attachments.counter, attachmentInfo.Answers);
|
||||||
var result = this.AttachmentProvider.PostAttachmentAsync(attachments);
|
var result = this.AttachmentProvider.PostAttachmentAsync(attachments);
|
||||||
if (result.IsSuccess)
|
if (result.IsSuccess)
|
||||||
{
|
{
|
||||||
@ -119,7 +119,7 @@ namespace DamageAssesment.Api.Attachments.Controllers
|
|||||||
var res = this.AttachmentProvider.GetAttachmentInfo(attachmentInfo.Answers);
|
var res = this.AttachmentProvider.GetAttachmentInfo(attachmentInfo.Answers);
|
||||||
if (res.IsSuccess)
|
if (res.IsSuccess)
|
||||||
{
|
{
|
||||||
List<Db.Attachment> attachments = UploadService.UpdateAttachments(attachmentInfo.ResponseId, attachmentInfo.Answers, res.Attachments);
|
List<Models.Attachment> attachments = UploadService.UpdateAttachments(attachmentInfo.ResponseId, attachmentInfo.Answers, res.Attachments);
|
||||||
var result = this.AttachmentProvider.PutAttachmentAsync(attachments);
|
var result = this.AttachmentProvider.PutAttachmentAsync(attachments);
|
||||||
if (result.IsSuccess)
|
if (result.IsSuccess)
|
||||||
{
|
{
|
||||||
|
@ -8,5 +8,12 @@ namespace DamageAssesment.Api.Attachments.Db
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
public DbSet<Db.Attachment> Attachments { get; set; }
|
public DbSet<Db.Attachment> Attachments { get; set; }
|
||||||
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
base.OnModelCreating(modelBuilder);
|
||||||
|
modelBuilder.Entity<Attachment>()
|
||||||
|
.Property(item => item.Id)
|
||||||
|
.ValueGeneratedOnAdd();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,8 +6,8 @@ namespace DamageAssesment.Api.Attachments.Interfaces
|
|||||||
{
|
{
|
||||||
Task<(bool IsSuccess, IEnumerable<Models.Attachment> Attachments, string ErrorMessage)> GetAttachmentsAsync();
|
Task<(bool IsSuccess, IEnumerable<Models.Attachment> Attachments, string ErrorMessage)> GetAttachmentsAsync();
|
||||||
Task<(bool IsSuccess, Models.Attachment Attachment, string ErrorMessage)> GetAttachmentByIdAsync(int Id);
|
Task<(bool IsSuccess, Models.Attachment Attachment, string ErrorMessage)> GetAttachmentByIdAsync(int Id);
|
||||||
(bool IsSuccess, IEnumerable<Models.Attachment> Attachments, string ErrorMessage) PostAttachmentAsync(List<Db.Attachment> Attachments);
|
(bool IsSuccess, IEnumerable<Models.Attachment> Attachments, string ErrorMessage) PostAttachmentAsync(List<Models.Attachment> Attachments);
|
||||||
(bool IsSuccess, IEnumerable<Models.Attachment> Attachments, string ErrorMessage) PutAttachmentAsync(List<Db.Attachment> Attachments);
|
(bool IsSuccess, IEnumerable<Models.Attachment> Attachments, string ErrorMessage) PutAttachmentAsync(List<Models.Attachment> Attachments);
|
||||||
Task<(bool IsSuccess, Models.Attachment Attachment, string Path)> DeleteAttachmentAsync(int Id);
|
Task<(bool IsSuccess, Models.Attachment Attachment, string Path)> DeleteAttachmentAsync(int Id);
|
||||||
Task<(bool IsSuccess, int counter, string Path)> DeleteAttachmentsAsync(int responseId, int answerId);
|
Task<(bool IsSuccess, int counter, string Path)> DeleteAttachmentsAsync(int responseId, int answerId);
|
||||||
Task<(bool IsSuccess, int counter, string Path)> DeleteBulkAttachmentsAsync(int responseId, List<int> answerIds);
|
Task<(bool IsSuccess, int counter, string Path)> DeleteBulkAttachmentsAsync(int responseId, List<int> answerIds);
|
||||||
|
@ -4,9 +4,9 @@ namespace DamageAssesment.Api.Attachments.Interfaces
|
|||||||
{
|
{
|
||||||
public interface IUploadService
|
public interface IUploadService
|
||||||
{
|
{
|
||||||
List<Db.Attachment> UploadAttachment(int responseId,int answerId, int counter, List<IFormFile> postedFile);
|
List<Models.Attachment> UploadAttachment(int responseId,int answerId, int counter, List<IFormFile> postedFile);
|
||||||
List<Db.Attachment> UploadAttachment(int responseId, int counter, List<AnswerInfo> answers);
|
List<Models.Attachment> UploadAttachment(int responseId, int counter, List<AnswerInfo> answers);
|
||||||
public List<Db.Attachment> UpdateAttachments(int responseId, List<AnswerInfo> answers, IEnumerable<Models.Attachment> attachments);
|
public List<Models.Attachment> UpdateAttachments(int responseId, List<AnswerInfo> answers, IEnumerable<Models.Attachment> attachments);
|
||||||
void Deletefile(string path);
|
void Deletefile(string path);
|
||||||
void Movefile(string path);
|
void Movefile(string path);
|
||||||
}
|
}
|
||||||
|
@ -13,10 +13,10 @@ namespace DamageAssesment.Api.Attachments.Models
|
|||||||
public bool IsDeleted { get; set; }
|
public bool IsDeleted { get; set; }
|
||||||
public string FileName { get; set; }
|
public string FileName { get; set; }
|
||||||
|
|
||||||
public Attachment(int answerId, string uri)
|
//public Attachment(int answerId, string uri)
|
||||||
{
|
//{
|
||||||
this.AnswerId = answerId;
|
// this.AnswerId = answerId;
|
||||||
this.URI = uri;
|
// this.URI = uri;
|
||||||
}
|
//}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
public AttachmentsProfiles()
|
public AttachmentsProfiles()
|
||||||
{
|
{
|
||||||
CreateMap<Db.Attachment, Models.Attachment>();
|
CreateMap<Db.Attachment, Models.Attachment>();
|
||||||
|
CreateMap<Models.Attachment, Db.Attachment>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -65,14 +65,15 @@ namespace DamageAssesment.Api.Attachments.Providers
|
|||||||
return (false, null, ex.Message);
|
return (false, null, ex.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public (bool IsSuccess, IEnumerable<Models.Attachment> Attachments, string ErrorMessage) PostAttachmentAsync(List<Db.Attachment> Attachments)
|
public (bool IsSuccess, IEnumerable<Models.Attachment> Attachments, string ErrorMessage) PostAttachmentAsync(List<Models.Attachment> Attachments)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
logger?.LogInformation("Query Attachment");
|
logger?.LogInformation("Query Attachment");
|
||||||
AttachmentDbContext.Attachments.AddRange(Attachments);
|
List<Db.Attachment> attachments = mapper.Map<List<Models.Attachment>, List<Db.Attachment>>(Attachments);
|
||||||
|
AttachmentDbContext.Attachments.AddRange(attachments);
|
||||||
AttachmentDbContext.SaveChanges();
|
AttachmentDbContext.SaveChanges();
|
||||||
var result = mapper.Map<IEnumerable<Db.Attachment>, IEnumerable<Models.Attachment>>(Attachments);
|
var result = mapper.Map<IEnumerable<Db.Attachment>, IEnumerable<Models.Attachment>>(attachments);
|
||||||
return (true, result, null);
|
return (true, result, null);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -82,14 +83,15 @@ namespace DamageAssesment.Api.Attachments.Providers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public (bool IsSuccess, IEnumerable<Models.Attachment> Attachments, string ErrorMessage) PutAttachmentAsync(List<Db.Attachment> Attachments)
|
public (bool IsSuccess, IEnumerable<Models.Attachment> Attachments, string ErrorMessage) PutAttachmentAsync(List<Models.Attachment> Attachments)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
logger?.LogInformation("Query Attachment");
|
logger?.LogInformation("Query Attachment");
|
||||||
AttachmentDbContext.Attachments.UpdateRange(Attachments);
|
List<Db.Attachment> attachments = mapper.Map<List<Models.Attachment>, List<Db.Attachment>>(Attachments);
|
||||||
|
AttachmentDbContext.Attachments.UpdateRange(attachments);
|
||||||
AttachmentDbContext.SaveChanges();
|
AttachmentDbContext.SaveChanges();
|
||||||
var result = mapper.Map<IEnumerable<Db.Attachment>, IEnumerable<Models.Attachment>>(Attachments);
|
var result = mapper.Map<IEnumerable<Db.Attachment>, IEnumerable<Models.Attachment>>(attachments);
|
||||||
return (true, result, null);
|
return (true, result, null);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -204,10 +206,11 @@ namespace DamageAssesment.Api.Attachments.Providers
|
|||||||
FileModel fileModel= new FileModel(){AttachmentId=0,FileName="Sample",FileContent= "c2FtcGxl",FileExtension=".txt"};
|
FileModel fileModel= new FileModel(){AttachmentId=0,FileName="Sample",FileContent= "c2FtcGxl",FileExtension=".txt"};
|
||||||
List<AnswerInfo> answerInfos=new List<AnswerInfo>();
|
List<AnswerInfo> answerInfos=new List<AnswerInfo>();
|
||||||
answerInfos.Add(new AnswerInfo(){ AnswerId = 1,postedFiles=new List<FileModel> { fileModel }});
|
answerInfos.Add(new AnswerInfo(){ AnswerId = 1,postedFiles=new List<FileModel> { fileModel }});
|
||||||
List<Db.Attachment> attachments = uploadservice.UploadAttachment(1, 0, answerInfos);
|
List<Models.Attachment> attachments = uploadservice.UploadAttachment(1, 0, answerInfos);
|
||||||
if (attachments.Count > 0)
|
if (attachments.Count > 0)
|
||||||
{
|
{
|
||||||
AttachmentDbContext.Attachments.AddRange(attachments);
|
List<Db.Attachment> Attachments = mapper.Map<List<Models.Attachment>, List<Db.Attachment>>(attachments);
|
||||||
|
AttachmentDbContext.Attachments.AddRange(Attachments);
|
||||||
AttachmentDbContext.SaveChanges();
|
AttachmentDbContext.SaveChanges();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ namespace DamageAssesment.Api.Attachments.Providers
|
|||||||
uploadpath = configuration.GetValue<string>("Fileupload:folderpath");
|
uploadpath = configuration.GetValue<string>("Fileupload:folderpath");
|
||||||
Deletepath = configuration.GetValue<string>("Fileupload:Deletepath");
|
Deletepath = configuration.GetValue<string>("Fileupload:Deletepath");
|
||||||
}
|
}
|
||||||
public List<Db.Attachment> UploadAttachment(int responseId,int answerId,int counter, List<IFormFile> postedFile)
|
public List<Models.Attachment> UploadAttachment(int responseId,int answerId,int counter, List<IFormFile> postedFile)
|
||||||
{
|
{
|
||||||
var pathToSave = Path.Combine(Directory.GetCurrentDirectory(), uploadpath);
|
var pathToSave = Path.Combine(Directory.GetCurrentDirectory(), uploadpath);
|
||||||
String responseDirectory = "Response-" + responseId;
|
String responseDirectory = "Response-" + responseId;
|
||||||
@ -42,7 +42,7 @@ namespace DamageAssesment.Api.Attachments.Providers
|
|||||||
Deletefile(searchFile);
|
Deletefile(searchFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
List<Db.Attachment> attachments = new List<Db.Attachment>();
|
List<Models.Attachment> attachments = new List<Models.Attachment>();
|
||||||
foreach (IFormFile item in postedFile)
|
foreach (IFormFile item in postedFile)
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -55,15 +55,15 @@ namespace DamageAssesment.Api.Attachments.Providers
|
|||||||
{
|
{
|
||||||
item.CopyTo(stream);
|
item.CopyTo(stream);
|
||||||
}
|
}
|
||||||
attachments.Add(new Db.Attachment { AnswerId = answerId, ResponseId = responseId, IsDeleted = false, FileName = UserfileName, URI = dbPath });
|
attachments.Add(new Models.Attachment { AnswerId = answerId, ResponseId = responseId, IsDeleted = false, FileName = UserfileName, URI = dbPath });
|
||||||
}
|
}
|
||||||
|
|
||||||
return attachments;
|
return attachments;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Db.Attachment> UploadAttachment(int responseId, int counter,List<AnswerInfo> answers)
|
public List<Models.Attachment> UploadAttachment(int responseId, int counter,List<AnswerInfo> answers)
|
||||||
{
|
{
|
||||||
List<Db.Attachment> attachments = new List<Db.Attachment>();
|
List<Models.Attachment> attachments = new List<Models.Attachment>();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
foreach (var item in answers)
|
foreach (var item in answers)
|
||||||
@ -94,20 +94,20 @@ namespace DamageAssesment.Api.Attachments.Providers
|
|||||||
var dbPath = Path.Combine(fullDirectoryPath, fileName);
|
var dbPath = Path.Combine(fullDirectoryPath, fileName);
|
||||||
File.WriteAllBytes(dbPath, Convert.FromBase64String(file.FileContent));
|
File.WriteAllBytes(dbPath, Convert.FromBase64String(file.FileContent));
|
||||||
|
|
||||||
attachments.Add(new Db.Attachment { AnswerId = answerId, ResponseId = responseId, IsDeleted = false, FileName = UserfileName, URI = dbPath });
|
attachments.Add(new Models.Attachment { AnswerId = answerId, ResponseId = responseId, IsDeleted = false, FileName = UserfileName, URI = dbPath });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return attachments;
|
return attachments;
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
return new List<Db.Attachment>();
|
return new List<Models.Attachment>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
public List<Db.Attachment> UpdateAttachments(int responseId,List<AnswerInfo> answers,IEnumerable<Models.Attachment> attachments)
|
public List<Models.Attachment> UpdateAttachments(int responseId,List<AnswerInfo> answers,IEnumerable<Models.Attachment> attachments)
|
||||||
{
|
{
|
||||||
List<Db.Attachment> Dbattachments = new List<Db.Attachment>();
|
List<Models.Attachment> Dbattachments = new List<Models.Attachment>();
|
||||||
foreach (Models.Attachment searchFile in attachments)
|
foreach (Models.Attachment searchFile in attachments)
|
||||||
{
|
{
|
||||||
Deletefile(searchFile.URI);
|
Deletefile(searchFile.URI);
|
||||||
@ -131,7 +131,7 @@ namespace DamageAssesment.Api.Attachments.Providers
|
|||||||
var dbPath = Path.Combine(fullDirectoryPath, fileName);
|
var dbPath = Path.Combine(fullDirectoryPath, fileName);
|
||||||
File.WriteAllBytes(dbPath, Convert.FromBase64String(file.FileContent));
|
File.WriteAllBytes(dbPath, Convert.FromBase64String(file.FileContent));
|
||||||
|
|
||||||
Dbattachments.Add(new Db.Attachment { Id=attachment.Id, AnswerId = answerId, ResponseId = responseId, IsDeleted = false, FileName = UserfileName, URI = dbPath });
|
Dbattachments.Add(new Models.Attachment { Id=attachment.Id, AnswerId = answerId, ResponseId = responseId, IsDeleted = false, FileName = UserfileName, URI = dbPath });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Dbattachments;
|
return Dbattachments;
|
||||||
|
@ -14,12 +14,21 @@ namespace DamageAssesment.Api.Questions.Db
|
|||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
//protected override void OnModelCreating(ModelBuilder modelBuilder)
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
//{
|
{
|
||||||
// modelBuilder.Entity<Question>()
|
base.OnModelCreating(modelBuilder);
|
||||||
// .HasOne(a => a.QuestionType)
|
modelBuilder.Entity<Question>()
|
||||||
// .WithOne(b => b.Question)
|
.Property(item => item.Id)
|
||||||
// .HasForeignKey<QuestionType>(b => b.QuestionTypeID);
|
.ValueGeneratedOnAdd();
|
||||||
//}
|
modelBuilder.Entity<QuestionType>()
|
||||||
|
.Property(item => item.Id)
|
||||||
|
.ValueGeneratedOnAdd();
|
||||||
|
modelBuilder.Entity<QuestionsTranslation>()
|
||||||
|
.Property(item => item.Id)
|
||||||
|
.ValueGeneratedOnAdd();
|
||||||
|
modelBuilder.Entity<QuestionCategory>()
|
||||||
|
.Property(item => item.Id)
|
||||||
|
.ValueGeneratedOnAdd();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user