Beispiel #1
0
        //
        // Get an array of Regist associated with a person id
        //
        public Person[] GetAllPersonByIdRegist(int idRegist)
        {
            using (var connect = new Connect())
            {
                SqlConnection sqlconn      = connect.GetConnection();
                var           personMapper = new PersonDataMapper(sqlconn);
                var           participants = personMapper.GetAllPersonByRegist(idRegist);

                return(participants.ToArray());
            }
        }
Beispiel #2
0
        //
        // Get a Person instance identify by his id
        //
        public Person GetPerson(int id)
        {
            try
            {
                using (var c = new Connect())
                {
                    var personDoa = new PersonDataMapper(c.GetConnection());
                    return(personDoa.GetById(id));
                }
            }

            catch (Exception exception)
            {
                throw new FaultException <ServerError>(new ServerError());
            }
        }
Beispiel #3
0
        //
        // Get an array of all Person in the database
        //
        public Person[] GetAllPerson(params String[] filters)
        {
            try
            {
                using (var connect = new Connect())
                {
                    SqlConnection sqlconn   = connect.GetConnection();
                    var           personDoa = new PersonDataMapper(sqlconn);

                    //  personDoa.GetAll().Where(p => p.Name == filters[0] && p.Birthplace == filters[1]);
                    return(personDoa.GetAll().ToArray());
                }
            }
            catch (Exception exception)
            {
                throw new FaultException <ServerError>(new ServerError());
            }
        }
Beispiel #4
0
 //
 //  Insert a Person
 //
 public int InsertPerson(Person val)
 {
     try
     {
         using (var c = new Connect())
         {
             c.BeginTrx(IsolationLevel.ReadCommitted);
             var personDoa = new PersonDataMapper(c.GetConnection());
             personDoa.SetTransaction(c.Transaction);
             int result = personDoa.Insert(val);
             c.Commit();
             return(result);
         }
     }
     catch (Exception exception)
     {
         throw new FaultException <ServerError>(new ServerError());
     }
 }
Beispiel #5
0
        //
        // Get an array of all Person that match the PersonSearchParams parameters in the database
        //

        // Argumentos 1º name , 2º birthday , 3º nacionalidade
        public PersonSearchResult GetAllPerson(PersonSearchParams personSearchParams)
        {
            try
            {
                string[] filters = personSearchParams.filters;

                using (var connect = new Connect())
                {
                    SqlConnection sqlconn = connect.GetConnection();

                    var personDoa = new PersonDataMapper(sqlconn);

                    PersonSearchResult sr = new PersonSearchResult();

                    sr.result = personDoa.GetAll().Where(p => p.Birthplace == filters[2]).ToArray();
                    return(sr);
                }
            }
            catch (Exception exception)
            {
                throw new FaultException <ServerError>(new ServerError(), "Server Error ");
            }
        }
Beispiel #6
0
 //
 //  Insert a Person
 //
 public int InsertPerson(Person val)
 {
     try
     {
         using (var c = new Connect())
         {
             c.BeginTrx(IsolationLevel.ReadCommitted);
             var personDoa = new PersonDataMapper(c.GetConnection());
             personDoa.SetTransaction(c.Transaction);
             int result = personDoa.Insert(val);
             c.Commit();
             return result;
         }
     }
     catch (Exception exception)
     {
         throw new FaultException<ServerError>(new ServerError());
     }
 }
Beispiel #7
0
        //
        // Get a Person instance identify by his id
        //
        public Person GetPerson(int id)
        {
            try
            {
                using (var c = new Connect())
                {
                    var personDoa = new PersonDataMapper(c.GetConnection());
                    return personDoa.GetById(id);
                }
            }

            catch (Exception exception)
            {
                throw new FaultException<ServerError>(new ServerError());
            }
        }
Beispiel #8
0
        //
        // Get an array of Regist associated with a person id
        //
        public Person[] GetAllPersonByIdRegist(int idRegist)
        {
            using (var connect = new Connect())
            {
                SqlConnection sqlconn = connect.GetConnection();
                var personMapper = new PersonDataMapper(sqlconn);
                var participants = personMapper.GetAllPersonByRegist(idRegist);

                return participants.ToArray();
            }
        }
Beispiel #9
0
        //
        // Get an array of all Person that match the PersonSearchParams parameters in the database
        //
        // Argumentos 1º name , 2º birthday , 3º nacionalidade
        public PersonSearchResult GetAllPerson(PersonSearchParams personSearchParams)
        {
            try
            {
                string[] filters = personSearchParams.filters;

                using (var connect = new Connect())
                {
                    SqlConnection sqlconn = connect.GetConnection();

                    var personDoa = new PersonDataMapper(sqlconn);

                    PersonSearchResult sr = new PersonSearchResult();

                    sr.result = personDoa.GetAll().Where(p => p.Birthplace == filters[2]).ToArray();
                    return sr;
                }
            }
            catch (Exception exception)
            {
                throw new FaultException<ServerError>(new ServerError(), "Server Error ");
            }
        }
