Beispiel #1
0
        public async Task <bool> Execute(UpdateChargeStationInputModel chargeStationInput, string groupId)
        {
            var group = await _groupRepository.GetGroupById(groupId);

            if (group == null)
            {
                HandlerMessage = "Can't add this station because the IdGroup doenst exist";
                return(false);
            }

            var hasChargeStation = _groupRepository.GetChargeStationById(chargeStationInput.Id);

            if (hasChargeStation != null)
            {
                HandlerMessage = "The charge station already exist.";
                return(false);
            }

            var chargeStation = new ChargeStation(chargeStationInput.Name);

            AddConnectors(chargeStationInput, chargeStation);

            group.ChargeStations.Add(chargeStation);

            await _groupRepository.Update(group.Id, group);

            HandlerMessage = "the Connector has created";
            return(true);
        }
Beispiel #2
0
        private static void AddConnectors(UpdateChargeStationInputModel chargeStationInput, ChargeStation chargeStation)
        {
            if (chargeStationInput.Connectors != null)
            {
                var newConnects = new List <Connector>(chargeStationInput.Connectors.Count);

                newConnects.AddRange(from connect in chargeStationInput.Connectors
                                     select new Connector(chargeStation.Id, connect.MaxCurrentAmps));
            }
        }
Beispiel #3
0
        public async Task <IActionResult> ConnectChargeStationToGroupStation(UpdateChargeStationInputModel chargeStationInput, string groupId)
        {
            var commandHandler = new ConnectChargeStationToGroupStationCommandHandler(_groupRepository);

            var result = await commandHandler.Execute(chargeStationInput, groupId);

            if (result)
            {
                return(Ok(commandHandler.HandlerMessage));
            }

            return(NoContent());
        }