Beispiel #1
0
        public Person CreatePerson(Person person, out TransactionalInformation transaction)
        {
            transaction = new TransactionalInformation();

            try
            {
                var personBusinessRules = new PersonBusinessRules();
                var results             = personBusinessRules.Validate(person);

                bool validationSucceeded = results.IsValid;
                var  failures            = results.Errors;

                if (validationSucceeded == false)
                {
                    transaction = ValidationErrors.PopulateValidationErrors(failures);
                    return(person);
                }

                _personDataService.CreateSession();
                _personDataService.BeginTransaction();
                _personDataService.CreatePerson(person);
                _personDataService.CommitTransaction(true);

                transaction.ReturnStatus = true;
                transaction.ReturnMessage.Add("Person successfully created.");
            }
            catch (Exception ex)
            {
                string errorMessage = ex.Message;
                transaction.ReturnMessage.Add(errorMessage);
                transaction.ReturnStatus = false;
            }
            finally
            {
                _personDataService.CloseSession();
            }

            return(person);
        }