Beispiel #1
0
        public async Task <CourseViewModel> AddAsync(CourseViewModel courseViewModel)
        {
            var model = _mapper.Map <Course>(courseViewModel);

            model.Id       = 0;
            model.Category = null;

            var validation = new RegisterCourseValidation().Validate(model);

            if (!validation.IsValid)
            {
                _domainNotification.AddNotifications(validation);
                return(courseViewModel);
            }

            await ValidateBusinessRulesAsync(courseViewModel);

            if (!_domainNotification.HasNotifications)
            {
                _courseRepository.Add(model);
                _unitOfWork.Commit();

                var viewModel = _mapper.Map <CourseViewModel>(model);

                return(viewModel);
            }

            return(courseViewModel);
        }
Beispiel #2
0
        public CustomerViewModel Add(CustomerViewModel customerVM)
        {
            CustomerViewModel viewModel = null;
            var model = _mapper.Map <Customer>(customerVM);

            var validation = new CustomerInsertValidation(_customerRepository).Validate(model);

            if (!validation.IsValid)
            {
                _domainNotification.AddNotifications(validation);
                return(viewModel);
            }

            /*
             * EXEMPLO COM TRANSAÇÃO:
             * Adicione a função "BeginTransaction()": _unitOfWork.BeginTransaction();
             * Utilize transação somente se realizar mais de uma operação no banco de dados ou banco de dados distintos
             */

            _customerRepository.Add(model);
            _unitOfWork.Commit();

            viewModel = _mapper.Map <CustomerViewModel>(model);

            return(viewModel);
        }
Beispiel #3
0
        public async Task <TransactionViewModel> Transaction(TransactionInputViewModel transactionVM)
        {
            TransactionViewModel viewModel = null;
            var transaction = _mapper.Map <Transaction>(transactionVM);
            var validation  = await new TransactionInsertValidation().ValidateAsync(transaction);

            if (!validation.IsValid)
            {
                _notification.AddNotifications(validation);
                return(viewModel);
            }

            switch (transaction.TransactionType)
            {
            case ETransactionType.Debit:
                await _transactionService.DebitAccount(transaction);

                break;

            case ETransactionType.Deposit:
            case ETransactionType.BankIncome:
            {
                await _transactionService.DepositAccount(transaction);

                break;
            }

            case ETransactionType.Transfer:
                await _transactionService.TransferAccount(transaction);

                break;

            default:
                _notification.AddNotification("transaction", "Tipo de transação não disponível.");
                return(null);
            }

            viewModel = _mapper.Map <TransactionViewModel>(transaction);
            return(viewModel);
        }