Még nem tökéletes, EF javítása
This commit is contained in:
@@ -25,6 +25,8 @@ namespace WorkFlowCheck.BL.Mappings
|
||||
CreateMap<CheckPoint, CheckPointDTO>();
|
||||
CreateMap<Location, LocationDTO>();
|
||||
CreateMap<Equipment, EquipmentDTO>();
|
||||
CreateMap<CheckListHeader, CheckListHeaderDTO>()
|
||||
.ForMember(dest => dest.CheckListRowDTO, opt => opt.MapFrom(src => src.CheckListRows));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,90 @@
|
||||
using System;
|
||||
using AutoMapper;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Serilog;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WorkFlowCheck.BL.Services.Interfaces;
|
||||
using WorkFlowCheck.Common.DTO;
|
||||
using WorkFlowCheck.DL;
|
||||
using WorkFlowCheck.DL.Entities;
|
||||
|
||||
namespace WorkFlowCheck.BL.Services
|
||||
{
|
||||
class CheckListService
|
||||
public class CheckListService : ICheckListService
|
||||
{
|
||||
private AppDbContext _dbContext;
|
||||
private IMapper _mapper;
|
||||
|
||||
public CheckListService(AppDbContext dbContext, IMapper mapper)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
_mapper = mapper;
|
||||
}
|
||||
public async Task<CheckListHeaderDTO> GetCheckListHeader(int Id)
|
||||
{
|
||||
var retVal = new CheckListHeaderDTO()
|
||||
{
|
||||
CheckListRowDTO = new List<CheckListRowDTO>()
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
var res = await _dbContext.CheckListHeaders
|
||||
.Where(w => w.Id == Id)
|
||||
.Include(i => i.CheckListRows)
|
||||
.AsNoTracking()
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
if (res != null)
|
||||
{
|
||||
retVal = _mapper.Map<CheckListHeaderDTO>(res);
|
||||
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex.Message);
|
||||
}
|
||||
|
||||
return retVal;
|
||||
}
|
||||
public async Task<CheckListHeaderDTO> StartNew(ApiRequestDTO<CheckListTemplateHeaderDTO> request)
|
||||
{
|
||||
var retVal = new CheckListHeaderDTO()
|
||||
{
|
||||
CheckListRowDTO = new List<CheckListRowDTO>()
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
var currentDate = DateTime.UtcNow;
|
||||
CheckListHeader checkListHeader = new CheckListHeader()
|
||||
{
|
||||
CheckListTemplateHeaderId = request.Data.Id,
|
||||
CreatedAt = currentDate,
|
||||
CreatedBy = request.UserDTO.UserName,
|
||||
Description = request.Data.Description,
|
||||
DocumentNumber = "",
|
||||
GuidNumber = Guid.NewGuid(),
|
||||
IsDeleted = false,
|
||||
IsStorno = false,
|
||||
LastModAt = currentDate,
|
||||
ShortName = "",
|
||||
CheckListRows = new List<CheckListRow>()
|
||||
};
|
||||
_dbContext.CheckListHeaders.Add(checkListHeader);
|
||||
await _dbContext.SaveChangesAsync();
|
||||
|
||||
retVal = _mapper.Map<CheckListHeaderDTO>(checkListHeader);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex.Message);
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,5 +10,6 @@ namespace WorkFlowCheck.BL.Services.Interfaces
|
||||
public interface ICheckListService
|
||||
{
|
||||
Task<CheckListHeaderDTO> GetCheckListHeader(int Id);
|
||||
Task<CheckListHeaderDTO> StartNew(ApiRequestDTO<CheckListTemplateHeaderDTO> request);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user