Exemplo n.º 1
0
        internal override HandleResponse HandleIt(UpdateGroupCommand request, CancellationToken cancellationToken)
        {
            var group = request.Group;

            var existingGroup = _groupRepository.GetGroupById(group.Id);

            if (existingGroup.Id == 0)
            {
                throw new RestException("Group not found");
            }

            var chargeStationList = _chargeStationRepository.GetChargeStationListByGroupId(group.Id);
            var connectionList    = _connectorRepository.GetConnectorsByChargeStationIds(chargeStationList);

            var currentConsumption = connectionList.Sum(c => c.MaxCurrent);

            if (group.CurrentCapacity < currentConsumption)
            {
                throw new RestException("New capacity can't sustain the existing connectors");
            }

            _groupRepository.UpdateGroup(group);

            return(new HandleResponse()
            {
                Content = group
            });
        }
        private void RunValidations(Connector connector, bool isUpdate = false)
        {
            ValidateFields(connector);

            var chargeStation     = _chargeStationRepository.GetChargeStationById(connector.ChargeStationId);
            var chargeStationList = _chargeStationRepository.GetChargeStationListByGroupId(chargeStation.GroupId);
            var connectionList    = _connectorRepository.GetConnectorsByChargeStationIds(chargeStationList);
            var group             = _groupRepository.GetGroupById(chargeStation.GroupId);

            if (!isUpdate)
            {
                ValidateChargeStationQuantity(connectionList, connector);
            }

            ValidateGroupCapacity(group, connectionList, connector);
        }