60 lines
2.2 KiB
C#
60 lines
2.2 KiB
C#
using System.Collections.Generic;
|
|
using _0_Framework.Application;
|
|
using AccountManagement.Application.Contracts.TicketAccessAccount;
|
|
using AccountManagement.Domain.AccountAgg;
|
|
using AccountManagement.Domain.TicketAccessAccountAgg;
|
|
|
|
namespace AccountManagement.Application;
|
|
|
|
public class TicketAccessAccountApplication : ITicketAccessAccountApplication
|
|
{
|
|
private readonly ITicketAccessAccountRepository _ticketAccessAccountRepository;
|
|
private readonly IAccountRepository _accountRepository;
|
|
|
|
public TicketAccessAccountApplication(ITicketAccessAccountRepository ticketAccessAccountRepository, IAccountRepository accountRepository)
|
|
{
|
|
_ticketAccessAccountRepository = ticketAccessAccountRepository;
|
|
_accountRepository = accountRepository;
|
|
}
|
|
|
|
public bool HasTicketAccess(long accountId)
|
|
{
|
|
return _ticketAccessAccountRepository.HasTicketAccess(accountId);
|
|
}
|
|
|
|
public OperationResult Create(long accountId)
|
|
{
|
|
OperationResult operation = new();
|
|
if (!_accountRepository.Exists(x => x.id == accountId && x.AdminAreaPermission == "true"))
|
|
{
|
|
return operation.Failed("شخص انتخاب شده نا معتبر است");
|
|
|
|
}
|
|
|
|
if (_ticketAccessAccountRepository.Exists(x => x.AccountId == accountId))
|
|
return operation.Failed("به این شخص قبلا دسترسی داده شده است");
|
|
|
|
TicketAccessAccount accessAccountEntity = new(accountId);
|
|
_ticketAccessAccountRepository.Create(accessAccountEntity);
|
|
_ticketAccessAccountRepository.SaveChanges();
|
|
|
|
return operation.Succcedded(accessAccountEntity.id);
|
|
|
|
}
|
|
|
|
public OperationResult Delete(long id)
|
|
{
|
|
OperationResult operation = new();
|
|
if (!_ticketAccessAccountRepository.Exists(x => x.id == id))
|
|
return operation.Failed("اطلاعات داده شده نامعتبر است");
|
|
_ticketAccessAccountRepository.Remove(id);
|
|
_ticketAccessAccountRepository.SaveChanges();
|
|
return operation.Succcedded(id);
|
|
|
|
}
|
|
|
|
public List<TicketAccessAccountViewModel> GetAllAccessedAccounts()
|
|
{
|
|
return _ticketAccessAccountRepository.GetAllAccessedAccounts();
|
|
}
|
|
} |