Beispiel #1
0
        public void UpdatePerson(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;
                }

                _personDataService.CreateSession();
                _personDataService.BeginTransaction();

                var existingPerson = _personDataService.GetPerson(person.PersonID);

                existingPerson.CompanyName  = person.CompanyName;
                existingPerson.Name         = person.Name;
                existingPerson.Country      = person.Country;
                existingPerson.City         = person.City;
                existingPerson.Address      = person.Address;
                existingPerson.MobileNumber = person.MobileNumber;
                existingPerson.Image        = person.Image;

                _personDataService.UpdatePerson(person);
                _personDataService.CommitTransaction(true);

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