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);
        }
Ejemplo n.º 2
0
        private void ValidateGroupCapacityExceedance(Connector connector, Group group, bool excludeGivenConnector)
        {
            //Get connectors of current group
            float connectorsSum = 0;

            if (!excludeGivenConnector)
            {
                connectorsSum =
                    (from c in _UnitOfWork.ConnectorRepository.Queryable
                     join cs in _UnitOfWork.ChargeStationRepository.Queryable.Where(e => e.GroupId == @group.Id)
                     on c.ChargeStationId equals cs.Id
                     select c).Sum(c => c.MaxCurrent);
            }
            else
            {
                connectorsSum =
                    (from c in _UnitOfWork.ConnectorRepository.Queryable
                     where c.ChargeStationId == @connector.ChargeStationId & c.CK_Id != @connector.CK_Id
                     join cs in _UnitOfWork.ChargeStationRepository.Queryable.Where(e => e.GroupId == @group.Id)
                     on c.ChargeStationId equals cs.Id
                     select c).Sum(c => c.MaxCurrent);
            }

            //Validate
            _CommonValidator.ValidateCapacityExceedance(group.Capacity, connectorsSum, connector.MaxCurrent);
        }
Ejemplo n.º 3
0
        public void ValidateUpdate(Group group)
        {
            ValidateCapacity(group);

            //Get sum of MaxCurrentSum of all connectors of current group
            var maxCurrentSum =
                (from c in _UnitOfWork.ConnectorRepository.Queryable
                 join cs in _UnitOfWork.ChargeStationRepository.Queryable.Where(e => e.GroupId == @group.Id)
                 on c.ChargeStationId equals cs.Id
                 select c.MaxCurrent).Sum();

            //Make sure that the user did not changed the Capacity to a value less than the sum of existing connectors
            _CommonValidator.ValidateCapacityExceedance(group.Capacity, maxCurrentSum);
        }