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));
            }
Exemplo n.º 2
0
            public override async Task <TransactionScheduleDetailsDto> Handle(Query request, CancellationToken cancellationToken)
            {
                var transactionScheduleEntity = await TransactionScheduleRepository.GetByIdAsync(request.TransactionScheduleId);

                if (transactionScheduleEntity.IsNullOrDefault() || !await BudgetCategoryRepository.IsAccessibleToUser(transactionScheduleEntity.Id))
                {
                    throw new NotFoundException("Target Transaction Schedule was not found.");
                }

                return(Mapper.Map <TransactionScheduleDetailsDto>(transactionScheduleEntity));
            }
            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));
            }
Exemplo n.º 4
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));
            }
Exemplo n.º 5
0
            public override async Task <IEnumerable <TransactionDto> > Handle(Query request, CancellationToken cancellationToken)
            {
                var schedules = await TransactionScheduleRepository.ListWithFilter(request.BudgetId, new TransactionScheduleFilterModel()
                {
                    StartDateEndFilter = DateTime.Today.AddDays(1),
                    EndDateStartFilter = DateTime.Today
                });

                var occurrences = new List <TransactionDto>();
                var startDate   = DateTime.Today.AddDays(-request.DaysBackwardLimit);
                var endDate     = DateTime.Today.AddDays(request.DaysForwardLimit);

                foreach (var schedule in schedules)
                {
                    var occurrenceDates = schedule.OccurrencesInPeriod(startDate, endDate);
                    var alreadyCreatedTransactionDates = (await TransactionScheduleRepository
                                                          .GetByIdAsync(schedule.Id))
                                                         .Transactions
                                                         .Where(x => x.TransactionDateTime.Date >= startDate && x.TransactionDateTime.Date <= endDate)
                                                         .Select(x => x.TransactionDateTime)
                                                         .ToList();

                    occurrenceDates.Except(alreadyCreatedTransactionDates)
                    .ToList()
                    .ForEach(date =>
                    {
                        occurrences.Add(new TransactionDto()
                        {
                            BudgetCategoryId      = schedule.BudgetCategoryId,
                            Amount                = schedule.Amount,
                            TransactionDate       = date,
                            Description           = schedule.Description,
                            TransactionScheduleId = schedule.Id
                        });
                    });
                }

                return(occurrences.OrderBy(x => x.TransactionDate));
            }
            public override async Task <IEnumerable <TransactionScheduleDto> > Handle(Query request, CancellationToken cancellationToken)
            {
                var schedules = await TransactionScheduleRepository.ListWithFilter(request.BudgetId, Mapper.Map <TransactionScheduleFilterModel>(request.Filters));

                return(Mapper.Map <IEnumerable <TransactionScheduleDto> >(schedules));
            }