Beispiel #10
0
        //
        // Get an array of all Person in the database
        //
        public Person[] GetAllPerson(params String[] filters)
        {
            try
            {
                using (var connect = new Connect())
                {
                    SqlConnection sqlconn = connect.GetConnection();
                    var personDoa = new PersonDataMapper(sqlconn);

                    //  personDoa.GetAll().Where(p => p.Name == filters[0] && p.Birthplace == filters[1]);
                    return personDoa.GetAll().ToArray();
                }
            }
            catch (Exception exception)
            {
                throw new FaultException<ServerError>(new ServerError());
            }
        }
Beispiel #11
0
        static void Main(string[] args)
        {
            try
            {
                PersonDataMapper personDataMapper = new PersonDataMapper(ConfigurationManager.ConnectionStrings["connectionStringSchool"].ConnectionString);

                /*
                 * personDataMapper.Insert(new Person
                 * {
                 *  LastName = "Munguia",
                 *  FirstName = "Isack",
                 *  HireDate = DateTime.Now,
                 *  EnrollmentDate = DateTime.Now,
                 *  Discriminator = "Instructor"
                 * });
                 */

                List <DataMapper.Models.Person> personas = personDataMapper.GetFiltered("AND FirstName = 'Isack'", "LastName", 10, 1).ToList();
                //List<Person> personasConApellidoPerez = personDataMapper.GetFiltered("LastName = 'Perez'", "", int.MaxValue, 1).ToList();

                //personas.ForEach(Console.WriteLine);

                //ISpecification<DataMapper.Models.Person> personasQueSeLlamanIsack = new ExpressionSpecification<DataMapper.Models.Person>(persona => persona.FirstName == "Isack");
                //ISpecification<DataMapper.Models.Person> personasConApellidoSuarez = new ExpressionSpecification<DataMapper.Models.Person>(persona => persona.LastName == "Suarez");
                //ISpecification<DataMapper.Models.Person> personasQueNoSonEstudiantes = new ExpressionSpecification<DataMapper.Models.Person>(persona => persona.Discriminator != "Student");
                //ISpecification<DataMapper.Models.Person> todasLasEspecificaciones = personasQueSeLlamanIsack.Or(personasConApellidoSuarez).Or(personasQueNoSonEstudiantes);

                //personas.FindAll(()=>personasQueSeLlamanIsack.IsSatisfiedBy).ForEach(Console.WriteLine);

                //var dataFiltrada = personas.FindAll(persona => todasLasEspecificaciones.IsSatisfiedBy());

                //personas.FindAll(persona => new PropertyEqualsSpecification<DataMapper.Models.Person>("Discriminator", "Student").IsSatisfiedBy(persona)).ForEach(Console.WriteLine);

                var p1 = new Person {
                    LastName       = "Munguia",
                    FirstName      = "Isack",
                    HireDate       = DateTime.Now,
                    EnrollmentDate = DateTime.Now,
                    Discriminator  = "Instructor"
                };
                var p2 = new Person
                {
                    LastName       = "Herrera",
                    FirstName      = "Gysela",
                    HireDate       = null,
                    EnrollmentDate = DateTime.Now,
                    Discriminator  = "Instructor"
                };

                ISpecification <Person> specification0 = new PersonDiscriminatorSpecification("Instructor");
                ISpecification <Person> specification1 = new PersonFirstNameSpecification("Isack");
                ISpecification <Person> specification2 = new ExpressionSpecification <Person>(p => p.FirstName.FirstOrDefault().Equals('A'));
                ISpecification <Person> specification3 = new ExpressionSpecification <Person>(p => p.LastName.FirstOrDefault().Equals('A'));

                var todasLasEspecificaciones = specification3.Or(specification2);

                List <Person> persons = new List <Person>();
                using (new ContextCreation())
                {
                    var repository = PersonRepository.Instance;
                    //var itemToCreate = repository.Create(pp);
                    //var itemToDelete = repository.Delete(specification1);
                    //var itemToDelete = repository.Delete(p2);
                    //repository.SaveChanges();
                    persons = repository.Filter(todasLasEspecificaciones).ToList();

                    //var updateResult = repository.Update(p2);
                }
                Console.WriteLine($"{nameof(persons)}: {persons.Count}");
                persons.ToList().ForEach(Console.WriteLine);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                Console.ReadKey();
            }
        }