Exemplo n.º 1
0
 public ClientAppService(IClientRepository clientRepository,
                         ILogger <ClientAppService> logger)
 {
     _clientRepository = clientRepository;
     _logger           = logger;
     _resources        = LocalizationFactory.CreateLocalResources();
 }
Exemplo n.º 2
0
        /// <summary>
        /// Create a new instance
        /// </summary>
        public BankAppService(IBankAccountRepository bankAccountRepository, // the bank account repository dependency
                              ICustomerRepository customerRepository,       // the customer repository dependency
                              IBankTransferService transferService,
                              ILogger <BankAppService> logger)
        {
            //check preconditions
            if (bankAccountRepository == null)
            {
                throw new ArgumentNullException("bankAccountRepository");
            }

            if (customerRepository == null)
            {
                throw new ArgumentNullException("customerRepository");
            }

            if (transferService == null)
            {
                throw new ArgumentNullException("trasferService");
            }

            _bankAccountRepository = bankAccountRepository;
            _customerRepository    = customerRepository;
            _transferService       = transferService;

            _logger    = logger;
            _resources = LocalizationFactory.CreateLocalResources();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Create a new instance of sales management service
        /// </summary>
        /// <param name="orderRepository">The associated order repository</param>
        /// <param name="productRepository">The associated product repository</param>
        /// <param name="customerRepository">The associated customer repository</param>
        public SalesAppService(IProductRepository productRepository,   //associated product repository
                               IOrderRepository orderRepository,       //associated order repository
                               ICustomerRepository customerRepository, //the associated customer repository
                               ILogger <SalesAppService> logger)
        {
            if (orderRepository == null)
            {
                throw new ArgumentNullException("orderRepository");
            }

            if (productRepository == null)
            {
                throw new ArgumentNullException("productRepository");
            }

            if (customerRepository == null)
            {
                throw new ArgumentNullException("customerRepository");
            }

            _orderRepository    = orderRepository;
            _productRepository  = productRepository;
            _customerRepository = customerRepository;

            _logger    = logger;
            _resources = LocalizationFactory.CreateLocalResources();
        }
Exemplo n.º 4
0
        public void PerformTransfer(decimal amount, BankAccount originAccount, BankAccount destinationAccount)
        {
            if (originAccount != null && destinationAccount != null)
            {
                var messages = LocalizationFactory.CreateLocalResources();

                if (originAccount.BankAccountNumber == destinationAccount.BankAccountNumber) // if transfer in same bank account
                {
                    throw new InvalidOperationException(messages.GetStringResource(LocalizationKeys.Domain.exception_CannotTransferMoneyWhenFromIsTheSameAsTo));
                }

                // Check if customer has required credit and if the BankAccount is not locked
                if (originAccount.CanBeWithdrawed(amount))
                {
                    //Domain Logic
                    //Process: Perform transfer operations to in-memory Domain-Model objects
                    // 1.- Charge money to origin acc
                    // 2.- Credit money to destination acc

                    //Charge money
                    originAccount.WithdrawMoney(amount, string.Format(messages.GetStringResource(LocalizationKeys.Domain.messages_TransactionFromMessage), destinationAccount.Id));

                    //Credit money
                    destinationAccount.DepositMoney(amount, string.Format(messages.GetStringResource(LocalizationKeys.Domain.messages_TransactionToMessage), originAccount.Id));
                }
                else
                {
                    throw new InvalidOperationException(messages.GetStringResource(LocalizationKeys.Domain.exception_BankAccountCannotWithdraw));
                }
            }
        }
Exemplo n.º 5
0
 public ContactAppService(IContactRepository contactRepository,
                          ILogger <ContactAppService> logger)
 {
     _contactRepository = contactRepository;
     _logger            = logger;
     _resources         = LocalizationFactory.CreateLocalResources();
 }
Exemplo n.º 6
0
        public void PerformCharge(Charge charge)
        {
            var card     = charge.Card;
            var messages = LocalizationFactory.CreateLocalResources();

            if (card != null)
            {
                if (charge.Status != ChargeStatus.Pending)
                {
                    throw new InvalidOperationException(messages.GetStringResource(LocalizationKeys.Domain.exception_InvalidStateForCharge));
                }
                if (card.CanWithdraw(charge.Amount))
                {
                    card.WithdrawMoney(charge.Amount,
                                       MovementType.CON,
                                       messages.GetStringResource(LocalizationKeys.Domain.messages_ChargeMessageDescription),
                                       messages.GetStringResource(LocalizationKeys.Domain.messages_ChargeMessageDisplayName),
                                       charge.Movements.FirstOrDefault()
                                       );
                    charge.Status = ChargeStatus.Accepted;
                    charge.GenerateOperationCode();
                    charge.ImageUrl = GenerateChargeUrl();
                }
                else
                {
                    charge.Status = ChargeStatus.Canceled;
                }
            }
            else
            {
                throw new InvalidOperationException(messages.GetStringResource(LocalizationKeys.Domain.exception_PerformChargeCardIsNull));
            }
        }
 public AuthenticationController(IAuthenticationAppService authenticationAppService, IConfiguration configuration)
 {
     _authenticationAppService = authenticationAppService;
     _smsManager   = new SMSManager(configuration);
     _tokenManager = new TokenManager(configuration);
     _resources    = LocalizationFactory.CreateLocalResources();
 }
Exemplo n.º 8
0
 public ChargeAppService(IChargeRepository chargeRepository,
                         ICardChargeService cardChargeService)
 {
     _chargeRepository  = chargeRepository;
     _cardChargeService = cardChargeService;
     _resources         = LocalizationFactory.CreateLocalResources();
 }
Exemplo n.º 9
0
 public CardAppService(IContactRepository contactRepository,
                       ICardRepository cardRepository)
 {
     _contactRepository = contactRepository;
     _cardRepository    = cardRepository;
     _resources         = LocalizationFactory.CreateLocalResources();
 }
Exemplo n.º 10
0
        public BlogsService(IBlogRepository blogRepository, IPostRepository postRepository)
            : base(blogRepository)
        {
            _blogRepository = blogRepository;
            _postRepository = postRepository;

            _resources = LocalizationFactory.CreateLocalResources();
            _validator = EntityValidatorFactory.CreateValidator();
        }
        /// <summary>
        /// The get <paramref name="key"/> from enum.
        /// </summary>
        /// <param name="key">
        /// The key.
        /// </param>
        /// <typeparam name="T">d d
        /// </typeparam>
        /// <returns>
        /// The <see cref="string"/>.
        /// </returns>
        /// <exception cref="ArgumentException">Argument Exception
        /// </exception>
        private string GetKeyFromEnum <T>(T key) where T : struct, IConvertible
        {
            if (!typeof(T).GetTypeInfo().IsEnum)
            {
                throw new ArgumentException(LocalizationFactory.CreateLocalResources().GetStringResource(LocalizationKeys.Infrastructure.ExceptionInvalidEnumeratedType));
            }

            return($"{typeof(T).Name}_{key.ToString()}");
        }
Exemplo n.º 12
0
 public LoadAppService(IClientRepository clientRepository,
                       IContactRepository contactRepository,
                       ICardTypeRepository cardTypeRepository,
                       ICardRechargeService rechargeService)
 {
     _clientRepository   = clientRepository;
     _contactRepository  = contactRepository;
     _cardTypeRepository = cardTypeRepository;
     _rechargeService    = rechargeService;
     _resources          = LocalizationFactory.CreateLocalResources();
 }
Exemplo n.º 13
0
 public TransferAppService(IContactRepository contactRepository,
                           ICardRepository cardRepository,
                           ITransferRepository transferRepository,
                           ICardTransferService transferService)
 {
     _contactRepository  = contactRepository;
     _cardRepository     = cardRepository;
     _transferRepository = transferRepository;
     _transferService    = transferService;
     _resources          = LocalizationFactory.CreateLocalResources();
 }
Exemplo n.º 14
0
 public virtual void Modify(TEntity item)
 {
     if (item != (TEntity)null)
     {
         _UnitOfWork.SetModified(item);
     }
     else
     {
         _logger.LogInformation(LocalizationFactory.CreateLocalResources().GetStringResource(LocalizationKeys.Infrastructure.info_CannotModifyNullEntity), typeof(TEntity).ToString());
     }
 }
Exemplo n.º 15
0
 public virtual void Add(TEntity item)
 {
     if (item != (TEntity)null)
     {
         GetSet().Add(item); // add new item in this set
     }
     else
     {
         _logger.LogInformation(LocalizationFactory.CreateLocalResources().GetStringResource(LocalizationKeys.Infrastructure.info_CannotAddNullEntity), typeof(TEntity).ToString());
     }
 }
Exemplo n.º 16
0
 public virtual void TrackItem(TEntity item)
 {
     if (item != (TEntity)null)
     {
         _UnitOfWork.Attach <TEntity>(item);
     }
     else
     {
         _logger.LogInformation(LocalizationFactory.CreateLocalResources().GetStringResource(LocalizationKeys.Infrastructure.info_CannotTrackNullEntity), typeof(TEntity).ToString());
     }
 }
Exemplo n.º 17
0
        public PostDTOValidator()
        {
            var _resources = LocalizationFactory.CreateLocalResources();

            RuleFor(b => b.Title)
            .NotEmpty().WithMessage(_resources.GetStringResource(LocalizationKeys.Application.validation_PostDto_Empty_Title));

            RuleFor(b => b.Content)
            .NotEmpty().WithMessage(_resources.GetStringResource(LocalizationKeys.Application.validation_PostDto_Empty_Content));

            RuleFor(b => b.BlogId)
            .LessThan(0).WithMessage(_resources.GetStringResource(LocalizationKeys.Application.validation_PostDto_Invalid_BlogId));
        }
Exemplo n.º 18
0
        public BlogDTOValidator()
        {
            var _resources = LocalizationFactory.CreateLocalResources();

            RuleFor(b => b.Name)
            .NotEmpty().WithMessage(_resources.GetStringResource(LocalizationKeys.Application.validation_BlogDto_Empty_Name));

            RuleFor(b => b.Url)
            .NotEmpty().WithMessage(_resources.GetStringResource(LocalizationKeys.Application.validation_BlogDto_Empty_Url));

            RuleFor(b => b.Rating)
            .GreaterThan(-1).LessThan(6).WithMessage(_resources.GetStringResource(LocalizationKeys.Application.validation_BlogDto_Invalid_Rating));
        }
Exemplo n.º 19
0
 public AuthenticationAppService(IContactRepository contactRepository,
                                 ISMSCodeRepository smsCodeRepository,
                                 ICashierRepository cashierRepository,
                                 IAdminRepository adminRepository,
                                 IConfiguration configuration,
                                 ILogger <AuthenticationAppService> logger)
 {
     _contactRepository = contactRepository;
     _smsCodeRepository = smsCodeRepository;
     _cashierRepository = cashierRepository;
     _adminRepository   = adminRepository;
     _logger            = logger;
     _resources         = LocalizationFactory.CreateLocalResources();
 }
Exemplo n.º 20
0
        public void PerformTransfer(Transfer transfer)
        {
            var messages    = LocalizationFactory.CreateLocalResources();
            var originCard  = transfer.OriginCard;
            var destinyCard = transfer.DestinyCard;

            if (originCard is null)
            {
                throw new InvalidOperationException(messages.GetStringResource(LocalizationKeys.Domain.exception_PerformTransferOriginCardIsNull));
            }

            if (destinyCard is null)
            {
                throw new InvalidOperationException(messages.GetStringResource(LocalizationKeys.Domain.exception_PerformTransferDestinyCardIsNull));
            }

            if (originCard.Id == destinyCard.Id)
            {
                throw new InvalidOperationException(messages.GetStringResource(LocalizationKeys.Domain.exception_InvalidTransferToSameCard));
            }

            if (originCard.Contact.ClientId != destinyCard.Contact.ClientId)
            {
                throw new InvalidOperationException(messages.GetStringResource(LocalizationKeys.Domain.exception_InvalidTransferDifferentContactClient));
            }

            if (originCard.CanWithdraw(transfer.Amount))
            {
                var movementBatchs = originCard.WithdrawMoney(
                    transfer.Amount,
                    MovementType.STR,
                    messages.GetStringResource(LocalizationKeys.Domain.messages_TransferFromMessageDescription),
                    messages.GetStringResource(LocalizationKeys.Domain.messages_TransferFromMessageDisplayName),
                    movement: null,
                    transfer
                    );
                destinyCard.DepositMoneyFromTransfer(
                    transfer.Amount,
                    movementBatchs,
                    messages.GetStringResource(LocalizationKeys.Domain.messages_TransferToMessageDescription),
                    messages.GetStringResource(LocalizationKeys.Domain.messages_TransferToMessageDisplayName),
                    transfer
                    );
            }
            else
            {
                throw new InvalidOperationException(messages.GetStringResource(LocalizationKeys.Domain.exception_NoEnoughMoneyToTransfer));
            }
            transfer.ImageUrl = GenerateTransferUrl();
        }
Exemplo n.º 21
0
 public virtual void Add(IEnumerable <TEntity> items)
 {
     if (items != null)
     {
         foreach (var item in items)
         {
             this.Add(item);
         }
     }
     else
     {
         _logger.LogInformation(LocalizationFactory.CreateLocalResources().GetStringResource(LocalizationKeys.Infrastructure.info_CannotAddNullEntity), typeof(TEntity).ToString());
     }
 }
Exemplo n.º 22
0
        public virtual void Remove(TEntity item)
        {
            if (item != (TEntity)null)
            {
                //attach item if not exist
                _UnitOfWork.Attach(item);

                //set as "removed"
                GetSet().Remove(item);
            }
            else
            {
                _logger.LogInformation(LocalizationFactory.CreateLocalResources().GetStringResource(LocalizationKeys.Infrastructure.info_CannotRemoveNullEntity), typeof(TEntity).ToString());
            }
        }
Exemplo n.º 23
0
        /// <summary>
        /// Order by order number
        /// </summary>
        /// <param name="orderNumber">Find orders using the order number</param>
        /// <returns>Related specification for this criterion</returns>
        public static ISpecification <Order> OrdersByNumber(string orderNumber)
        {
            var messages = LocalizationFactory.CreateLocalResources();

            string orderNumberPattern = @"\d{4}/\d{1,2}-\d+";

            if (Regex.IsMatch(orderNumber, orderNumberPattern))
            {
                int sequenceNumber = Int32.Parse(Regex.Split(orderNumber, "-")[1]);
                return(new DirectSpecification <Order>(o => o.SequenceNumberOrder == sequenceNumber));
            }
            else
            {
                throw new InvalidOperationException(messages.GetStringResource(LocalizationKeys.Domain.exception_OrderNumberSpecificationInvalidOrderNumberPattern));
            }
        }
Exemplo n.º 24
0
        public void PerformRecharge(Card card, Batch batch)
        {
            var messages = LocalizationFactory.CreateLocalResources();

            if (card != null)
            {
                card.RechargeMoney(
                    batch,
                    messages.GetStringResource(LocalizationKeys.Domain.messages_RechargeMessageDescription),
                    messages.GetStringResource(LocalizationKeys.Domain.messages_RechargeMessageDisplayName)
                    );
            }
            else
            {
                throw new InvalidOperationException(messages.GetStringResource(LocalizationKeys.Domain.exception_PerformRechargeCardIsNull));
            }
        }
Exemplo n.º 25
0
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            ILocalization messages = LocalizationFactory.CreateLocalResources();

            var validationResults = new List <ValidationResult>();

            if (AmountInStock < 0)
            {
                validationResults.Add(new ValidationResult(messages.GetStringResource(LocalizationKeys.Domain.validation_ProductAmountLessThanZero), new string[] { "AmountInStock" }));
            }

            if (UnitPrice < 0)
            {
                validationResults.Add(new ValidationResult(messages.GetStringResource(LocalizationKeys.Domain.validation_ProductUnitPriceLessThanZero), new string[] { "UnitPrice" }));
            }

            return(validationResults);
        }
