Exemplo n.º 1
0
 public WareHouse UpdateWareHouse(WareHouse wareHouse)
 {
     using (SqlCommand command = new SqlCommand())
     {
         using (SqlConnection connection = new SqlConnection())
         {
             connection.ConnectionString = ConnectionString;
             command.Connection          = connection;
             command.CommandText         = "spUpsertWareHouse";
             command.CommandType         = CommandType.StoredProcedure;
             foreach (PropertyInfo prop in (from x in wareHouse.GetType().GetProperties() where !excludedPropertiesInUpdate.Contains(x.Name) select x).ToArray())
             {
                 command.Parameters.AddWithValue("@" + prop.Name, prop.GetValue(wareHouse));
             }
             connection.Open();
             object wareHouseId = command.ExecuteScalar();
             wareHouse.Id = int.Parse(wareHouseId.ToString());
             connection.Close();
         }
         return(wareHouse);
     }
 }