public async Task <bool> Execute(CreateGroupStationInputModel groupStationInput) { var group = new GroupStation(groupStationInput.Name, groupStationInput.CapacityAmps); Parallel.ForEach(groupStationInput.ChargeStations, chargeStation => { var newChargStation = new ChargeStation(chargeStation.Name); var newConnectorList = CreateConnectors(chargeStation, newChargStation); newChargStation.Connectors.AddRange(newConnectorList); group.AddChargeStation(newChargStation); }); if (group.IsCapacityOfGroup() > group.CapacityAmps) { var numberOfExcessConnector = group.IsCapacityOfGroup() - group.CapacityAmps; HandlerMessage = $"The capactiy of Connector was excessed. You may remove {numberOfExcessConnector} of Connectors"; return(false); } await _groupRepository.Add(group); HandlerMessage = "Group has been added"; return(true); }
public async Task <IActionResult> CreateGroup(CreateGroupStationInputModel group) { var commandHandler = new CreateGroupStationCommandHandler(_groupRepository); var result = await commandHandler.Execute(group); if (result) { return(Ok(commandHandler.HandlerMessage)); } return(NoContent()); }