Beispiel #1
0
        public ListOfPersons GetListOfPersonWithDescription(ISqlFactory iSqlFactory)
        {
            ListOfPersons lPerson = new ListOfPersons();

            try
            {
                IPersonDB person   = new PersonDb();
                var       ageGroup = GetListOfAgeGroup(iSqlFactory);

                lPerson = person.GetDataFromPersonTable(iSqlFactory);

                foreach (var item in lPerson.lPersonModel)
                {
                    item.Description = ageGroup.ListOfAgeGroup.Where(x => x.MinAge <= item.Age && x.MaxAge > item.Age).Select(z => z.Description).SingleOrDefault();
                }
            }
            catch (DbException ex)
            {
                lPerson.Message.Add(new Response
                {
                    MessageCode    = "Error",
                    MessageDetails = ex.Message
                });
            }

            return(lPerson);
        }
Beispiel #2
0
        public ListOfPersons SearchForPerson(PersonModel personModel, ISqlFactory iSqlFactory)
        {
            ListOfPersons lSearchPerson = new ListOfPersons();

            try
            {
                IPersonDB person  = new PersonDb();
                var       lPerson = GetListOfPersonWithDescription(iSqlFactory);
                lSearchPerson.lPersonModel = lPerson.lPersonModel.Where(x => x.FirstName == personModel.FirstName || x.LastName == personModel.LastName)
                                             .Select(z => new PersonModel {
                    Id          = z.Id,
                    FirstName   = z.FirstName,
                    LastName    = z.LastName,
                    Age         = z.Age,
                    Description = z.Description
                }).ToList();
            }
            catch (DbException ex)
            {
                lSearchPerson.Message.Add(new Response
                {
                    MessageCode    = "Error",
                    MessageDetails = ex.Message
                });
            }

            return(lSearchPerson);
        }
Beispiel #3
0
        public ListOfPersons GetListOfPersons()
        {
            ListOfPersons lPersons  = new ListOfPersons();
            PersonBiz     personBiz = new PersonBiz();

            AgeRanger.Data.AgeRangerDataFactory ageRangerDataFactory = new Data.AgeRangerDataFactory();
            ISqlFactory sqlFactory = ageRangerDataFactory.GetReposotory();

            lPersons = personBiz.GetListOfPersonWithDescription(sqlFactory);
            return(lPersons);
        }
Beispiel #4
0
        public ListOfPersons GetListOfPerson(ISqlFactory sqlFactory)
        {
            ListOfPersons lPerson = new ListOfPersons();

            try
            {
                IPersonDB person = new PersonDb();
                lPerson = person.GetDataFromPersonTable(sqlFactory);
            }
            catch (DbException ex)
            {
                lPerson.Message.Add(new Response {
                    MessageCode    = "Error",
                    MessageDetails = ex.Message
                });
            }

            return(lPerson);
        }
Beispiel #5
0
        /// <summary>
        /// Get record from Person table.
        /// </summary>
        /// <param name="selectCommand"></param>
        /// <returns></returns>
        public ListOfPersons GetDataFromPersonTable(ISqlFactory iSqlFactory)
        {
            ListOfPersons lPerson = new ListOfPersons();

            lPerson.lPersonModel = new List <PersonModel>();
            PersonModel person;

            try
            {
                DbCommand    command;
                DbDataReader datareader;
                string       Sqlcommand = "Select * from Person";
                using (DbConnection conn = iSqlFactory.CreateConnection())
                {
                    conn.Open();
                    command    = iSqlFactory.ExecuteCommand(Sqlcommand, conn);
                    datareader = command.ExecuteReader();

                    while (datareader.Read())
                    {
                        person           = new PersonModel();
                        person.Id        = Convert.ToInt32(datareader["Id"]);
                        person.FirstName = datareader["FirstName"].ToString();
                        person.LastName  = datareader["LastName"].ToString();
                        person.Age       = Convert.ToInt32(datareader["Age"]);

                        lPerson.lPersonModel.Add(person);
                    }
                }
            }
            catch (DbException ex)
            {
                lPerson.Message.Add(new Response
                {
                    MessageCode    = "Error",
                    MessageDetails = ex.Message
                });
            }

            return(lPerson);
        }
Beispiel #6
0
        static void Main(string[] args)
        {
            ListOfPersons NewPerson = new ListOfPersons();
            string        Filepath  = @"C:\Users\stenk\samples";
            string        Filename  = @"Frozen.txt";
            string        fullpath  = Path.Combine(Filepath, Filename);


            string[] Personsfromfile = File.ReadAllLines(fullpath);

            foreach (string line in Personsfromfile)
            {
                string[] tempArray  = line.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
                string   personName = tempArray[0];
                string   Itemname   = tempArray[1];


                NewPerson.Addpersonstolist(personName, Itemname);
            }
            NewPerson.PrintPerson();
        }