RoleCheckPoint

This commit is contained in:
2025-03-31 11:55:24 +02:00
parent d7c198acfa
commit 56f17681be
26 changed files with 1511 additions and 20 deletions
@@ -1,14 +1,18 @@
using AutoMapper;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.EntityFrameworkCore;
using Serilog;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using WorkFlowCheck.BL.DocumentGenerator;
using WorkFlowCheck.BL.Services.Interfaces;
using WorkFlowCheck.Common.DTO;
using WorkFlowCheck.Common.Enums;
using WorkFlowCheck.DL;
using WorkFlowCheck.DL.Entities;
@@ -150,6 +154,7 @@ namespace WorkFlowCheck.BL.Services
CheckListHeader checkListHeader = new CheckListHeader()
{
CheckListTemplateHeaderId = checkListHeaderNewDTO.CheckListTemplateHeaderId,
CheckStatus = CheckStatus.Open,
DateExecution = currentDate,
IsEditable = true,
UserId = checkListHeaderNewDTO.UserId,
@@ -403,7 +408,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);
}
@@ -417,7 +422,6 @@ namespace WorkFlowCheck.BL.Services
return retVal;
}
public byte[] CreatePDF(int checkListHeaderId)
{
var location = System.Reflection.Assembly.GetEntryAssembly().Location;
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc.Rendering;
using WorkFlowCheck.Common.DTO;
namespace WorkFlowCheck.BL.Services.Interfaces
@@ -25,7 +21,8 @@ namespace WorkFlowCheck.BL.Services.Interfaces
Task<CheckListRowDTO> GetCheckListRowAsync(int id);
Task<CheckListRowDTO> UpdateCheckListRowAsync(CheckListRowDTO checkListRowDTO);
byte[] CreatePDF(int checkListHeaderId);
}
}
@@ -25,7 +25,11 @@ namespace WorkFlowCheck.BL.Services.Interfaces
Task<RoleCheckListTemplateHeaderDTO> GetRoleCheckListTemplateHeaderAsync(int Id);
Task<List<RoleCheckListTemplateHeaderDTO>> GetAllRoleCheckListTemplateHeadersAsync();
Task<RoleCheckListTemplateHeaderDTO> UpdateRoleCheckListTemplateHeaderAsync(RoleCheckListTemplateHeaderDTO roleCheckListTemplateHeaderDTO);
Task<RoleCheckPointDTO> GetRoleCheckPointAsync(int Id);
Task<List<RoleCheckPointDTO>> GetAllRoleCheckPointsAsync();
Task<RoleCheckPointDTO> UpdateRoleCheckPointAsync(RoleCheckPointDTO roleCheckPointDTO);
string GenerateJwtToken(UserDTO userDTO);
}
}
@@ -429,5 +429,95 @@ namespace WorkFlowCheck.BL.Services
return retVal;
}
public async Task<RoleCheckPointDTO> GetRoleCheckPointAsync(int Id)
{
var retVal = new RoleCheckPointDTO();
try
{
var userRole = await _dbContext.RoleCheckPoints.Where(w => w.Id == Id).FirstOrDefaultAsync();
if (userRole != null)
{
retVal = _mapper.Map<RoleCheckPointDTO>(userRole);
}
}
catch (Exception ex)
{
Log.Error(ex.Message);
}
return retVal;
}
public async Task<List<RoleCheckPointDTO>> GetAllRoleCheckPointsAsync()
{
var retVal = new List<RoleCheckPointDTO>();
try
{
var results = await _dbContext.RoleCheckPoints
.Include(i => i.CheckPoint)
.Include(i => i.Role)
.AsNoTracking()
.ToListAsync();
if (results != null)
{
retVal = _mapper.Map<List<RoleCheckPointDTO>>(results);
}
}
catch (Exception ex)
{
Log.Error(ex.Message);
}
return retVal;
}
public async Task<RoleCheckPointDTO> UpdateRoleCheckPointAsync(RoleCheckPointDTO roleCheckPointDTO)
{
var retVal = new RoleCheckPointDTO();
try
{
if (roleCheckPointDTO.Id == 0)
{
var roleCheckPoint_Exists = await _dbContext.RoleCheckPoints
.Where(w => w.RoleId == roleCheckPointDTO.RoleId &&
w.CheckPointId == roleCheckPointDTO.CheckPointId)
.FirstOrDefaultAsync();
if (roleCheckPoint_Exists == null)
{
var roleCheckPoint = new RoleCheckPoint();
roleCheckPoint.CheckPointId = roleCheckPointDTO.CheckPointId;
roleCheckPoint.RoleId = roleCheckPointDTO.RoleId;
roleCheckPoint.Enabled = roleCheckPointDTO.Enabled;
_dbContext.RoleCheckPoints.Add(roleCheckPoint);
await _dbContext.SaveChangesAsync();
retVal = _mapper.Map<RoleCheckPointDTO>(roleCheckPoint);
}
else
{
retVal = _mapper.Map<RoleCheckPointDTO>(roleCheckPoint_Exists);
}
}
else
{
var roleCheckPoint = await _dbContext.RoleCheckPoints.Where(w => w.Id == roleCheckPointDTO.Id).FirstOrDefaultAsync();
if (roleCheckPoint != null)
{
roleCheckPoint.CheckPointId = roleCheckPointDTO.CheckPointId;
roleCheckPoint.RoleId = roleCheckPointDTO.RoleId;
roleCheckPoint.Enabled = roleCheckPointDTO.Enabled;
await _dbContext.SaveChangesAsync();
retVal = _mapper.Map<RoleCheckPointDTO>(roleCheckPoint);
}
}
}
catch (Exception ex)
{
Log.Error(ex.Message);
}
return retVal;
}
}
}