Beispiel #1
0
        public async Task <int> CreateAsync(CreateRecordModel createRecordModel, string userId)
        {
            var account = await _accountRepository.GetByIdAsync(createRecordModel.AccountId);

            if (account == null)
            {
                throw new BudgetValidationException(
                          string.Format(ValidationMessages.Common.EntityDoesNotExist, nameof(account), createRecordModel.AccountId));
            }

            if (account.UserId != userId)
            {
                throw new BudgetValidationException(
                          string.Format(ValidationMessages.Accounts.InvalidAccount, account.Name));
            }

            var record = new Record()
            {
                AccountId     = account.Id,
                Amount        = createRecordModel.Amount,
                DateAdded     = _dateTimeProvider.Now,
                Note          = createRecordModel.Note,
                CategoryId    = createRecordModel.CategoryId,
                PaymentTypeId = createRecordModel.PaymentTypeId,
                RecordType    = createRecordModel.RecordType,
            };

            var createdRecord = await _recordRepository.CreateAsync(record);

            return(createdRecord.Id);
        }