Esempio n. 1
0
        public async Task <IssLocationModel> Handle(IssLocationCreateRequest request, CancellationToken cancellationToken)
        {
            var issLocationModel = await _mediator.Send(new IssLocationGetRequest { }, cancellationToken);

            var issLocation = _mapper.Map <IssLocation>(issLocationModel);

            using (_repository.UseTransaction())
            {
                _repository.IssLocation.Create(issLocation);
            }

            var result = _mapper.Map <IssLocationModel>(issLocation);

            return(result);
        }
        public Task <CustomerModel> Handle(CustomerCreateRequest request, CancellationToken cancellationToken)
        {
            var customerToCreate = _mapper.Map <Customer>(request);

            var existingCustomer = _repository.Customer.FindSingle(c => c.Email == request.Email);

            if (existingCustomer != null)
            {
                throw new BusinessException("Customer already exists");
            }

            using (_repository.UseTransaction())
            {
                _repository.Customer.Create(customerToCreate);
            }

            var result = _mapper.Map <CustomerModel>(customerToCreate);

            return(Task.FromResult(result));
        }
Esempio n. 3
0
        public Task <AccountModel> Handle(AccountCreateRequest request, CancellationToken cancellationToken)
        {
            ValidateIfAccountExists(request);

            ValidateIfCustomerExists(request);

            ValidateAccountType(request);

            var accountToCreate = new Account
            {
                AccountTypeId = (int)request.AccountTypeId,
                CustomerId    = (int)request.CustomerId
            };

            using (_repository.UseTransaction())
            {
                _repository.Account.Create(accountToCreate);
            }

            var result = _mapper.Map <AccountModel>(accountToCreate);

            return(Task.FromResult(result));
        }
        public Task <IEnumerable <TransactionModel> > Handle(TransactionCreateRequest request, CancellationToken cancellationToken)
        {
            var transactionsToCreate = _mapper.Map <IEnumerable <Transaction> >(request.Transactions);

            using (_repository.UseTransaction())
            {
                var operationDate = DateTime.Now;
                var operation     = CreateOperation(request, operationDate);

                transactionsToCreate.ToList().ForEach(t =>
                {
                    t.Operation   = operation;
                    t.OperationId = operation.Id;
                    t.Date        = operationDate;
                });

                _repository.TransactionRepository.CreateMany(transactionsToCreate);
            }

            var result = _mapper.Map <IEnumerable <TransactionModel> >(transactionsToCreate);

            return(Task.FromResult(result));
        }