Exemple #1
0
        public async Task <List <Fight> > MoveFighterToFight(FighterMoving fighterMoving)
        {
            Fight sourceFight = await _repository.Get(fighterMoving.SourceFightId);

            Fight targetFight = fighterMoving.SourceFightId != fighterMoving.TargetFightId ?
                                await _repository.Get(fighterMoving.TargetFightId) : sourceFight;

            string sourceRedFighterId  = sourceFight.RedAthleteId;
            string sourceBlueFighterId = sourceFight.BlueAthleteId;


            if (targetFight.RedAthleteId == fighterMoving.TargetFighterId)
            {
                targetFight.RedAthleteId = fighterMoving.SourceFighterId;
            }

            if (targetFight.BlueAthleteId == fighterMoving.TargetFighterId)
            {
                targetFight.BlueAthleteId = fighterMoving.SourceFighterId;
            }

            if (sourceRedFighterId == fighterMoving.SourceFighterId)
            {
                sourceFight.RedAthleteId = fighterMoving.TargetFighterId;
            }

            if (sourceBlueFighterId == fighterMoving.SourceFighterId)
            {
                sourceFight.BlueAthleteId = fighterMoving.TargetFighterId;
            }

            var fights = new List <Fight> {
                sourceFight, targetFight
            };
            await _repository.SaveFights(fights);

            return(fights);
        }
        public async Task <List <FightResponseModel> > MoveFighter(FighterMoving fighterMoving)
        {
            var changedFights = await _fighterMovingService.MoveFighterToFight(fighterMoving);

            return(_mapper.Map <List <FightResponseModel> >(changedFights));
        }