Photo rendberakása + EF migráció
This commit is contained in:
@@ -48,12 +48,29 @@ namespace WorkFlowCheck.BL.Mappings
|
||||
.ForMember(dest => dest.CheckListRowDTO, opt => opt.MapFrom(src => src.CheckListRows));
|
||||
|
||||
CreateMap<CheckListRow, CheckListRowDTO>()
|
||||
.ForMember(dest => dest.CheckListTemplateRowDTO, opt => opt.MapFrom(src => src.CheckListTemplateRow));
|
||||
.ForMember(dest => dest.CheckListTemplateRowDTO, opt => opt.MapFrom(src => src.CheckListTemplateRow))
|
||||
.ForMember(dest => dest.Photo, opt => opt.MapFrom(src => GetImageBytes(src.PhotoFileName)));
|
||||
|
||||
|
||||
CreateMap<RoleCheckListTemplateHeader, RoleCheckListTemplateHeaderDTO>()
|
||||
.ForMember(dest => dest.RoleDTO, opt => opt.MapFrom(src => src.Role))
|
||||
.ForMember(dest => dest.CheckListTemplateHeaderDTO, opt => opt.MapFrom(src => src.CheckListTemplateHeader));
|
||||
}
|
||||
private byte[] GetImageBytes(string fileName)
|
||||
{
|
||||
try
|
||||
{
|
||||
var filePath = Path.Combine(Directory.GetCurrentDirectory(), "Images", fileName);
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
return File.ReadAllBytes(filePath);
|
||||
}
|
||||
return Array.Empty<byte>(); // Visszaad egy üres byte[]-ot, ha a fájl nem található
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return Array.Empty<byte>(); // Hiba esetén is üres byte[]-ot ad vissza
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -184,7 +184,7 @@ namespace WorkFlowCheck.BL.Services
|
||||
CheckListTemplateRowId = item.Id,
|
||||
GuidNumber = Guid.NewGuid(),
|
||||
IsDeleted = false,
|
||||
Photo = new byte[0],
|
||||
PhotoFileName = "",
|
||||
};
|
||||
_dbContext.CheckListRows.Add(checkListRow);
|
||||
}
|
||||
@@ -410,7 +410,7 @@ namespace WorkFlowCheck.BL.Services
|
||||
if (checkListRow != null)
|
||||
{
|
||||
checkListRow.Answer = checkListRowDTO.Answer;
|
||||
checkListRow.Photo = checkListRowDTO.Photo;
|
||||
//checkListRow.Photo = checkListRowDTO.Photo;
|
||||
await _dbContext.SaveChangesAsync();
|
||||
retVal = _mapper.Map<CheckListRowDTO>(checkListRow);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
|
||||
using AutoMapper;
|
||||
using DocumentFormat.OpenXml.InkML;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Serilog;
|
||||
using System.Collections.Generic;
|
||||
@@ -376,9 +377,14 @@ namespace WorkFlowCheck.BL.Services
|
||||
if (dtoRow != null)
|
||||
{
|
||||
row.Answer = dtoRow.Answer;
|
||||
if (dtoRow.Photo != null && dtoRow.Photo.Length > 0)
|
||||
if (dtoRow.Photo != null && dtoRow.Photo.Length > 0 )
|
||||
{
|
||||
row.Photo = dtoRow.Photo;
|
||||
string imageDirectory = Path.Combine(Directory.GetCurrentDirectory(), "Images");
|
||||
var timestamp = DateTime.Now.ToString("yyyyMMdd_HHmmss");
|
||||
var fileName = $"PH_{timestamp}_{row.CheckListHeaderId}_{row.Id}.jpeg";
|
||||
row.PhotoFileName = fileName;
|
||||
var filePath = Path.Combine(imageDirectory, fileName);
|
||||
await File.WriteAllBytesAsync(filePath, dtoRow.Photo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user