protected override async Task <IResponseContainer> GetResultAsync(UpdateConnectorRequest request)
        {
            IResponseContainer result = new ResponseContainer();
            var connector             = await connectorRepository.GetByChargeStationIdAndLineNoAsync(request.ChargeStationId, request.LineNo);

            if (connector is null)
            {
                result.AddErrorMessage($"Connector with ID={request.ChargeStationId} is not found.");
                return(result);
            }

            var updateResponseContainer = await connector.UpdateMaxCurrentInAmps(request.MaxCurrentInAmps, groupRepository);

            result.JoinWith(updateResponseContainer);

            if (result.IsSuccess)
            {
                var previousValue = connector.MaxCurrentInAmps;
                await connectorRepository.UpdateAsync(connector);

                Log.Info($"Connector with ID={connector.GetNumericId()} is updated with new value {request.MaxCurrentInAmps}, previous value was {previousValue}.");
            }
            else
            {
                Log.Error(result.Messages);
            }

            return(result);
        }
Esempio n. 2
0
        public async Task <IResponseContainerWithValue <ConnectorFactoryResult> > CreateAsync(int chargeStationId, int lineNo, decimal maxCurrentInAmps)
        {
            var result            = new ResponseContainerWithValue <ConnectorFactoryResult>();
            var existingConnector = await connectorRepository.GetByChargeStationIdAndLineNoAsync(chargeStationId, lineNo);

            if (existingConnector is not null)
            {
                result.AddErrorMessage($"There is already a connector existing with charge station ID={chargeStationId} and line #{lineNo}.");
                return(result);
            }

            var strategyResponseContainer = await connectorAllocationStrategy.AllocateAsync(chargeStationId, maxCurrentInAmps);

            if (!strategyResponseContainer.IsSuccess)
            {
                return(result.JoinWith(strategyResponseContainer));
            }

            Connector connector = null;

            if (!strategyResponseContainer.Value.Any())
            {
                connector = new Connector
                {
                    ChargeStationId  = chargeStationId,
                    LineNo           = lineNo,
                    MaxCurrentInAmps = maxCurrentInAmps
                };

                result.AddMessage($"Suggestions are not made. Creating a connector. [{connector}]");
                connector = await connectorRepository.CreateAsync(connector);

                result.AddMessage($"Connector created. [{connector}]");
            }

            result = new ResponseContainerWithValue <ConnectorFactoryResult>
            {
                Value = new ConnectorFactoryResult(strategyResponseContainer.Value)
                {
                    Connector = connector
                }
            };

            return(result);
        }
        protected override async Task <IResponseContainer> GetResultAsync(DeleteConnectorRequest request)
        {
            var result    = new ResponseContainer();
            var connector = await connectorRepository.GetByChargeStationIdAndLineNoAsync(request.ChargeStationId, request.LineNo);

            if (connector is not null)
            {
                await connectorRepository.DeleteAsync(connector.Id);

                Log.Info($"Connector {connector} has been deleted.");
            }
            else
            {
                var message = $"Connector with charge station ID={request.ChargeStationId} and line #{request.LineNo} is not found.";
                result.AddErrorMessage(message);
                Log.Error(message);
            }

            return(result);
        }