Exemplo n.º 1
0
            /// <summary>
            /// Updates record in DB with spesified value
            /// </summary>
            /// <param name="p">Address to be updated</param>
            protected void UpdateAddress(Mock.PhoneBook.Address p)
            {
                if (p != null)
                {
                    m_sqlconnection.Open();
                    Dictionary<string, object> dic = new BLL.AddressConvertor().ToDictionary(p);
                    SqlCommand command = new SqlCommand(UPDATE_ADDRESS, m_sqlconnection);

                    dic.Where(m => m.Key != "address_id").ToList().ForEach(o => command.Parameters.AddWithValue("@" + o.Key, o.Value));

                    if (command.ExecuteNonQuery() == 0)
                        throw new ArgumentException();
                    m_sqlconnection.Close();
                }
                else
                    throw new ArgumentNullException("Object to insert is null");
            }
Exemplo n.º 2
0
            /// <summary>
            /// Gets all Persons form DB with JOIN
            /// </summary>
            /// <returns>List of Person</returns>
            public List<Model.Person> GetPersonsJoin()
            {
                List<Model.Person> res = new List<Model.Person>();

                m_connection.Open();
                Infrastructure.PhoneBook.IMockConvertor convertor = new BLL.PersonConvertor();

                using (EntityCommand cmd = new EntityCommand(SELECT_PERSONS_ALL, m_connection))
                {
                    using (DbDataReader reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess))
                    {
                        while (reader.Read())
                        {
                            Dictionary<string, object> dic = Enumerable.Range(0, reader.FieldCount).ToDictionary(reader.GetName, reader.GetValue);
                            Mock.PhoneBook.Person person = new BLL.PersonConvertor().ToObject(dic) as Mock.PhoneBook.Person;
                            if (person.ID == 0)
                                person = Mock.PhoneBook.Person.Null;

                            Mock.PhoneBook.Phone phone = new BLL.PhoneConvertor().ToObject(dic) as Mock.PhoneBook.Phone;
                            if (phone.ID == 0)
                                person = Mock.PhoneBook.Person.Null;

                            Mock.PhoneBook.Address address = new BLL.AddressConvertor().ToObject(dic) as Mock.PhoneBook.Address;
                            if (address.ID == 0)
                                person = Mock.PhoneBook.Person.Null;

                            res.Add(new Model.Person(person, phone, address));
                        }
                    }
                }
                m_connection.Close();

                return res;
            }
Exemplo n.º 3
0
            /// <summary>
            /// Sectes all Addresses from person table into List
            /// </summary>
            /// <returns>List of Address mocks</returns>
            protected List<Mock.PhoneBook.Address> GetAddresses()
            {
                List<Mock.PhoneBook.Address> list = new List<Mock.PhoneBook.Address>();

                m_connection.Open();
                Infrastructure.PhoneBook.IMockConvertor convertor = new BLL.AddressConvertor();

                using (EntityCommand cmd = new EntityCommand(SELECT_ADDRESSES_ALL, m_connection))
                {
                    using (DbDataReader reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess))
                    {
                        while (reader.Read())
                        {
                            list.Add(convertor.ToObject(Enumerable.Range(0, reader.FieldCount).ToDictionary(reader.GetName, reader.GetValue)) as Mock.PhoneBook.Address);
                        }
                    }
                }
                m_connection.Close();
                return list;
            }