public override async Task <TransactionScheduleDto> Handle(Command request, CancellationToken cancellationToken)
            {
                var transactionSchedule = await TransactionScheduleRepository.GetByIdAsync(request.TransactionScheduleId);

                if (transactionSchedule == null)
                {
                    throw new NotFoundException("Transaction schedule was not found.");
                }
                var sourceCategoryAccessible = BudgetCategoryRepository.IsAccessibleToUser(transactionSchedule.Id);

                if (!await sourceCategoryAccessible)
                {
                    throw new NotFoundException("Source budget category was not found.");
                }

                transactionSchedule.Description      = request.Description;
                transactionSchedule.StartDate        = request.StartDate;
                transactionSchedule.Frequency        = request.Frequency;
                transactionSchedule.PeriodStep       = request.PeriodStep;
                transactionSchedule.EndDate          = request.EndDate;
                transactionSchedule.BudgetCategoryId = request.BudgetCategoryId;

                await TransactionScheduleRepository.UpdateAsync(transactionSchedule);

                await TransactionScheduleRepository.SaveChangesAsync(cancellationToken);

                return(Mapper.Map <TransactionScheduleDto>(transactionSchedule));
            }
            public override async Task <TransactionScheduleDto> Handle(Command request, CancellationToken cancellationToken)
            {
                var transactionScheduleEntity = await TransactionScheduleRepository.GetByIdAsync(request.TransactionScheduleId);

                if (transactionScheduleEntity.IsNullOrDefault() || !await BudgetCategoryRepository.IsAccessibleToUser(transactionScheduleEntity.BudgetCategoryId))
                {
                    throw new NotFoundException("Target transaction schedule was not found.");
                }

                await TransactionScheduleRepository.DeleteAsync(transactionScheduleEntity);

                await TransactionScheduleRepository.SaveChangesAsync(cancellationToken);

                return(Mapper.Map <TransactionScheduleDto>(transactionScheduleEntity));
            }
Beispiel #3
0
            public override async Task <TransactionScheduleDto> Handle(Command request, CancellationToken cancellationToken)
            {
                if (!await BudgetCategoryRepository.IsAccessibleToUser(request.BudgetCategoryId))
                {
                    throw new NotFoundException("Target budget category was not found.");
                }

                var transactionScheduleEntity = Mapper.Map <Domain.Entities.TransactionSchedule>(request);

                transactionScheduleEntity.CreatedByUserId = AuthenticationProvider.User.UserId;

                var savedTransactionSchedule = await TransactionScheduleRepository.AddAsync(transactionScheduleEntity);

                var addedRows = await TransactionScheduleRepository.SaveChangesAsync(cancellationToken);

                if (addedRows.IsNullOrDefault())
                {
                    throw new SaveFailureException(nameof(transactionScheduleEntity), transactionScheduleEntity);
                }

                return(Mapper.Map <TransactionScheduleDto>(savedTransactionSchedule));
            }