Esempio n. 1
0
        /// <inheritdoc />
        public async Task SavePayment(PaymentViewModel paymentViewModel)
        {
            Payment payment = await CreatePaymentFromViewModel(paymentViewModel);

            await context.AddAsync(payment);

            int count = await context.SaveChangesAsync();

            logger.Info("{count} entities saved.", count);
        }
Esempio n. 2
0
            /// <inheritdoc />
            public async Task <Unit> Handle(CreatePaymentCommand request, CancellationToken cancellationToken)
            {
                await context.Payments.AddAsync(request.PaymentToSave, cancellationToken);

                await context.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
            }
            public async Task <Unit> Handle(DeletePaymentByIdCommand request, CancellationToken cancellationToken)
            {
                var entityToDelete = await context.Payments.FindAsync(request.PaymentId);

                context.Payments.Remove(entityToDelete);
                await context.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
            }
            public async Task <Unit> Handle(DeleteCategoryByIdCommand request, CancellationToken cancellationToken)
            {
                Category entityToDelete = await context.Categories.FindAsync(request.CategoryId);

                context.Categories.Remove(entityToDelete);
                await context.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
            }
Esempio n. 5
0
            public async Task <Unit> Handle(UpdateCategoryCommand request, CancellationToken cancellationToken)
            {
                var existingCategory = await context.Categories.FindAsync(request.Category.Id);

                existingCategory.UpdateData(request.Category.Name,
                                            request.Category.Note);

                await context.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
            }
Esempio n. 6
0
            public async Task <Unit> Handle(UpdateAccountCommand request, CancellationToken cancellationToken)
            {
                Account existingAccount = await context.Accounts.FindAsync(request.Account.Id);

                existingAccount.UpdateAccount(request.Account.Name,
                                              request.Account.CurrentBalance,
                                              request.Account.Note,
                                              request.Account.IsExcluded);

                await context.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
            }
Esempio n. 7
0
            /// <inheritdoc />
            public async Task <Unit> Handle(CreatePaymentCommand request, CancellationToken cancellationToken)
            {
                context.Entry(request.PaymentToSave).State = EntityState.Added;

                if (request.PaymentToSave.IsRecurring)
                {
                    context.Entry(request.PaymentToSave.RecurringPayment).State = EntityState.Added;
                }

                await context.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
            }
Esempio n. 8
0
            public async Task <Unit> Handle(UpdatePaymentCommand request, CancellationToken cancellationToken)
            {
                Payment existingPayment = await context.Payments.FindAsync(request.Payment.Id);

                if (existingPayment != null)
                {
                    context.Entry(existingPayment).CurrentValues.SetValues(request.Payment);
                }

                await context.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
            }
            public async Task <Unit> Handle(UpdatePaymentCommand request, CancellationToken cancellationToken)
            {
                Payment existingPayment = await context.Payments.FindAsync(request.Payment.Id);

                existingPayment.UpdatePayment(request.Payment.Date,
                                              request.Payment.Amount,
                                              request.Payment.Type,
                                              request.Payment.ChargedAccount,
                                              request.Payment.TargetAccount,
                                              request.Payment.Category,
                                              request.Payment.Note);

                await context.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
            }
Esempio n. 10
0
        /// <inheritdoc />
        public async Task UpdatePayment(PaymentViewModel newPaymentViewModel)
        {
            await UpdatePaymentFromViewModel(newPaymentViewModel);

            await context.SaveChangesAsync();
        }