Example #1
0
        private async Task <Guid> Create(SaveExpenseAggregateParameters parameters)
        {
            var aggregate = ExpensesAggregate.Create(parameters.UserId, parameters.Name, parameters.AddedDate, parameters.IsDraft);
            await _context.ExpensesAggregates.AddAsync(aggregate);

            await _context.SaveChangesAsync();

            return(aggregate.Id);
        }
Example #2
0
        public async Task <ResultOrError <Guid> > Handle(SaveExpenseAggregateParameters parameters)
        {
            if (parameters.Id.HasValue)
            {
                return(await Update(parameters));
            }

            var result = await Create(parameters);

            return(result);
        }
Example #3
0
        private async Task <ResultOrError <Guid> > Update(SaveExpenseAggregateParameters parameters)
        {
            var aggregate = await _context.ExpensesAggregates.SingleOrDefaultAsync(x => x.Id == parameters.Id.Value);

            if (aggregate == null)
            {
                return(CommonErrors.ExpenseAggregateNotFound);
            }

            aggregate.Update(
                name: parameters.Name,
                addedDate: parameters.AddedDate,
                isDraft: parameters.IsDraft);
            await _context.SaveChangesAsync();

            return(aggregate.Id);
        }