Пример #1
0
        private async Task UpdatingIncomes(CancellationToken cancellationToken, decimal newExpense,
                                           TypeExpense typeExpense)
        {
            var totalSalary = await _context.Transactions.AsNoTracking()
                              .Include(c => c.Category)
                              .Where(t => t.Category.CategoryId == 1)
                              .GroupBy(t => t.TransactionId)
                              .Select(t => new SalaryDto()
            {
                Id    = t.Key,
                Value = t.Sum(s => s.Value)
            }).FirstOrDefaultAsync(cancellationToken);

            var entity = await _context.Transactions.FirstOrDefaultAsync(t => t.TransactionId == totalSalary.Id, cancellationToken);

            switch (typeExpense)
            {
            case TypeExpense.Expense:
                entity.Value = totalSalary.Value - newExpense;
                break;

            case TypeExpense.Income:
                entity.Value = totalSalary.Value + newExpense;
                break;
            }

            await _context.SaveChangesAsync(cancellationToken);
        }
        public async Task <bool> Handle(AddCategoryCommand request, CancellationToken cancellationToken)
        {
            var entity = new Category()
            {
                Description = request.Description,
                ImageName   = request.ImageFile.FileName,
                Image       = getBytesFromImage(request.ImageFile)
            };

            _context.Categories.Add(entity);

            await _context.SaveChangesAsync(cancellationToken);

            await uploadImage(request.ImageFile, entity.CategoryId);

            return(true);
        }