public static Person GetByPersonId(Guid personId)
        {
            Person person = new Person();

            using (ObjectConnection objectConnection = new ObjectConnection())
            {
                using (GetPersonByPersonIdCommand objectCommand = new GetPersonByPersonIdCommand(objectConnection))
                {
                    objectCommand.PersonId = personId;

                    objectConnection.Open();
                    using (SqlDataReader sqlDataReader = objectCommand.ExecuteReader())
                    {
                        if (!sqlDataReader.HasRows)
                        {
                            return person;
                        }

                        using (PersonSqlDataReader objectSqlDataReader = new PersonSqlDataReader(sqlDataReader))
                        {
                            while (objectSqlDataReader.Read())
                            {
                                person = objectSqlDataReader.Person;
                            }
                        }
                    }
                }
            }

            return person;
        }
        public static Entities.Person ToEntity(BusinessObject.Person businessObject)
        {
            if (businessObject == null)
                return null;

            Entities.Person entity = new Entities.Person
            {
                PersonEmail = businessObject.EmailAddress,
                PersonFirstName = businessObject.FirstName,
                PersonLastName = businessObject.LastName,
                PersonId = businessObject.PersonId,
                PersonPhone = businessObject.PhoneNumber,
                PersonTypeId = (int)businessObject.PersonType
            };

            return entity;
        }
Ejemplo n.º 3
0
        public static Entities.Person ToEntity(BusinessObject.Person businessObject)
        {
            if (businessObject == null)
            {
                return(null);
            }

            Entities.Person entity = new Entities.Person
            {
                PersonEmail     = businessObject.EmailAddress,
                PersonFirstName = businessObject.FirstName,
                PersonLastName  = businessObject.LastName,
                PersonId        = businessObject.PersonId,
                PersonPhone     = businessObject.PhoneNumber,
                PersonTypeId    = (int)businessObject.PersonType
            };

            return(entity);
        }
Ejemplo n.º 4
0
        public static BusinessObject.Person ToBusinessObject(Entities.Person entity)
        {
            if (entity == null)
            {
                return(null);
            }

            Enumeration.PersonType personType = (Enumeration.PersonType)entity.PersonTypeId;

            BusinessObject.Person businessObject = new BusinessObject.Person
            {
                EmailAddress = entity.PersonEmail,
                FirstName    = entity.PersonFirstName,
                LastName     = entity.PersonLastName,
                PersonId     = entity.PersonId,
                PhoneNumber  = entity.PersonPhone,
                PersonType   = personType
            };

            return(businessObject);
        }
        public static int UpdateByPersonId(Person person)
        {
            using (ObjectConnection objectConnection = new ObjectConnection())
            {
                using (UpdatePersonByPersonIdCommand objectCommand = new UpdatePersonByPersonIdCommand(objectConnection))
                {
                    objectCommand.PersonId = person.PersonId;
                    objectCommand.PersonFirstName = person.PersonFirstName;
                    objectCommand.PersonLastName = person.PersonLastName;
                    objectCommand.PersonPhone = person.PersonPhone;
                    objectCommand.PersonEmail = person.PersonEmail;
                    objectCommand.PersonTypeId = person.PersonTypeId;

                    objectConnection.Open();
                    objectCommand.ExecuteNonQuery();

                    return objectCommand.ReturnValue;
                }
            }
        }
        public static int Insert(Person person)
        {
            using (ObjectConnection objectConnection = new ObjectConnection())
            {
                using (InsertPersonCommand objectCommand = new InsertPersonCommand(objectConnection))
                {
                    objectCommand.PersonId = (person.PersonId != Guid.Empty) ? person.PersonId : new Guid();
                    objectCommand.PersonFirstName = person.PersonFirstName;
                    objectCommand.PersonLastName = person.PersonLastName;
                    objectCommand.PersonPhone = person.PersonPhone;
                    objectCommand.PersonEmail = person.PersonEmail;
                    objectCommand.PersonTypeId = person.PersonTypeId;

                    objectConnection.Open();
                    objectCommand.ExecuteNonQuery();

                    return objectCommand.ReturnValue;
                }
            }
        }