/// <summary> /// Udførelse af kommandoen. /// </summary> /// <param name="command">Command til tilføjelse af en budgetkonto.</param> /// <returns>Oprettet budgetkonto.</returns> public BudgetkontoView Execute(BudgetkontoAddCommand command) { if (command == null) { throw new ArgumentNullException("command"); } Regnskab regnskab; try { var getBrevhoved = new Func <int, Brevhoved>(nummer => _fællesRepository.BrevhovedGetByNummer(nummer)); regnskab = _finansstyringRepository.RegnskabGetAll(getBrevhoved) .Single(m => m.Nummer == command.Regnskabsnummer); } catch (InvalidOperationException ex) { throw new DataAccessSystemException( Resource.GetExceptionMessage(ExceptionMessage.CantFindUniqueRecordId, typeof(Regnskab), command.Regnskabsnummer), ex); } Budgetkontogruppe budgetkontogruppe; try { budgetkontogruppe = _finansstyringRepository.BudgetkontogrupperGetAll() .Single(m => m.Nummer == command.Budgetkontogruppe); } catch (InvalidOperationException ex) { throw new DataAccessSystemException( Resource.GetExceptionMessage(ExceptionMessage.CantFindUniqueRecordId, typeof(Budgetkontogruppe), command.Budgetkontogruppe), ex); } var budgetkonto = _finansstyringRepository.BudgetkontoAdd(regnskab, command.Kontonummer, command.Kontonavn, command.Beskrivelse, command.Note, budgetkontogruppe); return(_objectMapper.Map <Budgetkonto, BudgetkontoView>(budgetkonto)); }