45 lines
2.3 KiB
C#
45 lines
2.3 KiB
C#
using AutoMapper;
|
|
using DigitalData.Core.Application;
|
|
using Microsoft.Extensions.Localization;
|
|
using EnvelopeGenerator.Application.Contracts;
|
|
using EnvelopeGenerator.Domain.Entities;
|
|
using EnvelopeGenerator.Infrastructure.Contracts;
|
|
using static EnvelopeGenerator.Common.Constants;
|
|
using EnvelopeGenerator.Application.Resources;
|
|
using DigitalData.Core.DTO;
|
|
using EnvelopeGenerator.Application.DTOs.EnvelopeHistory;
|
|
|
|
namespace EnvelopeGenerator.Application.Services
|
|
{
|
|
public class EnvelopeHistoryService : CRUDService<IEnvelopeHistoryRepository, EnvelopeHistoryCreateDto, EnvelopeHistoryDto, EnvelopeHistoryDto, EnvelopeHistory, long>, IEnvelopeHistoryService
|
|
{
|
|
public EnvelopeHistoryService(IEnvelopeHistoryRepository repository, IStringLocalizer<Resource> localizer, IMapper mapper)
|
|
: base(repository, localizer, mapper)
|
|
{
|
|
}
|
|
|
|
public async Task<int> CountAsync(int? envelopeId = null, string? userReference = null, int? status = null) => await _repository.CountAsync(envelopeId: envelopeId, userReference: userReference, status: status);
|
|
|
|
public async Task<bool> HasStatus(EnvelopeStatus status, int envelopeId, string userReference) => await _repository.CountAsync(
|
|
envelopeId: envelopeId,
|
|
userReference: userReference,
|
|
status: (int) status) > 0;
|
|
|
|
public async Task<bool> AccessCodeAlreadyRequested(int envelopeId, string userReference) => await _repository.CountAsync(
|
|
envelopeId: envelopeId,
|
|
userReference:userReference,
|
|
status: (int) EnvelopeStatus.AccessCodeRequested) > 0;
|
|
|
|
public async Task<bool> IsSigned(int envelopeId, string userReference) => await _repository.CountAsync(
|
|
envelopeId: envelopeId,
|
|
userReference: userReference,
|
|
status: (int) EnvelopeStatus.DocumentSigned) > 0;
|
|
|
|
public async Task<DataResult<long>> RecordAsync(int envelopeId, string userReference, EnvelopeStatus status) =>
|
|
await CreateAsync(new (EnvelopeId: envelopeId, UserReference: userReference, Status: (int)status, ActionDate: DateTime.Now))
|
|
.ThenAsync(
|
|
Success: id => Result.Success(id),
|
|
Fail: (mssg, ntc) => Result.Fail<long>().Message(mssg).Notice(ntc)
|
|
);
|
|
}
|
|
} |