using System; using System.Collections.Generic; using _0_Framework.Application; using Company.Application.Contracts.AuthorizedBankDetails; using Company.Domain.AuthorizedBankDetailsAgg; using CompanyManagment.App.Contracts.AuthorizedBankDetails; namespace CompanyManagment.Application { public class AuthorizedBankDetailsApplication : IAuthorizedBankDetailsApplication { private readonly IAuthorizedBankDetailsRepository _authorizedBankDetailsRepository; public AuthorizedBankDetailsApplication(IAuthorizedBankDetailsRepository authorizedBankDetailsRepository) { _authorizedBankDetailsRepository = authorizedBankDetailsRepository; } public OperationResult Create(CreateAuthorizedBankDetails command) { var operation = new OperationResult(); if (_authorizedBankDetailsRepository.Exists(x => x.CardNumber == command.CardNumber && x.AccountNumber == command.AccountNumber && x.IBan == command.IBan)) return operation.Failed(ApplicationMessages.DuplicatedRecord); var ownersList = new List(); if (command.OwnersList != null && command.OwnersList.Count > 0) { foreach (var owner in command.OwnersList) { var bankDetailsOwner = new AuthorizedBankDetailsOwner( owner.FName, owner.LName, owner.NationalIdentifier, owner.CustomerType ); ownersList.Add(bankDetailsOwner); } } var authorizedBankDetails = new AuthorizedBankDetails( command.CardNumber, command.AccountNumber, command.IBan, command.BankName, ownersList ); _authorizedBankDetailsRepository.Create(authorizedBankDetails); _authorizedBankDetailsRepository.SaveChanges(); return operation.Succcedded(); } public EditAuthorizedBankDetails GetDetails(long id) { return _authorizedBankDetailsRepository.GetDetails(id); } public List Search(AuthorizedBankDetailsSearchModel searchModel) { return _authorizedBankDetailsRepository.Search(searchModel); } public AuthorizedBankDetailsViewModel GetByIban(string iban) { return _authorizedBankDetailsRepository.GetByIban(iban); } } }