Beispiel #1
0
 private void DataPortal_Fetch(PKCriteria criteria)
 {
     Database.LogInfo("Territory.DataPortal_Fetch", GetHashCode());
     try
     {
         using (SqlConnection cn = Database.Northwind_SqlConnection)
         {
             ApplicationContext.LocalContext["cn"] = cn;
             using (SqlCommand cm = cn.CreateCommand())
             {
                 cm.CommandType = CommandType.StoredProcedure;
                 cm.CommandText = "getTerritory";
                 cm.Parameters.AddWithValue("@TerritoryID", criteria.TerritoryID);
                 using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
                 {
                     if (!dr.Read())
                     {
                         _ErrorMessage = "No Record Found";
                         return;
                     }
                     ReadData(dr);
                     // load child objects
                     dr.NextResult();
                     _TerritoryEmployeeTerritories = TerritoryEmployeeTerritories.Get(dr);
                 }
             }
             // removing of item only needed for local data portal
             if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client)
             {
                 ApplicationContext.LocalContext.Remove("cn");
             }
         }
     }
     catch (Exception ex)
     {
         Database.LogException("Territory.DataPortal_Fetch", ex);
         _ErrorMessage = ex.Message;
         throw new DbCslaException("Territory.DataPortal_Fetch", ex);
     }
 }
Beispiel #2
0
 private void DataPortal_Delete(PKCriteria criteria)
 {
     Database.LogInfo("Territory.DataPortal_Delete", GetHashCode());
     try
     {
         using (SqlConnection cn = Database.Northwind_SqlConnection)
         {
             using (SqlCommand cm = cn.CreateCommand())
             {
                 cm.CommandType = CommandType.StoredProcedure;
                 cm.CommandText = "deleteTerritory";
                 cm.Parameters.AddWithValue("@TerritoryID", criteria.TerritoryID);
                 cm.ExecuteNonQuery();
             }
         }
     }
     catch (Exception ex)
     {
         Database.LogException("Territory.DataPortal_Delete", ex);
         _ErrorMessage = ex.Message;
         throw new DbCslaException("Territory.DataPortal_Delete", ex);
     }
 }