protected override async Task <IResponseContainerWithValue <ChargeStationDto> > GetResultAsync(CreateChargeStationRequest request) { if (request is null) { throw new ArgumentNullException(nameof(request)); } var result = new ResponseContainerWithValue <ChargeStationDto>(); var group = await groupRepository.GetAsync(request.GroupId); if (group is null) { result.AddErrorMessage($"Group with ID={request.GroupId} is not found."); Log.Error(result.Messages); return(result); } var chargeStationResponseContainer = ChargeStation.Create(group, request.Name); if (!chargeStationResponseContainer.IsSuccess) { result.JoinWith(chargeStationResponseContainer); Log.Error(result.Messages); return(result); } var chargeStation = await chargeStationRepository.CreateAsync(chargeStationResponseContainer.Value); result = new ResponseContainerWithValue <ChargeStationDto> { Value = ChargeStationDto.From(chargeStation) }; return(result); }
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 <IResponseContainerWithValue <GroupDto> > GetResultAsync(CreateGroupRequest request) { var result = new ResponseContainerWithValue <GroupDto>(); var groupResponseContainer = Group.Create(request.Name, request.CapacityInAmps); if (!groupResponseContainer.IsSuccess) { result.JoinWith(groupResponseContainer); Log.Error(result.Messages); } else { var group = await groupRepository.CreateAsync(groupResponseContainer.Value); result = new ResponseContainerWithValue <GroupDto> { Value = GroupDto.From(group) }; Log.Info($"Group {group.Name} with ID={group.Id} is created."); } return(result); }