Exemplo n.º 26
0
        /// <summary>
        /// Create a new instance of Customer Management Service
        /// </summary>
        /// <param name="customerRepository">Associated CustomerRepository, intented to be resolved with DI</param>
        /// <param name="countryRepository">Associated country repository</param>
        public CustomerAppService(ICountryRepository countryRepository,   //the country repository
                                  ICustomerRepository customerRepository, //the customer repository
                                  ILogger <CustomerAppService> logger)
        {
            if (customerRepository == null)
            {
                throw new ArgumentNullException("customerRepository");
            }

            if (countryRepository == null)
            {
                throw new ArgumentNullException("countryRepository");
            }

            _countryRepository  = countryRepository;
            _customerRepository = customerRepository;

            _logger    = logger;
            _resources = LocalizationFactory.CreateLocalResources();
        }
Exemplo n.º 27
0
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            var resources         = LocalizationFactory.CreateLocalResources();
            var validationResults = new List <ValidationResult>();

            if (string.IsNullOrEmpty(Title))
            {
                validationResults.Add(new ValidationResult(string.Format(resources.GetStringResource(LocalizationKeys.Domain.validation_PropertyIsEmptyOrNull), "Title", "Post"), new string[] { "Title" }));
            }

            if (string.IsNullOrEmpty(Content))
            {
                validationResults.Add(new ValidationResult(string.Format(resources.GetStringResource(LocalizationKeys.Domain.validation_PropertyIsEmptyOrNull), "Content", "Post"), new string[] { "Content" }));
            }

            if (BlogId < 1)
            {
                validationResults.Add(new ValidationResult(string.Format(resources.GetStringResource(LocalizationKeys.Domain.validation_PropertyOutOfRange), "BlogId", "Blog", "0", "Int32.MaxValue"), new string[] { "BlogId" }));
            }

            return(validationResults);
        }
