Beispiel #1
0
        /// <summary>
        /// Udførelse af kommandoen.
        /// </summary>
        /// <param name="command">Command til opdatering af et givent postnummer.</param>
        /// <returns>Opdateret postnummer.</returns>
        public PostnummerView Execute(PostnummerModifyCommand command)
        {
            if (command == null)
            {
                throw new ArgumentNullException("command");
            }

            Postnummer postnummer;

            try
            {
                postnummer = _adresseRepository.PostnummerGetAll()
                             .Single(m =>
                                     m.Landekode.CompareTo(command.Landekode) == 0 &&
                                     m.Postnr.CompareTo(command.Postnummer) == 0);
            }
            catch (InvalidOperationException ex)
            {
                throw new DataAccessSystemException(
                          Resource.GetExceptionMessage(ExceptionMessage.CantFindUniqueRecordId, typeof(Postnummer),
                                                       string.Format("{0}-{1}", command.Landekode, command.Postnummer)), ex);
            }
            postnummer.SætBy(command.Bynavn);

            var opdateretPostnummer = _adresseRepository.PostnummerModify(postnummer.Landekode, postnummer.Postnr,
                                                                          postnummer.By);

            return(_objectMapper.Map <Postnummer, PostnummerView>(opdateretPostnummer));
        }