public void ValidateCreate(ChargeStation chargeStation, ICollection <Connector> connectors) { if (chargeStation.GroupId <= 0) { throw new UnexpectedValueException(nameof(chargeStation.GroupId)); } _CommonValidator.ValidateChargeStationConnectorsCount(connectors.Count); //Get group var group = _UnitOfWork.GroupRepository.GetById(chargeStation.GroupId); if (group == null) { throw new DependentNotFoundException(nameof(ChargeStation.GroupId), chargeStation.GroupId); } //Get sum of MaxCurrent of given connectors var connectorsMaxCurrentSum = connectors.Sum(c => c.MaxCurrent); //Get sum of MaxCurrentSum of all connectors of current group var groupConnectorsMaxCurrentSum = (from c in _UnitOfWork.ConnectorRepository.Queryable join cs in _UnitOfWork.ChargeStationRepository.Queryable.Where(e => e.GroupId == chargeStation.GroupId) on c.ChargeStationId equals cs.Id select c.MaxCurrent).Sum(); _CommonValidator.ValidateCapacityExceedance(group.Capacity, groupConnectorsMaxCurrentSum + connectorsMaxCurrentSum); }
public void ValidateCreate(Connector connector) { ValidateMaxCurrent(connector); //Check ChargeStation exists var chargeStation = _UnitOfWork.ChargeStationRepository.GetById(connector.ChargeStationId); if (chargeStation == null) { throw new DependentNotFoundException(nameof(connector.ChargeStationId), connector.ChargeStationId); } //Check maximum number of allowed connectors per ChargeStation var chargeStationConnectorsCount = _UnitOfWork.ConnectorRepository.Queryable .Where(c => c.ChargeStationId == chargeStation.Id).Count(); _CommonValidator.ValidateChargeStationConnectorsCount(chargeStationConnectorsCount + 1); //Prevent from exeeding Group Capacity var group = _UnitOfWork.GroupRepository.GetById(chargeStation.GroupId); ValidateGroupCapacityExceedance(connector, group, false); }