Exemplo n.º 28
0
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            var resources         = LocalizationFactory.CreateLocalResources();
            var validationResults = new List <ValidationResult>();

            if (string.IsNullOrEmpty(Name))
            {
                validationResults.Add(new ValidationResult(string.Format(resources.GetStringResource(LocalizationKeys.Domain.validation_PropertyIsEmptyOrNull), "Name", "Blog"), new string[] { "Name" }));
            }

            if (string.IsNullOrEmpty(Url))
            {
                validationResults.Add(new ValidationResult(string.Format(resources.GetStringResource(LocalizationKeys.Domain.validation_PropertyIsEmptyOrNull), "Url", "Blog"), new string[] { "Url" }));
            }

            if (Rating < 0 && Rating > 5)
            {
                validationResults.Add(new ValidationResult(string.Format(resources.GetStringResource(LocalizationKeys.Domain.validation_PropertyOutOfRange), "Rating", "Blog", "-1", "5"), new string[] { "Rating" }));
            }

            return(validationResults);
        }
Exemplo n.º 29
0
 public Service(IRepository <TEntity> repository)
 {
     _repository = repository;
     _resources  = LocalizationFactory.CreateLocalResources();
     _validator  = EntityValidatorFactory.CreateValidator();
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ApplicationValidationErrorsException"/> class.
 /// Create new instance of Application validation errors exception
 /// </summary>
 /// <param name="validationErrors">
 /// The collection of validation errors
 /// </param>
 public ApplicationValidationErrorsException(IEnumerable <string> validationErrors)
     : base(LocalizationFactory.CreateLocalResources().GetStringResource(LocalizationKeys.Application.ValidationException))
 {
     this.validationErrors = validationErrors;
 }