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();
            }


        }
        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;


        }
        public HttpResponseMessage UpdatePerson(HttpRequestMessage request, [FromBody] PersonViewModel personViewModel)
        {
            TransactionalInformation transaction;

            var person = new Person
            {
                PersonID = personViewModel.PersonID,
                CompanyName = personViewModel.CompanyName,
                Name = personViewModel.Name,
                Country = personViewModel.Country,
                City = personViewModel.City,
                Address = personViewModel.Address,
                MobileNumber = personViewModel.MobileNumber
            };

            if (personViewModel.ImageUrl != null)
            {
                person.Image = Convert.FromBase64String(personViewModel.ImageUrl.Replace("data:image/jpeg;base64,", ""));
            }

            var personBusinessService = new PersonBusinessService(_personDataService);
            personBusinessService.UpdatePerson(person, out transaction);
            if (transaction.ReturnStatus == false)
            {
                personViewModel.ReturnStatus = false;
                personViewModel.ReturnMessage = transaction.ReturnMessage;
                personViewModel.ValidationErrors = transaction.ValidationErrors;

                var responseError = Request.CreateResponse(HttpStatusCode.BadRequest, personViewModel);
                return responseError;

            }

            personViewModel.ReturnStatus = true;
            personViewModel.ReturnMessage = transaction.ReturnMessage;

            var response = Request.CreateResponse(HttpStatusCode.OK, personViewModel);
            return response;

        }
        public void UpdatePerson(Person person)
        {

        }
 public void DeletePerson(Person person)
 {
     dbConnection.Persons.Remove(person);
 }
 public void ActivatePerson(Person person, bool isActive)
 {
     person.IsActive = isActive;
 }
 public void CreatePerson(Person person)
 {
     dbConnection.Persons.Add(person);
 }
        public Person GetPerson(int personID, out TransactionalInformation transaction)
        {
            transaction = new TransactionalInformation();

            var person = new Person();

            try
            {

                _personDataService.CreateSession();
                person = _personDataService.GetPerson(personID);
                _personDataService.CloseSession();      
                transaction.ReturnStatus = true;

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

            return person;

        }