Permalink
Browse files

added null checks for aggregate stats

  • Loading branch information...
half-ogre committed Jun 25, 2012
1 parent fa70cef commit 513f257e6818391345edd2a7301ce6a018d585d0
Showing with 6 additions and 4 deletions.
  1. +6 −4 Website/Services/AggregateStatsService.cs
@@ -24,12 +24,14 @@ public AggregateStats GetAggregateStats()
database.Connection.Open();
using (var reader = command.ExecuteReader(CommandBehavior.CloseConnection | CommandBehavior.SingleRow))
{
- reader.Read();
+ bool hasData = reader.Read();
+ if (!hasData)
+ return new AggregateStats();
return new AggregateStats
{
- UniquePackages = reader.GetInt32(0),
- TotalPackages = reader.GetInt32(1),
- Downloads = reader.GetInt32(2),
+ UniquePackages = reader.IsDBNull(0) ? 0 : reader.GetInt32(0),
+ TotalPackages = reader.IsDBNull(1) ? 0 : reader.GetInt32(1),
+ Downloads = reader.IsDBNull(2) ? 0 : reader.GetInt32(2),
};
}
}

0 comments on commit 513f257

Please sign in to comment.