示例#1
0
        public static Allocation <int> Allocate(int value, int count)
        {
            int q = DivRem(value, count, out int rem);

            //var seq = Enumerable.Repeat(q, count);

            return(Allocation.Create(value, q, rem, count));
        }
示例#2
0
        public static Allocation <long> Allocate(long value, int count)
        {
            long q = DivRem(value, count, out long rem);

            //var seq = Enumerable.Repeat(q, count);

            return(Allocation.Create(value, q, rem, count));
        }
示例#3
0
            public async Task <Result> Handle(Command request, CancellationToken cancellationToken)
            {
                var targetBudgetCategoryId = request.TargetBudgetCategoryId;

                if (!await _accessControlService.HasBudgetCategoryAccessAsync(targetBudgetCategoryId))
                {
                    throw new NotFoundException(Localization.For(() => ErrorMessages.BudgetNotFound));
                }

                var sourceBudgetCategoryId = request.SourceBudgetCategoryId;

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

                var targetBudgetCategory = _writeDbContext.BudgetCategories
                                           .First(x => x.BudgetCategoryId == request.TargetBudgetCategoryId);
                var sourceBudgetCategory = sourceBudgetCategoryId != null
                                        ? _writeDbContext.BudgetCategories
                                           .First(x => x.BudgetCategoryId == request.SourceBudgetCategoryId)
                                        : null;

                var allocation = Allocation.Create(request.Description,
                                                   targetBudgetCategory,
                                                   sourceBudgetCategory,
                                                   request.Amount,
                                                   request.AllocationDate);

                _writeDbContext.Allocations.Add(allocation);

                await _writeDbContext.SaveChangesAsync(cancellationToken);

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

                return(new Result()
                {
                    Id = allocation.AllocationId
                });
            }