public async Task <ActionResult <SpendingViewModel> > Post([FromBody] CreateSpendingViewModel createViewModel) { Domain.Entity.Currency currency = _currencyRepository.Get(createViewModel.CurrencyId); if (currency == null) { return(NotFound("Currency not found")); } Domain.Entity.Spender spender = _spenderRepository.Get(createViewModel.SpenderId); if (spender == null) { return(NotFound("Spender not found")); } Domain.Entity.Spending spendingToCreate = Domain.Entity.Spending.BuildSpending( amount: createViewModel.Amount, comment: createViewModel.Comment, currency: currency, spender: spender, date: createViewModel.Date?.Date, nature: createViewModel.Nature); _spendingService.ValidateNewSpending(spendingToCreate); Domain.Entity.Spending insertedSpending = await _spendingRepository.Insert(spendingToCreate); return(CreatedAtAction(nameof(Get), new { insertedSpending.Id }, insertedSpending.ToViewModel())); }
public static Data.Currency ToDb(this Domain.Entity.Currency currency) { return(new Data.Currency { Name = currency.Name, }); }