Egyéb javítások
This commit is contained in:
@@ -86,6 +86,26 @@ namespace WorkFlowCheck.API.Controllers
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
[HttpPost("UpdateAllCheckPoint")]
|
||||
public async Task<ApiResponseDTO<List<CheckPointDTO>>> UpdateAllCheckPoint([FromBody] List<CheckPointDTO> checkPointListDTO)
|
||||
{
|
||||
var retVal = new ApiResponseDTO<List<CheckPointDTO>>()
|
||||
{
|
||||
IsSuccess = true
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
var result = await _syncService.UpdateAllCheckPointAsync(checkPointListDTO);
|
||||
retVal.Data = result;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
retVal.IsSuccess = false;
|
||||
Log.Error(ex.Message);
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
|
||||
|
||||
[HttpGet("GetEquipment/{id}")]
|
||||
|
||||
@@ -46,6 +46,9 @@ namespace WorkFlowCheck.BL.Mappings
|
||||
CreateMap<CheckListHeader, CheckListHeaderDTO>()
|
||||
.ForMember(dest => dest.UserDTO, opt => opt.MapFrom(src => src.User))
|
||||
.ForMember(dest => dest.CheckListRowDTO, opt => opt.MapFrom(src => src.CheckListRows));
|
||||
|
||||
CreateMap<CheckListRow, CheckListRowDTO>()
|
||||
.ForMember(dest => dest.CheckListTemplateRowDTO, opt => opt.MapFrom(src => src.CheckListTemplateRow));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ namespace WorkFlowCheck.BL.Services
|
||||
{
|
||||
var roles = await _dbContext.CheckListHeaders
|
||||
.Include(i => i.CheckListRows)
|
||||
.Include(i=>i.User)
|
||||
.Include(i => i.User)
|
||||
.AsNoTracking()
|
||||
.ToListAsync();
|
||||
if (roles != null)
|
||||
@@ -121,7 +121,7 @@ namespace WorkFlowCheck.BL.Services
|
||||
{
|
||||
CheckListRowDTO = new List<CheckListRowDTO>()
|
||||
};
|
||||
|
||||
using var transaction = await _dbContext.Database.BeginTransactionAsync();
|
||||
try
|
||||
{
|
||||
var checkListTemplateHeader = await _dbContext.CheckListTemplateHeaders
|
||||
@@ -132,7 +132,7 @@ namespace WorkFlowCheck.BL.Services
|
||||
return retVal;
|
||||
}
|
||||
var currentDate = DateTime.UtcNow;
|
||||
var documentNumber = await _numberGeneratorService.GenerateNextNumberAsync(checkListTemplateHeader.NumberGenerator1Id ?? 1, currentDate);
|
||||
var documentNumber = await _numberGeneratorService.GenerateNextNumberAsync(checkListTemplateHeader.NumberGenerator1Id ?? 1, transaction, currentDate);
|
||||
CheckListHeader checkListHeader = new CheckListHeader()
|
||||
{
|
||||
CheckListTemplateHeaderId = checkListHeaderNewDTO.CheckListTemplateHeaderId,
|
||||
@@ -147,13 +147,37 @@ namespace WorkFlowCheck.BL.Services
|
||||
IsStorno = false,
|
||||
CheckListRows = new List<CheckListRow>()
|
||||
};
|
||||
|
||||
|
||||
_dbContext.CheckListHeaders.Add(checkListHeader);
|
||||
await _dbContext.SaveChangesAsync();
|
||||
|
||||
var checkListTemplateRows = await _dbContext.CheckListTemplateRows
|
||||
.Where(w => w.CheckListTemplateHeaderId == checkListHeaderNewDTO.CheckListTemplateHeaderId)
|
||||
.OrderBy(o => o.RowIndex)
|
||||
.ToListAsync();
|
||||
foreach (var item in checkListTemplateRows)
|
||||
{
|
||||
CheckListRow checkListRow = new CheckListRow()
|
||||
{
|
||||
Answer = "",
|
||||
CheckListHeaderId = checkListHeader.Id,
|
||||
CheckListTemplateRowId = item.Id,
|
||||
GuidNumber = Guid.NewGuid(),
|
||||
IsDeleted = false,
|
||||
Photo = new byte[0],
|
||||
};
|
||||
_dbContext.CheckListRows.Add(checkListRow);
|
||||
}
|
||||
|
||||
await _dbContext.SaveChangesAsync();
|
||||
await transaction.CommitAsync();
|
||||
|
||||
retVal = _mapper.Map<CheckListHeaderDTO>(checkListHeader);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await transaction.RollbackAsync();
|
||||
Log.Error(ex.Message);
|
||||
}
|
||||
return retVal;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Storage;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@@ -8,7 +9,7 @@ namespace WorkFlowCheck.BL.Services.Interfaces
|
||||
{
|
||||
public interface INumberGeneratorService
|
||||
{
|
||||
Task<string> GenerateNextNumberAsync(int templateId, DateTime? baseDate = null);
|
||||
Task<string> GenerateNextNumberAsync(int templateId, IDbContextTransaction transaction, DateTime? baseDate = null);
|
||||
Task<string> GetSampleAsync(int templateId, DateTime? baseDate = null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,8 +8,9 @@ namespace WorkFlowCheck.BL.Services.Interfaces
|
||||
Task<List<CheckPointDTO>> GetAllCheckPointAsync();
|
||||
Task<CheckPointDTO> GetCheckPointAsync(int id);
|
||||
Task<CheckPointDTO> UpdateCheckPointAsync(CheckPointDTO checkPointDTO);
|
||||
|
||||
|
||||
Task<List<CheckPointDTO>> UpdateAllCheckPointAsync(List<CheckPointDTO> checkPointListDTO);
|
||||
|
||||
|
||||
Task<List<LocationDTO>> GetAllLocationAsync();
|
||||
Task<LocationDTO> GetLocationAsync(int id);
|
||||
Task<LocationDTO> UpdateLocationAsync(LocationDTO LocationDTO);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Storage;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -20,14 +21,13 @@ namespace WorkFlowCheck.BL.Services
|
||||
_dbContext = dbContext;
|
||||
}
|
||||
|
||||
public async Task<string> GenerateNextNumberAsync(int templateId, DateTime? baseDate = null)
|
||||
public async Task<string> GenerateNextNumberAsync(int templateId, IDbContextTransaction transaction, DateTime? baseDate = null)
|
||||
{
|
||||
var semaphore = GetOrCreateSemaphore(templateId);
|
||||
await semaphore.WaitAsync();
|
||||
|
||||
try
|
||||
{
|
||||
using var transaction = await _dbContext.Database.BeginTransactionAsync();
|
||||
|
||||
var template = await _dbContext.Set<NumberGeneratorTemplate>()
|
||||
.FirstOrDefaultAsync(t => t.Id == templateId);
|
||||
@@ -60,13 +60,10 @@ namespace WorkFlowCheck.BL.Services
|
||||
|
||||
templateDate.LastGeneratedNumber = result;
|
||||
await _dbContext.SaveChangesAsync();
|
||||
await transaction.CommitAsync();
|
||||
|
||||
return result;
|
||||
}
|
||||
catch
|
||||
{
|
||||
await _dbContext.Database.RollbackTransactionAsync();
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
|
||||
@@ -101,8 +101,33 @@ namespace WorkFlowCheck.BL.Services
|
||||
|
||||
return retVal;
|
||||
}
|
||||
public async Task<List<CheckPointDTO>> UpdateAllCheckPointAsync(List<CheckPointDTO> checkPointListDTO)
|
||||
{
|
||||
var retVal = new List<CheckPointDTO>();
|
||||
try
|
||||
{
|
||||
var ids = checkPointListDTO.Select(dto => dto.Id).ToList();
|
||||
var checkPoints = await _dbContext.CheckPoints
|
||||
.Where(cp => ids.Contains(cp.Id))
|
||||
.ToListAsync();
|
||||
|
||||
|
||||
foreach (var checkPoint in checkPoints)
|
||||
{
|
||||
var dto = checkPointListDTO.FirstOrDefault(d => d.Id == checkPoint.Id);
|
||||
if (dto != null)
|
||||
{
|
||||
checkPoint.Code = dto.Code;
|
||||
}
|
||||
}
|
||||
await _dbContext.SaveChangesAsync();
|
||||
retVal = _mapper.Map<List<CheckPointDTO>>(checkPoints);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex.Message);
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
|
||||
public async Task<List<LocationDTO>> GetAllLocationAsync()
|
||||
{
|
||||
@@ -180,10 +205,6 @@ namespace WorkFlowCheck.BL.Services
|
||||
return retVal;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public async Task<List<EquipmentDTO>> GetAllEquipmentAsync()
|
||||
{
|
||||
var retVal = new List<EquipmentDTO>();
|
||||
|
||||
@@ -11,6 +11,7 @@ namespace WorkFlowCheck.Common.DTO
|
||||
public int Id { get; set; }
|
||||
public int CheckListHeaderId { get; set; }
|
||||
public int CheckListTemplateRowId { get; set; }
|
||||
public virtual CheckListTemplateRowDTO CheckListTemplateRowDTO { get; set; }
|
||||
public string Answer { get; set; } = null!;
|
||||
public byte[] Photo { get; set; } = null!;
|
||||
public Guid GuidNumber { get; set; }
|
||||
|
||||
Reference in New Issue
Block a user