Beispiel #1
0
        public int AddAgency(Entity.Agency agency)
        {
            int agencyID = 0;

            using (SqlCommand command = new SqlCommand("dbo.uspSaveAgency"))
            {
                command.CommandType = System.Data.CommandType.StoredProcedure;

                PropertyInfo[] propertyInfo = agency.GetType().
                                              GetProperties().
                                              Where(property => property.Name != "bIsActive" &&
                                                    property.Name != "dtInserted" &&
                                                    property.Name != "dtUpdated").
                                              ToArray();

                propertyInfo.ToList().
                ForEach(property => command.Parameters.
                        Add(new SqlParameter(String.Format("@{0}", property.Name),
                                             (property.GetValue(agency) ?? DBNull.Value))));

                command.Parameters["@iAgencyID"].Direction = System.Data.ParameterDirection.Output;

                agencyID = new EMSRepository <Agency>().Add(command);
            }

            return(agencyID);
        }
Beispiel #2
0
        void TestGet <T>() where T : class
        {
            EMSRepository <T> repository = new EMSRepository <T>();
            string            SQL        = String.Format("EXEC dbo.uspGet{0}List", typeof(T).Name);

            IList <T> list = repository.GetList(SQL);

            foreach (var item in list)
            {
                IList <PropertyInfo> propertyInfo = new List <PropertyInfo>(item.GetType().GetProperties());

                foreach (PropertyInfo property in propertyInfo)
                {
                    var propertyValue = property.GetValue(item);

                    Console.Write(property.Name + ": ");
                    Console.WriteLine((propertyValue != null) ? propertyValue.ToString() : string.Empty);
                }

                Console.WriteLine("|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||");
            }
        }