Ejemplo n.º 1
0
            public async Task <Result> Handle(Command request, CancellationToken cancellationToken)
            {
                if (!await _accessControlService.HasAllocationAccess(request.AllocationId))
                {
                    throw new NotFoundException(Localization.For(() => ErrorMessages.AllocationNotFound));
                }
                var allocation = await _writeDbContext.Allocations
                                 .FirstOrDefaultAsync(x => x.AllocationId == request.AllocationId, cancellationToken : cancellationToken)
                                 ?? throw new NotFoundException(Localization.For(() => ErrorMessages.TransactionNotFound));

                var oldDate = allocation.AllocationDate;

                allocation.SetAllocationDate(request.AllocationDate);

                await _writeDbContext.SaveChangesAsync(cancellationToken);

                _ = _mediator.Publish(new Notification()
                {
                    ReferenceAllocation = allocation,
                    OldAllocationDate   = oldDate,
                    NewAllocationDate   = allocation.AllocationDate
                }, cancellationToken);

                return(new Result()
                {
                    Data = allocation.AllocationDate
                });
            }
Ejemplo n.º 2
0
            public async Task <Result> Handle(Command request, CancellationToken cancellationToken)
            {
                if (!await _accessControlService.HasAllocationAccess(request.AllocationId))
                {
                    throw new NotFoundException(Localization.For(() => ErrorMessages.TransactionNotFound));
                }

                if (request.SourceBudgetCategoryId != null && !await _accessControlService.HasBudgetCategoryAccessAsync(request.SourceBudgetCategoryId))
                {
                    throw new NotFoundException(Localization.For(() => ErrorMessages.BudgetCategoryNotFound));
                }

                var allocation = await _writeDbContext.Allocations
                                 .FirstAsync(x => x.AllocationId == request.AllocationId, cancellationToken : cancellationToken);

                var oldBudgetCategory = allocation.SourceBudgetCategoryId != null
                                        ? await _writeDbContext.BudgetCategories.FirstAsync(x => x.BudgetCategoryId == allocation.SourceBudgetCategoryId, cancellationToken : cancellationToken)
                                        : null;

                var newBudgetCategory = request.SourceBudgetCategoryId != null
                                        ? await _writeDbContext.BudgetCategories.FirstAsync(x => x.BudgetCategoryId == request.SourceBudgetCategoryId, cancellationToken : cancellationToken)
                                        : null;

                if (oldBudgetCategory != null && newBudgetCategory != null && oldBudgetCategory?.BudgetCategoryType != newBudgetCategory?.BudgetCategoryType)
                {
                    throw new BusinessException(Localization.For(() => ErrorMessages.NotSameBudgetCategoryType));
                }

                var oldCategoryId = allocation.SourceBudgetCategoryId;

                allocation.SetSourceBudgetCategory(newBudgetCategory);

                await _writeDbContext.SaveChangesAsync(cancellationToken);

                _ = _mediator.Publish(new Notification()
                {
                    ReferenceAllocation = allocation,
                    OldBudgetCategoryId = oldCategoryId,
                    NewBudgetCategoryId = allocation.SourceBudgetCategoryId
                }, cancellationToken);
                return(new Result()
                {
                    Id = allocation.SourceBudgetCategoryId
                });
            }
Ejemplo n.º 3
0
            public async Task <Result> Handle(Command request, CancellationToken cancellationToken)
            {
                var allocation = await _writeDbContext.Allocations
                                 .FirstOrDefaultAsync(x => x.AllocationId == request.AllocationId, cancellationToken : cancellationToken)
                                 ?? throw new NotFoundException(Localization.For(() => ErrorMessages.AllocationNotFound));

                if (!await _accessControlService.HasAllocationAccess(allocation.AllocationId))
                {
                    throw new NotFoundException(Localization.For(() => ErrorMessages.AllocationNotFound));
                }

                allocation.SoftDelete();

                await _writeDbContext.SaveChangesAsync(cancellationToken);

                _ = _mediator.Publish(new Notification()
                {
                    ReferenceAllocation = allocation
                }, cancellationToken);

                return(new Result()
                {
                });
            }