//in this method we are calculating the total rack space used and then subtracting it by total rack units/space //this was we can find out the Space availabe in a specific Rack. :) public int add() { asatContext context = new asatContext(); //here we are checking how much space is used by servers assiged to a specific rack. //The problem with Sum() method in SQL is that it returns a null exception if the return value is 0. so //this can be treated via the following way i.e. by adding ?? to the query. int usedunits = (context.Servers.Where(e=>e.RackID==this.RackID).Sum(ii=>(int?)ii.HardWareModel.RackUnits)?? 0 ); int availableunits = TotalUnits - usedunits; return availableunits; }
public asatRepository() { this.context = new asatContext(); }
public int units() { using (var context = new asatContext()) { var e = context.HardWareModels.SingleOrDefault(i => i.HardWareModelID == this.HardWareModelID).RackUnits; return e; } }
public int portsused() { using (var context = new asatContext()) { var e = context.Ports.Where(i => i.NetworkSwitchID == this.NetworkSwitchID).Count(); var s = TotalPorts - e; return s; } }