public ActionResult GetFighter(int id, string active, bool showWinnerItem) { Fighter fighter = fighterService.GetById(id); Timeline timeline = timelineService.GetWithFilter(x => x.CategoryId == fighter.Fight.CategoryId && x.LevelId == fighter.Fight.LevelId).SingleOrDefault(); int refId; if (timeline == null) { refId = -1; } else { refId = timeline.RefereeId; } Tournament tournament = fighter.Fight.Category.Tournament; List <Fighter> fighters = new List <Fighter>(); switch (active) { case "Competitions": int catId = fighter.Fight.CategoryId; if (fightService.GetWithFilter(x => x.CategoryId == catId && x.Fighters.Any(s => s.IsWinner)).Count() == 0 && (User.Identity.Name.Equals(tournament.Organizer))) { fighters = fighterService.GetFightersToReplace(fighter).ToList(); } showWinnerItem = false; break; case "UpcomingFights": //showWinnerItem = true; break; case "FinishedFights": showWinnerItem = false; break; } return(PartialView("_Fighter", new FighterViewModel { Fighter = fighter, FightersToReplace = fighters, ShowWinnerItem = showWinnerItem, RefereeId = refId })); }
public ActionResult SetWinner(int Id, int refereeId) { if (Request.IsAjaxRequest()) { Fighter winner = fighterService.GetById(Id); winner.IsWinner = true; fighterService.Update(winner); SportUnit[] distinctions = sportUnitService.GetByTypeForGroup(winner.Fight.Category.Tournament.GroupId, SportUnitType.Distinction).ToArray(); var nextWinnerFight = winner.Fight.FightRelationsChildFights.Where(x => x.IsWinner).SingleOrDefault(); if (nextWinnerFight != null) { int fighterCount = nextWinnerFight.FightParent.Fighters.Count(); Fighter fighter = new Fighter() { FightId = (int)nextWinnerFight.FightParentId, ParticipantId = winner.ParticipantId, DistinctionId = distinctions[fighterCount].Id }; fighterService.Create(fighter); } var nexLoserFight = winner.Fight.FightRelationsChildFights.Where(x => !x.IsWinner).SingleOrDefault(); if (nexLoserFight != null) { var loser = winner.Fight.Fighters.Where(x => x.Id != Id).Single(); int fighterCount = nexLoserFight.FightParent.Fighters.Count(); Fighter fighter = new Fighter() { FightId = (int)nexLoserFight.FightParentId, ParticipantId = loser.ParticipantId, DistinctionId = distinctions[fighterCount].Id }; fighterService.Create(fighter); } return(RedirectToAction("Details", "Referees", new { id = refereeId })); } return(null); }