private async Task <Squad> BuildSquadAsync(SquadFactoryDto data) { var squadTask = GetSquadAsync(data); var weaponsTask = GetWeaponsAsync(data); var armorsTask = GetArmorsAsync(data); await Task.WhenAll(squadTask, weaponsTask, armorsTask); var squad = squadTask.Result; var quantity = new Quantity(data.Quantity); squad.SetQuantity(quantity); foreach (var weapon in weaponsTask.Result) { squad.AddWeapon(weapon); } foreach (var armor in armorsTask.Result) { squad.AddArmor(armor); } return(squad); }
private async Task <IEnumerable <Weapon> > GetWeaponsAsync(SquadFactoryDto squadData) { if (squadData.Weapons == null || !squadData.Weapons.Any()) { return(Enumerable.Empty <Weapon>()); } return(await Task.WhenAll(squadData.Weapons.Select(GetWeaponAsync))); }
private async Task <IEnumerable <Armor> > GetArmorsAsync(SquadFactoryDto squadData) { if (squadData.Armors == null || !squadData.Armors.Any()) { return(Enumerable.Empty <Armor>()); } return(await Task.WhenAll(squadData.Armors.Select(GetArmorAsync))); }
private async Task <Squad> GetSquadAsync(SquadFactoryDto squadData) { return(await Squad.LoadAsync(squads, squadData.Type)); }